summaryrefslogtreecommitdiff
path: root/de.dhbw.horb.ksm.tableeditor/src
diff options
context:
space:
mode:
Diffstat (limited to 'de.dhbw.horb.ksm.tableeditor/src')
-rw-r--r--de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/perspective/TableEditorPerspective.java37
-rw-r--r--de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/PropertyLabelProvider.java75
-rw-r--r--de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/TableEditorView.java281
3 files changed, 393 insertions, 0 deletions
diff --git a/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/perspective/TableEditorPerspective.java b/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/perspective/TableEditorPerspective.java
new file mode 100644
index 0000000..9fc3945
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/perspective/TableEditorPerspective.java
@@ -0,0 +1,37 @@
+package de.dhbw.horb.tableeditor.perspective;
+
+
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+import de.dhbw.horb.tableeditor.view.TableEditorView;
+
+public class TableEditorPerspective implements IPerspectiveFactory {
+ public static final String ID = "ksm.tableeditor.perspectives.TableEditorPerspective"; //$NON-NLS-N$
+ private IPageLayout factory;
+
+ public TableEditorPerspective() {
+ super();
+ }
+
+ public void createInitialLayout(IPageLayout factory) {
+ this.factory = factory;
+ factory.setEditorAreaVisible(true);
+ addViews();
+ }
+
+ private void addViews() {
+ IFolderLayout topLeft = factory.createFolder("topLeft", //$NON-NLS-N$
+ IPageLayout.LEFT, 0.30f, factory.getEditorArea());
+
+ topLeft.addView(de.dhbw.horb.ksm.core.view.Navigator.VIEW_ID);
+
+ IFolderLayout topRight = factory.createFolder("topRight",
+ IPageLayout.RIGHT, 0.30f, factory.getEditorArea());
+ topRight.addView(TableEditorView.VIEW_ID);
+// topRight.addView("org.eclipse.ui.views.ContentOutline"); //$NON-NLS-N$
+
+ // org.eclipse.ui.internal.PerspectiveBarNewContributionItem
+ }
+} \ No newline at end of file
diff --git a/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/PropertyLabelProvider.java b/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/PropertyLabelProvider.java
new file mode 100644
index 0000000..dd278fa
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/PropertyLabelProvider.java
@@ -0,0 +1,75 @@
+package de.dhbw.horb.tableeditor.view;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+
+import de.dhbw.horb.ksm.core.editor.model.ModelProperties;
+import de.dhbw.horb.ksm.model.api.Connection;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+import de.dhbw.horb.ksm.model.api.NodeGroup;
+import de.dhbw.horb.ksm.model.api.Properties;
+
+public class PropertyLabelProvider extends ColumnLabelProvider {
+ private final String propertyName;
+
+ public PropertyLabelProvider(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+ @Override
+ public String getText(Object element) {
+ String value = null;
+ Properties properties = null;
+ if (element instanceof KSM) {
+ properties = ((KSM) element).getProperties();
+ } else if (element instanceof NodeGroup) {
+ properties = ((NodeGroup) element).getProperties();
+ } else if (element instanceof Node) {
+ properties = ((Node) element).getProperties();
+ } else if (element instanceof Connection) {
+ properties = ((Connection) element).getProperties();
+ }
+
+ if (properties != null) {
+ String type = ModelProperties.INSTANCE.type(propertyName);
+ String name = ModelProperties.INSTANCE.name(propertyName);
+ if ("string".equals(type)) {
+ value = properties.getString(name);
+ if (value == null) {
+ value = "<null>";
+ }
+ } else if ("decimal".equals(type)) {
+ BigDecimal bigDecimal = properties.getDecimal(name);
+ if (bigDecimal == null) {
+ value = "<null>";
+ } else {
+ value = bigDecimal.toPlainString();
+ }
+ } else if ("integer".equals(type)) {
+ BigInteger bigInteger = properties.getInteger(name);
+ if (bigInteger == null) {
+ value = "<null>";
+ } else {
+ value = bigInteger.toString();
+ }
+ } else if ("boolean".equals(type)) {
+ // TODO nullchecks...
+ value = properties.getBoolean(name).toString();
+ } else if ("stringList".equals(type)) {
+ value = properties.getStringList(name).toString();
+ } else if ("decimalList".equals(type)) {
+ value = properties.getDecimalList(name).toString();
+ } else if ("integerList".equals(type)) {
+ value = properties.getIntegerList(name).toString();
+ }
+ }
+ if (value == null) {
+ return "<null>";
+ } else {
+ return value;
+ }
+ }
+}
diff --git a/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/TableEditorView.java b/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/TableEditorView.java
new file mode 100644
index 0000000..886c24d
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/src/de/dhbw/horb/tableeditor/view/TableEditorView.java
@@ -0,0 +1,281 @@
+package de.dhbw.horb.tableeditor.view;
+
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.commands.CommandStackListener;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.IPage;
+import org.eclipse.ui.part.MessagePage;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.PageBookView;
+import org.eclipse.ui.part.PageSite;
+
+import de.dhbw.horb.ksm.core.Activator;
+import de.dhbw.horb.ksm.core.editor.commands.NodeRenameCommand;
+import de.dhbw.horb.ksm.core.editor.model.ModelProperties;
+import de.dhbw.horb.ksm.core.editor.parts.KSMNodeEditPart;
+import de.dhbw.horb.ksm.core.editor.ui.DiagramEditor;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+
+public class TableEditorView extends PageBookView {
+ public static final String VIEW_ID = "de.dhbw.horb.ksm.tableditor.view"; //$NON-NLS-1$
+ private final String message = "No compatible Editor selected";
+
+ @Override
+ public void setFocus() {
+
+ }
+
+ @Override
+ protected IPage createDefaultPage(PageBook book) {
+ MessagePage page = new MessagePage();
+ initPage(page);
+ page.createControl(book);
+ page.setMessage(message);
+ return page;
+ }
+
+ @Override
+ protected PageRec doCreatePage(IWorkbenchPart part) {
+ if (part instanceof DiagramEditor) {
+ DiagramEditor editor = (DiagramEditor) part;
+ TableEditorPage page = new TableEditorPage(editor);
+ page.init(new PageSite(getViewSite()));
+ page.createControl(getPageBook());
+ return new PageRec(part, page);
+ }
+ return null;
+ }
+
+ @Override
+ protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
+ pageRecord.page.dispose();
+ pageRecord.dispose();
+ }
+
+ @Override
+ protected IWorkbenchPart getBootstrapPart() {
+ IWorkbenchPage page = getSite().getPage();
+ if (page != null) {
+ return page.getActiveEditor();
+ }
+ return null;
+ }
+
+ @Override
+ protected boolean isImportant(IWorkbenchPart part) {
+ return (part instanceof DiagramEditor);
+ }
+
+ public class TableEditorPage extends Page implements CommandStackListener {
+ private final DiagramEditor editor;
+ private TableViewer tableViewer;
+ private final String columnCaptionCaption = "Caption";
+ private final String columnCaptionX = "X";
+
+ public TableEditorPage(DiagramEditor editor) {
+ this.editor = editor;
+ }
+
+ @Override
+ public void createControl(final Composite parent) {
+ // Create a Table Viewer with Single-Selection Support
+ tableViewer = new TableViewer(parent, SWT.SINGLE);
+ tableViewer.getTable().setLinesVisible(true);
+ tableViewer.getTable().setHeaderVisible(true);
+
+ TableViewerColumn tableViewerColumnCaption = new TableViewerColumn(
+ tableViewer, SWT.NONE);
+ tableViewerColumnCaption
+ .setLabelProvider(new PropertyLabelProvider(
+ ModelProperties.INSTANCE.NODE_VISUAL_CAPTION));
+ tableViewerColumnCaption
+ .setEditingSupport(new StringPropertyEditingSupport(editor,
+ tableViewer.getTable(), tableViewerColumnCaption
+ .getViewer(),
+ ModelProperties.INSTANCE.NODE_VISUAL_CAPTION));
+
+ TableColumn columnCaption = tableViewerColumnCaption.getColumn();
+ columnCaption.setText(columnCaptionCaption);
+ columnCaption.setWidth(100);
+ columnCaption.setResizable(true);
+ columnCaption.setMoveable(true);
+
+ TableViewerColumn tableViewerColumnX = new TableViewerColumn(
+ tableViewer, SWT.NONE);
+ tableViewerColumnX.setLabelProvider(new PropertyLabelProvider(
+ ModelProperties.INSTANCE.NODE_VISUAL_LOCATION_X));
+
+ TableColumn columnX = tableViewerColumnX.getColumn();
+ columnX.setText(columnCaptionX);
+ columnX.setWidth(100);
+ columnX.setResizable(true);
+ columnX.setMoveable(true);
+
+ tableViewer.setContentProvider(new ArrayContentProvider());
+
+ ((CommandStack) editor.getAdapter(CommandStack.class))
+ .addCommandStackListener(this);
+ refreshTable();
+
+ editor.getEditorSite()
+ .getSelectionProvider()
+ .addSelectionChangedListener(
+ new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(
+ SelectionChangedEvent event) {
+ ISelection selection = event.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection s = (IStructuredSelection) selection;
+ System.out.println(s.getFirstElement());
+ if (s.getFirstElement() instanceof KSMNodeEditPart) {
+ KSMNodeEditPart nodeEditPart = (KSMNodeEditPart) s
+ .getFirstElement();
+ System.out.println(nodeEditPart
+ .getModel());
+ tableViewer.setSelection(
+ new StructuredSelection(
+ nodeEditPart
+ .getModel()),
+ true);
+ }
+ }
+ }
+ });
+
+ }
+
+ protected void refreshTable() {
+ KSM model = editor.getModel();
+ List<Node> list = new ArrayList<Node>();
+ for (Node node : model.getAllNodes()) {
+ list.add(node); // XXX change getAllNodes to return a list
+ }
+ tableViewer.setInput(list.toArray());
+ }
+
+ @Override
+ public Control getControl() {
+ return tableViewer.getControl();
+ }
+
+ @Override
+ public void setFocus() {
+ tableViewer.getTable().setFocus();
+ }
+
+ @Override
+ public void commandStackChanged(EventObject event) {
+ refreshTable();
+ }
+
+ @Override
+ public void dispose() {
+ ((CommandStack) editor.getAdapter(CommandStack.class))
+ .removeCommandStackListener(this);
+ super.dispose();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ }
+
+ public class StringPropertyEditingSupport extends EditingSupport {
+ private final String stringPropertyName;
+ private final Table table;
+ private final DiagramEditor editor;
+
+ public StringPropertyEditingSupport(DiagramEditor editor,
+ final Table table, final ColumnViewer columnViewer,
+ final String stringPropertyName) {
+ super(columnViewer);
+ this.editor = editor;
+ this.table = table;
+ this.stringPropertyName = ModelProperties.INSTANCE
+ .stripType(stringPropertyName);
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ if (element instanceof Node && value instanceof String) {
+ CommandStack commandStack = (CommandStack) editor
+ .getAdapter(CommandStack.class);
+ GraphicalViewer graphicalViewer = (GraphicalViewer) editor
+ .getAdapter(GraphicalViewer.class);
+
+ Object object = graphicalViewer.getEditPartRegistry().get(
+ element);
+ if (object instanceof KSMNodeEditPart) {
+ KSMNodeEditPart ep = (KSMNodeEditPart) object;
+ NodeRenameCommand nodeRenameCommand = new NodeRenameCommand(
+ ep);
+ nodeRenameCommand.setNewCaption((String) value);
+ commandStack.execute(nodeRenameCommand);
+ } else {
+ Platform.getLog(Platform.getBundle(Activator.PLUGIN_ID))
+ .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Cant get EditPart for "
+ + element.toString()));
+ }
+ }
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ if (element instanceof Node) {
+ return ((Node) element).getProperties().getString(
+ stringPropertyName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ if (element instanceof Node) {
+ String value = (String) getValue(element);
+ TextCellEditor textCellEditor = new TextCellEditor(table);
+ textCellEditor.setValue(value);
+ return textCellEditor;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ }
+}