directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r556858 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: controller/ model/ view/views/ view/wrappers/
Date Tue, 17 Jul 2007 09:18:01 GMT
Author: pamarcelot
Date: Tue Jul 17 02:17:59 2007
New Revision: 556858

URL: http://svn.apache.org/viewvc?view=rev&rev=556858
Log:
Improved events handling in the ProjectsView.

Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/ProjectsViewContentProvider.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/AbstractTreeNode.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectWrapper.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectsViewRoot.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java?view=diff&rev=556858&r1=556857&r2=556858
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
Tue Jul 17 02:17:59 2007
@@ -32,6 +32,7 @@
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project.ProjectState;
 import org.apache.directory.studio.apacheds.schemaeditor.view.views.ProjectsView;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.ProjectWrapper;
+import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.ProjectsViewRoot;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
@@ -44,7 +45,6 @@
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IWorkbenchActionConstants;
 
 
@@ -59,6 +59,9 @@
     /** The associated view */
     private ProjectsView view;
 
+    /** The TableViewer */
+    private TableViewer viewer;
+
     /** The Context Menu */
     private MenuManager contextMenu;
 
@@ -84,6 +87,7 @@
     public ProjectsViewController( ProjectsView view )
     {
         this.view = view;
+        viewer = view.getViewer();
 
         projectsHandler = Activator.getDefault().getProjectsHandler();
 
@@ -151,8 +155,6 @@
             }
         } );
 
-        TableViewer viewer = view.getViewer();
-
         // set the context menu to the table viewer
         viewer.getControl().setMenu( contextMenu.createContextMenu( viewer.getControl() )
);
 
@@ -166,8 +168,8 @@
      */
     private void initViewer()
     {
-        view.getViewer().setInput( projectsHandler.getProjects() );
-        view.getViewer().getTable().addKeyListener( new KeyAdapter()
+        viewer.setInput( new ProjectsViewRoot( viewer ) );
+        viewer.getTable().addKeyListener( new KeyAdapter()
         {
             public void keyReleased( KeyEvent e )
             {
@@ -178,40 +180,6 @@
                 }
             }
         } );
-        projectsHandler.addListener( new ProjectsHandlerListener()
-        {
-            public void projectAdded( Project project )
-            {
-                refreshProjectsViewer();
-            }
-
-
-            public void projectRemoved( Project project )
-            {
-                refreshProjectsViewer();
-            }
-
-
-            public void openProjectChanged( Project oldProject, Project newProject )
-            {
-                refreshProjectsViewer();
-            }
-        } );
-    }
-
-
-    /**
-     * Refreshes the Projects Viewer
-     */
-    public void refreshProjectsViewer()
-    {
-        Display.getDefault().asyncExec( new Runnable()
-        {
-            public void run()
-            {
-                view.getViewer().refresh();
-            }
-        } );
     }
 
 
@@ -220,11 +188,11 @@
      */
     private void initDoubleClickListener()
     {
-        view.getViewer().addDoubleClickListener( new IDoubleClickListener()
+        viewer.addDoubleClickListener( new IDoubleClickListener()
         {
             public void doubleClick( DoubleClickEvent event )
             {
-                StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection();
+                StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
 
                 if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) )
                 {

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java?view=diff&rev=556858&r1=556857&r2=556858
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
Tue Jul 17 02:17:59 2007
@@ -176,4 +176,33 @@
     {
         this.state = state;
     }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj instanceof Project )
+        {
+            Project project = ( Project ) obj;
+            if ( !getName().equals( project.getName() ) )
+            {
+                return false;
+            }
+            else if ( !getType().equals( project.getType() ) )
+            {
+                return false;
+            }
+            else if ( !getState().equals( project.getState() ) )
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+        // Default
+        return super.equals( obj );
+    }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/ProjectsViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/ProjectsViewContentProvider.java?view=diff&rev=556858&r1=556857&r2=556858
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/ProjectsViewContentProvider.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/ProjectsViewContentProvider.java
Tue Jul 17 02:17:59 2007
@@ -20,11 +20,14 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.views;
 
 
-import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.ProjectWrapper;
+import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.ProjectsViewRoot;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.TreeNode;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -91,16 +94,37 @@
     {
         List<TreeNode> children = null;
 
-        if ( parentElement instanceof List )
+        if ( parentElement instanceof ProjectsViewRoot )
         {
-            List<Project> projects = ( List<Project> ) parentElement;
+            ProjectsViewRoot projectsViewRoot = ( ProjectsViewRoot ) parentElement;
 
-            children = new ArrayList<TreeNode>();
-
-            for ( Project project : projects )
+            if ( !projectsViewRoot.hasChildren() )
             {
-                children.add( new ProjectWrapper( project, tableViewer ) );
+                for ( Project project : Activator.getDefault().getProjectsHandler().getProjects()
)
+                {
+                    projectsViewRoot.addChild( new ProjectWrapper( project, tableViewer )
);
+                }
             }
+
+            children = projectsViewRoot.getChildren();
+
+            // Sorting Children
+            Collections.sort( children, new Comparator<TreeNode>()
+            {
+                public int compare( TreeNode tn1, TreeNode tn2 )
+                {
+                    if ( ( tn1 instanceof ProjectWrapper ) && ( tn2 instanceof ProjectWrapper
) )
+                    {
+                        ProjectWrapper pw1 = ( ProjectWrapper ) tn1;
+                        ProjectWrapper pw2 = ( ProjectWrapper ) tn2;
+
+                        return pw1.getProject().getName().compareToIgnoreCase( pw2.getProject().getName()
);
+                    }
+
+                    // Default
+                    return 0;
+                }
+            } );
         }
         else if ( parentElement instanceof ProjectWrapper )
         {

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/AbstractTreeNode.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/AbstractTreeNode.java?view=diff&rev=556858&r1=556857&r2=556858
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/AbstractTreeNode.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/AbstractTreeNode.java
Tue Jul 17 02:17:59 2007
@@ -59,7 +59,7 @@
     {
         if ( fChildren == null )
         {
-            return true;
+            return false;
         }
 
         return !fChildren.isEmpty();

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectWrapper.java?view=diff&rev=556858&r1=556857&r2=556858
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectWrapper.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectWrapper.java
Tue Jul 17 02:17:59 2007
@@ -82,4 +82,18 @@
     {
         return false;
     }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj instanceof ProjectWrapper )
+        {
+            return getProject().equals( ( ( ProjectWrapper ) obj ).getProject() );
+        }
+
+        return super.equals( obj );
+    }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectsViewRoot.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectsViewRoot.java?view=diff&rev=556858&r1=556857&r2=556858
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectsViewRoot.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wrappers/ProjectsViewRoot.java
Tue Jul 17 02:17:59 2007
@@ -20,6 +20,14 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.wrappers;
 
 
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandlerListener;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.widgets.Display;
+
+
 /**
  * This wrapper is used as root in the ProjectsView.
  *
@@ -28,11 +36,92 @@
  */
 public class ProjectsViewRoot extends AbstractTreeNode
 {
+    /** The TableViewer */
+    private TableViewer viewer;
+
+    /** The ProjectsHandler */
+    private ProjectsHandler projectsHandler;
+
+
     /**
      * Creates a new instance of ProjectsViewRoot.
+     *
+     * @param tableViewer
+     *      the associated TableViewer
      */
-    public ProjectsViewRoot()
+    public ProjectsViewRoot( TableViewer tableViewer )
     {
         super( null );
+        this.viewer = tableViewer;
+
+        projectsHandler = Activator.getDefault().getProjectsHandler();
+        projectsHandler.addListener( new ProjectsHandlerListener()
+        {
+            public void projectAdded( Project project )
+            {
+                addProjectWrapper( project );
+                refreshProjectsViewer();
+            }
+
+
+            public void projectRemoved( Project project )
+            {
+                deleteProjectWrapper( project );
+                refreshProjectsViewer();
+            }
+
+
+            public void openProjectChanged( Project oldProject, Project newProject )
+            {
+                refreshProjectsViewer();
+            }
+        } );
+    }
+
+
+    /**
+     * Add a ProjectWrapper for the given project.
+     *
+     * @param project
+     *      the project
+     */
+    private void addProjectWrapper( Project project )
+    {
+        addChild( new ProjectWrapper( project, viewer ) );
+    }
+
+
+    /**
+     * Deletes the ProjectWrapper associated with the given project.
+     *
+     * @param project
+     *      the project
+     */
+    private void deleteProjectWrapper( Project project )
+    {
+        for ( TreeNode node : getChildren() )
+        {
+            ProjectWrapper pw = ( ProjectWrapper ) node;
+            if ( project == pw.getProject() )
+            {
+                removeChild( node );
+                return;
+            }
+        }
+    }
+
+
+    /**
+     * Refreshes the Projects Viewer
+     */
+    public void refreshProjectsViewer()
+    {
+        Display.getDefault().asyncExec( new Runnable()
+        {
+            public void run()
+            {
+                viewer.refresh();
+            }
+        } );
     }
 }



Mime
View raw message