experimental implementation of ConceptGraphContentProvider
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 16 Feb 2012 13:19:52 +0000 (13:19 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 16 Feb 2012 13:19:52 +0000 (13:19 +0000)
.gitattributes
eu.etaxonomy.taxeditor.cdmlib/.classpath
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/ConceptViewPart.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphContentProvider.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphLabelProvider.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/plugin.xml
pom.xml

index 2245934e3da2c6bb6ee167fc80c93cb2528154f4..55ee497e73a2a6b14def877830369b72e6743614 100644 (file)
@@ -432,6 +432,9 @@ eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/c
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/ConceptLabelProvider.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/ConceptViewPart.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/ConceptViewerSorter.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphContentProvider.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphLabelProvider.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/AbstractDynamicConceptRelationMenu.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/ChangeConceptRelationshipTypeHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/ChangeConceptRelationshipTypeMenu.java -text
index d33912548c13d9deacc2251f2a8a34789f10e051..bab4e61759db18d74a61cdbfd2192feaaaa6c4a6 100644 (file)
@@ -1,14 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-commons-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-ext-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-io-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-print-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-remote-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.0.10-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-envers-3.4.0-SNAPSHOT.jar"/>
        <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 exported="true" kind="lib" path="lib/activation-1.1.jar" sourcepath="lib/activation-1.1src.zip"/>
        <classpathentry exported="true" kind="lib" path="lib/xom-1.0.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/xsltc.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/xstream-1.3.1.jar" sourcepath="lib/xstream-1.3.1src.zip"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-envers-3.4.0-SNAPSHOT.jar" sourcepath="lib/hibernate-envers-3.4.0-SNAPSHOTsrc.zip"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-commons-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-ext-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-io-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-print-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-remote-3.0.10-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.0.10-SNAPSHOT.jar"/>
        <classpathentry kind="output" path="target/classes"/>
 </classpath>
index 99bef4cf7d14692d4be97fafc7c4ec8273780c2b..310d67404b027ea4c662b371a2ad1585f304dfd4 100644 (file)
                name="Concept Relations"
                restorable="true">
          </view>
+         <view
+               class="eu.etaxonomy.taxeditor.editor.view.concept.graph.ConceptGraphView"
+               icon="icons/address-book-new.png"
+               id="eu.etaxonomy.taxeditor.editor.view.concept.graph"
+               name="Concept Graph"
+               restorable="true">
+         </view>
       </extension>
    <extension
          point="org.eclipse.ui.elementFactories">
                   value="eu.etaxonomy.taxeditor.editor.view.concept">
             </parameter>
          </command>
+         <command
+               commandId="org.eclipse.ui.views.showView"
+               label="Concept Graph"
+               style="push">
+            <parameter
+                  name="org.eclipse.ui.views.showView.viewId"
+                  value="eu.etaxonomy.taxeditor.editor.view.concept.graph">
+            </parameter>
+            <visibleWhen
+                  checkEnabled="false">
+               <reference
+                     definitionId="isShowExperimentalFeatures">
+               </reference>
+            </visibleWhen>
+         </command>
       </menuContribution>
       <menuContribution
             locationURI="menu:org.eclipse.ui.main.menu.navigate">
index f44d0b1516d56081ee353471449bca8fe3db3df1..4aa081d5c94a35a9dae38bad8ba35ba95d9dabec 100644 (file)
@@ -58,7 +58,8 @@ public class ConceptViewPart extends AbstractCdmEditorViewPart {
                }
                
                if(part instanceof AbstractGraphKeyEditor){
-                       
+                       showEmptyPage();
+                       return;
                }
                
                if(part instanceof MultiPageTaxonEditor){
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphContentProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphContentProvider.java
new file mode 100644 (file)
index 0000000..d444bc6
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * 
+ */
+package eu.etaxonomy.taxeditor.editor.view.concept.graph;
+
+import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.zest.core.viewers.IGraphContentProvider;
+
+
+
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+
+/**
+ * @author andreas 
+ *
+ */
+public class ConceptGraphContentProvider implements IGraphContentProvider {
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+        */
+       @Override
+       public void dispose() {
+               // TODO Auto-generated method stub
+
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+        */
+       @Override
+       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               // TODO Auto-generated method stub
+
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.zest.core.viewers.IGraphContentProvider#getSource(java.lang.Object)
+        */
+       @Override
+       public Object getSource(Object taxonRelationship) {
+               return ((TaxonRelationship)taxonRelationship).getFromTaxon();
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.zest.core.viewers.IGraphContentProvider#getDestination(java.lang.Object)
+        */
+       @Override
+       public Object getDestination(Object taxonRelationship) {
+               return ((TaxonRelationship)taxonRelationship).getToTaxon();
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.zest.core.viewers.IGraphContentProvider#getElements(java.lang.Object)
+        */
+       @Override
+       public Object[] getElements(Object inputElement) {
+               if(inputElement instanceof TaxonEditorInput){
+                       Taxon taxon = ((TaxonEditorInput) inputElement).getTaxon();
+
+                       Map<String, TaxonRelationship> filteredTaxonRelations = new HashMap<String, TaxonRelationship>();
+                       getTaxonRelationshipsRecursive(filteredTaxonRelations, taxon);
+                       
+                       return filteredTaxonRelations.values().toArray();
+               }
+               return new Object[0];
+       }
+
+       private void getTaxonRelationshipsRecursive(Map<String, TaxonRelationship> filteredTaxonRelations, Taxon taxon) {
+               // TODO extract method into new class TaxonHelper in
+               // eu.etaxonomy.taxeditor.model;
+               // see also ConceptContentProvider
+               for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
+                       
+                       if (!relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
+                                       && !relationship.getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR())
+                                       && !relationship.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
+                               
+                               if(!relationship.getToTaxon().equals(taxon)){
+                                       continue;
+                               }
+                               
+                               String key = relationship.getFromTaxon().getUuid().toString() + relationship.getType().getUuid();
+                               if(!filteredTaxonRelations.containsKey(key)) {
+                                       filteredTaxonRelations.put(key, relationship);                                  
+                                       Taxon toTaxon = relationship.getToTaxon();
+                                       if(toTaxon != null){
+                                               getTaxonRelationshipsRecursive(filteredTaxonRelations, toTaxon);
+       
+                                       }
+                               }
+                       }
+                       
+                       
+               }
+               
+               
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphLabelProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphLabelProvider.java
new file mode 100644 (file)
index 0000000..fe431c8
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * 
+ */
+package eu.etaxonomy.taxeditor.editor.view.concept.graph;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.zest.core.viewers.IEntityStyleProvider;
+
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author andreas
+ * 
+ */
+public class ConceptGraphLabelProvider extends LabelProvider implements
+               IEntityStyleProvider {
+       
+       
+
+       @Override
+       public String getText(Object element) {
+               if(element instanceof Taxon){
+                       return ((Taxon)element).getTitleCache();
+               } else if( element instanceof TaxonRelationship) {
+                       return ((TaxonRelationship)element).getType().getRepresentation(Language.ENGLISH()).getAbbreviatedLabel();
+               }
+               return "TODO";
+       }
+
+       @Override
+       public Color getNodeHighlightColor(Object entity) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Color getBorderColor(Object entity) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Color getBorderHighlightColor(Object entity) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public int getBorderWidth(Object entity) {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public Color getBackgroundColour(Object entity) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Color getForegroundColour(Object entity) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public IFigure getTooltip(Object element) {
+               if( element instanceof TaxonRelationship) {
+                       return new Label(((TaxonRelationship)element).getType().getRepresentation(CdmStore.getDefaultLanguage()).getLabel());
+               }
+               return null;
+       }
+
+       @Override
+       public boolean fisheyeNode(Object entity) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/graph/ConceptGraphView.java
new file mode 100644 (file)
index 0000000..c7a2f9c
--- /dev/null
@@ -0,0 +1,128 @@
+/**
+ * 
+ */
+package eu.etaxonomy.taxeditor.editor.view.concept.graph;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.zest.core.viewers.GraphViewer;
+import org.eclipse.zest.core.widgets.ZestStyles;
+import org.eclipse.zest.layouts.LayoutAlgorithm;
+import org.eclipse.zest.layouts.LayoutStyles;
+import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
+
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
+import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
+
+/**
+ * @author andreas
+ *
+ */
+public class ConceptGraphView extends AbstractCdmEditorViewPart {
+       
+       public static final String ID = "eu.etaxonomy.taxeditor.editor.view.concept.graph";
+
+       private GraphViewer viewer;
+       private LayoutAlgorithm layoutAlgoritm;
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
+        */
+       @Override
+       public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+
+//             if(part instanceof ConceptGraphView){
+//                     // ConceptGraphView is maximized
+//                     return;
+//             }
+               
+               if(EditorUtil.getActiveEditor() == null){
+                       showEmptyPage();
+                       return;
+               }
+               
+               if(part instanceof BulkEditor){
+                       showEmptyPage();
+                       return;
+               }
+               
+               
+               if(part instanceof MultiPageTaxonEditor){
+                       if(! part.equals(this.part)){
+                               IEditorInput input = ((IEditorPart) part).getEditorInput();
+                               showViewer(part, new StructuredSelection(input));
+                       }
+                       showViewer();
+               }
+
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
+        */
+       @Override
+       public boolean onComplete() {
+               // TODO IGNORED
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.view.AbstractCdmViewPart#getViewer()
+        */
+       @Override
+       public Viewer getViewer() {
+               return viewer;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.view.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
+        */
+       @Override
+       public void createViewer(Composite parent) {
+               
+               viewer = new GraphViewer(parent, SWT.NONE);
+               getSite().setSelectionProvider(viewer);
+
+               viewer.setContentProvider(new ConceptGraphContentProvider());
+               viewer.setLabelProvider(new ConceptGraphLabelProvider());
+
+               viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
+
+               viewer.setLayoutAlgorithm(getLayoutAlgoritm(), false);
+
+//             createMenu();
+//
+//             createToolbar();
+
+
+       }
+
+       private LayoutAlgorithm getLayoutAlgoritm() {
+
+               if (layoutAlgoritm == null) {
+                       // layoutAlgoritm = new CompositeLayoutAlgorithm(
+                       // LayoutStyles.NO_LAYOUT_NODE_RESIZING,
+                       // new LayoutAlgorithm[] {
+                       // new TreeLayoutAlgorithm(
+                       // LayoutStyles.NO_LAYOUT_NODE_RESIZING),
+                       // new HorizontalShift(
+                       // LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
+
+                       layoutAlgoritm = new TreeLayoutAlgorithm(
+                                       LayoutStyles.NO_LAYOUT_NODE_RESIZING);
+                       layoutAlgoritm.setEntityAspectRatio(0.5);
+               }
+               return layoutAlgoritm;
+       }
+
+}
index 8376ad3e252597efd7360bf2b4213be85e2c403d..3e81a80096c02f3997d531bd7f23f89d9e6e246a 100644 (file)
    <definition
          id="isShowExperimentalFeatures">
       <with
-            variable="activeMenuSelection">
+            variable="selection">
          <test
                property="eu.etaxonomy.taxeditor.preferences.propertyTester.isShowExperimentalFeatures">
          </test>
diff --git a/pom.xml b/pom.xml
index b1ad12be0d45c3997c7c4a70be02880dea2dab1a..9faaaaf30cc0ec4708b6d66ad9557a500374c82a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
   <packaging>pom</packaging>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <cdmlib.version>3.0.10-SNAPSHOT</cdmlib.version>
+    <cdmlib.version>3.0.10-SNAPSHOT</cdmlib.version><!-- TODO can we use project.version ????? -->
     <tycho.version>0.14.0</tycho.version>
     <taxeditor.version>3.0.10-SNAPSHOT</taxeditor.version>
   </properties>