import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IEditorInput;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
+import org.simantics.db.Session;
import org.simantics.db.Statement;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.interop.update.model.UpdateOp;
import org.simantics.interop.update.model.UpdateTree;
import org.simantics.interop.utils.TableUtils;
-import org.simantics.ui.workbench.ResourceEditorPart2;
+import org.simantics.ui.SimanticsUI;
import org.simantics.utils.datastructures.Callback;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.ui.ExceptionUtils;
* @author Marko Luukkainen <marko.luukkainen@vtt.fi>
*
*/
-public abstract class ModelUpdateEditor extends ResourceEditorPart2 {
+public abstract class ModelUpdateEditor extends Composite{
-
- private Composite composite;
private Composite errorComposite;
private CheckboxTreeViewer changeBrowser;
private List<ChangeFilter> filters = new ArrayList<ChangeFilter>();
- public ModelUpdateEditor() {
+ public ModelUpdateEditor(Composite parent) {
+ super(parent,SWT.NONE);
checked = manager.createImage(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/tick.png"));
unchecked = manager.createImage(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/cross.png"));
warning = manager.createImage(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/error.png"));
- }
-
- @Override
- public void createPartControl(Composite parent) {
+
containsColor = new Color(parent.getDisplay(), new RGB(255,255,220));
deletedColor = new Color(parent.getDisplay(), new RGB(255,220,220));
addedColor = new Color(parent.getDisplay(), new RGB(220,255,220));
- composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new GridLayout(1,false));
+ this.setLayout(new GridLayout(1,false));
- errorComposite = new Composite(composite, SWT.BORDER);
+ errorComposite = new Composite(this, SWT.BORDER);
GridData data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = false;
errorComposite.setVisible(false);
- IEditorInput input = getEditorInput();
- if (!(input instanceof UpdateEditorInput)) {
- Label label = new Label(composite, SWT.NONE);
- label.setText("Unknown input.");
- return;
- }
-
- Composite fillComposite = new Composite(composite, SWT.NONE);
+// IEditorInput input = getEditorInput();
+// if (!(input instanceof UpdateEditorInput)) {
+// Label label = new Label(composite, SWT.NONE);
+// label.setText("Unknown input.");
+// return;
+// }
+
+ Composite fillComposite = new Composite(this, SWT.NONE);
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
node.getOp().select(Boolean.TRUE.equals(event.getChecked()));
}
- updateSelection();
+ refreshChecked();
}
});
@Override
public void run() {
- updateSelection();
+ // TreeViewer uses lazy load, checked states must be updated when the tree is expanded.
+ refreshChecked();
}
});
selection.setEditingSupport(new SelectionEditingSupport(changeViewer, selected));
}
- Composite buttonComposite = new Composite(composite, SWT.NONE);
+ Composite buttonComposite = new Composite(this, SWT.NONE);
data = new GridData();
data.grabExcessHorizontalSpace = true;
updateAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- updateAll();
+ applyAll();
}
});
updateSelectedButton = new Button(buttonComposite, SWT.PUSH);
updateSelectedButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- updateSelected();
+ applySelected();
}
});
-
- load();
-
+ }
+
+ protected Session getSession() {
+ return SimanticsUI.getSession();
}
protected String getColumntTitle(int i) {
return changes;
}
+ public UpdateTree getUpdateTree() {
+ return updateTree;
+ }
+
+ public CheckboxTreeViewer getChangeBrowser() {
+ return changeBrowser;
+ }
+
+ public TableViewer getChangeViewer() {
+ return changeViewer;
+ }
+
private void showWarning(String text) {
errorComposite.setVisible(true);
label = new Label(errorComposite, SWT.NONE);
label.setText(text);
//this.setStatusMessage("Update contains structural changes (new or deleted symbols), please create a new model.");
- composite.layout(true);
+ this.layout(true);
+ }
+
+
+ private List<ICheckStateListener> checkStateListeners = new ArrayList<>();
+
+ public void addCheckStateListener(ICheckStateListener listener) {
+ checkStateListeners.add(listener);
+ }
+
+ public void removeCheckStateListener(ICheckStateListener listener) {
+ checkStateListeners.remove(listener);
}
- private void updateSelection() {
+ public void refreshChecked() {
Stack<UpdateNode> nodeStack = new Stack<UpdateNode>();
nodeStack.push((UpdateNode)updateTree.getRootNode());
while (!nodeStack.isEmpty()) {
}
changeBrowser.refresh();
+ for (ICheckStateListener l : checkStateListeners) {
+ l.checkStateChanged(new CheckStateChangedEvent(changeBrowser, null, false));
+ }
}
- private void load() {
+ public void load(UpdateEditorInput uei) {
addFilters(filters);
- UpdateEditorInput uei = (UpdateEditorInput)getEditorInput();
Resource r1 = uei.getR1();
Resource r2 = uei.getR2();
changes = getSession().syncRequest(new FilterChangesRead(changes));
updateTree = getUpdateTree(changes);
} catch (DatabaseException e) {
- Text text = new Text(composite, SWT.MULTI);
+ Text text = new Text(this, SWT.MULTI);
text.setText(e.getMessage());
e.printStackTrace();
return;
changeViewer.setInput(changes.getModifications());
changeBrowser.setInput(updateTree);
- updateSelection();
+ refreshChecked();
}
- private void updateAll() {
+ private void applyAll() {
updateAllButton.setEnabled(false);
updateSelectedButton.setEnabled(false);
getSession().asyncRequest(new WriteRequest(){
updateAllButton.setEnabled(true);
updateSelectedButton.setEnabled(true);
- updateSelection();
+ refreshChecked();
changeViewer.refresh();
}
});
}
- private void updateSelected() {
+ private void applySelected() {
updateAllButton.setEnabled(false);
updateSelectedButton.setEnabled(false);
getSession().asyncRequest(new WriteRequest(){
changeViewer.refresh();
updateAllButton.setEnabled(true);
updateSelectedButton.setEnabled(true);
- updateSelection();
+ refreshChecked();
}
});
}
});
}
- @Override
- public void setFocus() {
- composite.setFocus();
-
- }
/**
* Filters changes: