退出保存ViewPart

时间:2016-08-05 06:28:54

标签: java eclipse-rcp jface rcp eclipse-gef

我是GEF& RCP。现在我想在退出时保存我的ViewPart,因为我实现了savestate和init方法。但是我使用tableItem来填充My viewpart中的数据。当我试图从我的桌子上获取文本并将它们存储在我的savestate中时,没有任何事情发生。如何从savestate保存存储在TableItem中的数据,并在启动图形编辑器时初始化

public class Theartview extends ViewPart implements Serializable {

    private static final long serialVersionUID = -3033215443267698138L;
    public static String ID = "TutoGEF.theartview_id";
    public Text text;
    public Text text_1;
    private Table table;

    private IMemento memento;
    @SuppressWarnings("unused")
    private Node node;

    private static Node sourceNode;

    private static Node targetNode;

    private static int connectionType;

    TableItem[] items = null;

    @Override
    public void init(IViewSite site, IMemento memento) throws PartInitException {
        this.memento = memento;
        super.init(site, memento);
        System.out.println("hi there");
    }

    @Override
    public void saveState(IMemento memento) {
        super.saveState(memento);
        System.out.println("hello there");

    }

    @SuppressWarnings("static-access")
    public void getDataOfConnection(Node sourceNode, Node targetNode,
            int connectionType1) {
        this.sourceNode = sourceNode;
        this.targetNode = targetNode;
        this.connectionType = connectionType1;

    }

    public Theartview() {
    }

    @Override
    public void createPartControl(Composite parent) {

        parent.setLayout(new GridLayout(10, false));

        table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 10, 1));
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        TableColumn tblclmnTheartName = new TableColumn(table, SWT.NONE);// 1
        tblclmnTheartName.setWidth(100);
        tblclmnTheartName.setText("Theart Name");

        TableColumn tblclmnCategory = new TableColumn(table, SWT.NONE);// 2
        tblclmnCategory.setWidth(100);
        tblclmnCategory.setText("Category");

        TableColumn tblclmnCombo = new TableColumn(table, SWT.NONE);// 3
        tblclmnCombo.setWidth(100);
        tblclmnCombo.setText("Satus");

        TableColumn tblclmnCombo_1 = new TableColumn(table, SWT.NONE);// 4
        tblclmnCombo_1.setWidth(100);
        tblclmnCombo_1.setText("Priority");

        TableColumn tblclmnDescription = new TableColumn(table, SWT.NONE);// 5
        tblclmnDescription.setWidth(162);
        tblclmnDescription.setText("Description");

        TableColumn tblclmnJustification = new TableColumn(table, SWT.NONE);// 6
        tblclmnJustification.setWidth(212);
        tblclmnJustification.setText("Justification");
        // getfillTableRoWData();
        if (memento != null) {
            restoreState(memento);
        }
        memento = null;
    }

    void restoreState(IMemento memento) {
    }

    public void fillTableRoWData() {

        try {
            if (Connection.Number_Of_Connection != 0) {
                TableItem item = new TableItem(table, SWT.NONE);
                String tempConType = null;
                String sourceNodeName = null;
                String targetNodeName = null;

                String settingString = null;

                for (int s = 1; s <= Connection.Number_Of_Connection; s++) {

                    if (connectionType == Connection.CONNECTION_DESIGN) {
                        tempConType = "Deliver Design";

                    } else if (connectionType == Connection.CONNECTION_RESOURCES) {
                        tempConType = "Deliver Resource";

                    } else if (connectionType == Connection.CONNECTION_WORKPACKAGES) {
                        tempConType = "Distributed Work Packages";

                    }
                    // for source
                    if (Service.class.isInstance(sourceNode)) {
                        sourceNodeName = "Service-";

                    } else if (Circle.class.isInstance(sourceNode)) {
                        sourceNodeName = "Circle-";

                    }
                    // for targets

                    if (Service.class.isInstance(targetNode)) {
                        targetNodeName = "Service ";

                    } else if (Circle.class.isInstance(targetNode)) {
                        targetNodeName = "Circle ";

                    }

                    if (sourceNodeName.equals(targetNodeName)) {
                        settingString = sourceNodeName + tempConType;
                    } else if (!(sourceNodeName.equals(targetNodeName))) {
                        settingString = sourceNodeName + targetNodeName
                                + tempConType;

                    }

                    for (int j = 0; j < 6; j++) {

                        TableEditor editor = new TableEditor(table);

                        Text text = new Text(table, SWT.NONE);
                        editor.grabHorizontal = true;
                        editor.setEditor(text, item, 0);
                        text.setText(settingString);

                        editor = new TableEditor(table);
                        text = new Text(table, SWT.NONE);
                        editor.grabHorizontal = true;
                        editor.setEditor(text, item, 1);
                        text.setText(settingString);

                        editor = new TableEditor(table);
                        Combo Status_Combo = new Combo(table, SWT.NONE);

                        Status_Combo.add("Mitigated");
                        Status_Combo.add("Not Applicable");
                        Status_Combo.add("Not Started");
                        Status_Combo.add("Needs Investigation");
                        Status_Combo.setText("Not Started");
                        editor.grabHorizontal = true;
                        editor.setEditor(Status_Combo, item, 2);

                        editor = new TableEditor(table);
                        Combo priority_Combo = new Combo(table, SWT.NONE);
                        priority_Combo.add("High");
                        priority_Combo.add("Medium");
                        priority_Combo.add("Low");
                        priority_Combo.setText("High");
                        editor.grabHorizontal = true;
                        editor.setEditor(priority_Combo, item, 3);

                        editor = new TableEditor(table);
                        text = new Text(table, SWT.NONE);
                        editor.grabHorizontal = true;
                        editor.setEditor(text, item, 4);
                        text.setText(settingString);

                        editor = new TableEditor(table);
                        text = new Text(table, SWT.MULTI | SWT.BORDER
                                | SWT.WRAP | SWT.V_SCROLL);
                        editor.grabHorizontal = true;
                        editor.setEditor(text, item, 5);
                        // text.setText(settingString);
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public void setFocus() {

    }

1 个答案:

答案 0 :(得分:1)

您的saveState()实施应该存储您需要的数据以维持状态。 有关代码示例,请参阅this short tutorial

相关问题