summaryrefslogtreecommitdiff
path: root/de.dhbw.horb.ksm.tableeditor
diff options
context:
space:
mode:
authoryvesf <yvesf-git@xapek.org>2011-05-09 23:37:38 +0200
committeryvesf <yvesf-git@xapek.org>2011-05-10 20:56:04 +0200
commitd99fac83ac0b02c2e8d1e93c18a25a3c92539726 (patch)
tree5c5fb9fe75073f0556a81201ef5d6de249d07a15 /de.dhbw.horb.ksm.tableeditor
downloadksm-rcp-d99fac83ac0b02c2e8d1e93c18a25a3c92539726.tar.gz
ksm-rcp-d99fac83ac0b02c2e8d1e93c18a25a3c92539726.zip
Vor-Ergebnisse Studienarbeit
Diffstat (limited to 'de.dhbw.horb.ksm.tableeditor')
-rw-r--r--de.dhbw.horb.ksm.tableeditor/.classpath7
-rw-r--r--de.dhbw.horb.ksm.tableeditor/.gitignore1
-rw-r--r--de.dhbw.horb.ksm.tableeditor/.project28
-rw-r--r--de.dhbw.horb.ksm.tableeditor/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--de.dhbw.horb.ksm.tableeditor/META-INF/MANIFEST.MF9
-rw-r--r--de.dhbw.horb.ksm.tableeditor/build.properties6
-rw-r--r--de.dhbw.horb.ksm.tableeditor/fragment.xml28
-rw-r--r--de.dhbw.horb.ksm.tableeditor/icons/16/ksm-tableeditor.pngbin0 -> 579 bytes
-rw-r--r--de.dhbw.horb.ksm.tableeditor/icons/32/ksm-tableeditor.pngbin0 -> 832 bytes
-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
12 files changed, 480 insertions, 0 deletions
diff --git a/de.dhbw.horb.ksm.tableeditor/.classpath b/de.dhbw.horb.ksm.tableeditor/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/de.dhbw.horb.ksm.tableeditor/.gitignore b/de.dhbw.horb.ksm.tableeditor/.gitignore
new file mode 100644
index 0000000..e660fd9
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/.gitignore
@@ -0,0 +1 @@
+bin/
diff --git a/de.dhbw.horb.ksm.tableeditor/.project b/de.dhbw.horb.ksm.tableeditor/.project
new file mode 100644
index 0000000..428ea49
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>de.dhbw.horb.ksm.tableeditor</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/de.dhbw.horb.ksm.tableeditor/.settings/org.eclipse.jdt.core.prefs b/de.dhbw.horb.ksm.tableeditor/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7589268
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Thu Apr 14 00:03:26 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/de.dhbw.horb.ksm.tableeditor/META-INF/MANIFEST.MF b/de.dhbw.horb.ksm.tableeditor/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..eda24a5
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: KSM TableEditor
+Bundle-SymbolicName: de.dhbw.horb.ksm.tableeditor;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Fragment-Host: de.dhbw.horb.ksm.core;bundle-version="1.0.0.qualifier"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ClassPath: .
+Require-Bundle: org.eclipse.core.boot;bundle-version="3.1.200"
diff --git a/de.dhbw.horb.ksm.tableeditor/build.properties b/de.dhbw.horb.ksm.tableeditor/build.properties
new file mode 100644
index 0000000..a396e88
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ fragment.xml
+source.. = src/
diff --git a/de.dhbw.horb.ksm.tableeditor/fragment.xml b/de.dhbw.horb.ksm.tableeditor/fragment.xml
new file mode 100644
index 0000000..867b95b
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/fragment.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<fragment>
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ category="ksm.core.views.KSMCategory"
+ class="de.dhbw.horb.tableeditor.view.TableEditorView"
+ icon="icons/16/ksm-tableeditor.png"
+ id="de.dhbw.horb.ksm.tableditor.view"
+ name="Table Editor"
+ restorable="true">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ class="de.dhbw.horb.tableeditor.perspective.TableEditorPerspective"
+ fixed="true"
+ icon="icons/32/ksm-tableeditor.png"
+ id="ksm.tableeditor.perspectives.TableEditorPerspective"
+ name="Table Editor">
+ <description>
+ Table Editor Perspective
+ </description>
+ </perspective>
+ </extension>
+</fragment>
diff --git a/de.dhbw.horb.ksm.tableeditor/icons/16/ksm-tableeditor.png b/de.dhbw.horb.ksm.tableeditor/icons/16/ksm-tableeditor.png
new file mode 100644
index 0000000..cfd515e
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/icons/16/ksm-tableeditor.png
Binary files differ
diff --git a/de.dhbw.horb.ksm.tableeditor/icons/32/ksm-tableeditor.png b/de.dhbw.horb.ksm.tableeditor/icons/32/ksm-tableeditor.png
new file mode 100644
index 0000000..16d54a6
--- /dev/null
+++ b/de.dhbw.horb.ksm.tableeditor/icons/32/ksm-tableeditor.png
Binary files differ
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;
+ }
+ }
+}