gpt4 book ai didi

java - 退出时保存 ViewPart

转载 作者:行者123 更新时间:2023-11-30 07:13:35 27 4
gpt4 key购买 nike

我是 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com