2016-08-05 56 views
1

我是GEF & RCP中的新成员。现在我想保存我的ViewPart退出,因为我已经实现了savestate和init方法。但我正在使用tableItem来填充“我的”视图中的数据。当我试图从我的桌子上拿到文字并将它们存储在我的藏身处时,什么都没有发生。如何从saveState和保存存储在表项我的数据并进行初始化当我启动我的图形编辑器退出时保存ViewPart

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

saveState()实现应该存储你为了保持状态所需要的数据。 代码示例请参阅this short tutorial