退出时保存 ViewPart
Save ViewPart on Exit
我是 GEF 和 RCP 的新成员。现在我想在退出时保存我的 ViewPart,因为我已经实现了 savestate 和 init 方法。但是我正在使用 tableItem 来填充我的视图部分中的数据。当我尝试从我的 table 获取文本并将它们存储在我的保存状态时,没有任何反应。如何从 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。
我是 GEF 和 RCP 的新成员。现在我想在退出时保存我的 ViewPart,因为我已经实现了 savestate 和 init 方法。但是我正在使用 tableItem 来填充我的视图部分中的数据。当我尝试从我的 table 获取文本并将它们存储在我的保存状态时,没有任何反应。如何从 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。