java - 退出时保存 ViewPart

标签 java eclipse-rcp jface rcp eclipse-gef

我是 GEF 和 RCP 的新人。现在我想在退出时保存我的 ViewPart,因为我已经实现了 savestate 和 init 方法。但我正在使用 tableItem 来填充我的 View 部分中的数据。当我尝试从表中获取文本并将它们存储在我的保存状态中时,什么也没有发生。如何在启动图形编辑器时从 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() {

    }

最佳答案

您的 saveState() 实现应该存储维护状态所需的数据。 请参阅this short tutorial代码示例。

关于java - 退出时保存 ViewPart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38782541/

相关文章:

java - 为 Tomcat 配置 SSL 连接器,由 eclipse 调用

java - 如何组合两个字节数组

Java注解和继承

java - 在 SWT 浏览器小部件中获取选定的文本

java - 在 SWT/JFace RCP 应用程序中填充巨大的表

java - 我怎样才能在我的自定义工具提示中得到一个气球?

java - 如何模拟 Jface 对话框上的“确定”按钮单击

java - 需要 WinForm 应用程序与 Nexus 7 通信 - 没有合适的 NFC 读卡器

eclipse-plugin - 如何让版权信息显示在 Eclipse RCP 应用程序的 "About"对话框中

eclipse - 仅从 SWT/JFace TableViewer 刷新一列/单元格