You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/01/25 17:04:10 UTC
svn commit: r499825 - in
/directory/ldapstudio/trunk/ldapstudio-schemas-plugin: ressources/icons/
src/main/java/org/apache/directory/ldapstudio/schemas/controller/
src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/
src/main/java/...
Author: pamarcelot
Date: Thu Jan 25 08:04:06 2007
New Revision: 499825
URL: http://svn.apache.org/viewvc?view=rev&rev=499825
Log:
Fixing DIRSTUDIO-6 (Synchronization between schema view and the sorted list)
Added:
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/ressources/icons/link_with_editor.gif (with props)
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorHierarchyView.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorSchemasView.java
Modified:
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/ICommandIds.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/IImageKeys.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalContentProvider.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalViewer.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/PoolManager.java
Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/ressources/icons/link_with_editor.gif
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/ressources/icons/link_with_editor.gif?view=auto&rev=499825
==============================================================================
Binary file - no diff available.
Propchange: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/ressources/icons/link_with_editor.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/ICommandIds.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/ICommandIds.java?view=diff&rev=499825&r1=499824&r2=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/ICommandIds.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/ICommandIds.java Thu Jan 25 08:04:06 2007
@@ -42,4 +42,6 @@
public static final String CMD_CREATE_A_NEW_ATTRIBUTETYPE = Application.PLUGIN_ID + ".createanewattributetype"; //$NON-NLS-1$
public static final String CMD_SORT_HIERACHICAL_VIEWER = Application.PLUGIN_ID + ".sorthierarchicalviewer"; //$NON-NLS-1$
public static final String CMD_SORT_POOL_MANAGER = Application.PLUGIN_ID + ".sortpoolmanager"; //$NON-NLS-1$
+ public static final String LINK_WITH_EDITOR_HIERARCHY_VIEW = Application.PLUGIN_ID + ".linkwitheditorhierarchyview"; //$NON-NLS-1$
+ public static final String LINK_WITH_EDITOR_SCHEMA_VIEW = Application.PLUGIN_ID + ".linkwitheditorschemasview"; //$NON-NLS-1$
}
Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorHierarchyView.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorHierarchyView.java?view=auto&rev=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorHierarchyView.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorHierarchyView.java Thu Jan 25 08:04:06 2007
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.Activator;
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.model.AttributeType;
+import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
+import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.directory.ldapstudio.schemas.view.editors.AttributeTypeFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.editors.ObjectClassFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.editors.SchemaFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.viewers.HierarchicalViewer;
+import org.apache.directory.ldapstudio.schemas.view.viewers.PoolManager;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.AttributeTypeWrapper;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.DisplayableTreeElement;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.IntermediateNode;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ObjectClassWrapper;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.SchemaWrapper;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Link With Editor Action for the Schemas View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LinkWithEditorHierarchyView extends Action
+{
+ /** The String for storing the checked state of the action */
+ private static final String LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY = LinkWithEditorHierarchyView.class.getName()
+ + ".dialogsettingkey";
+
+ /** The associated view */
+ private HierarchicalViewer hierarchyView;
+
+ /** The listener listening on changes on editors */
+ private IPartListener2 editorListener = new IPartListener2()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partBroughtToTop( IWorkbenchPartReference partRef )
+ {
+ String id = partRef.getId();
+
+ if ( ( id.equals( ObjectClassFormEditor.ID ) || ( id.equals( AttributeTypeFormEditor.ID ) ) ) )
+ {
+ linkViewWithEditor( partRef.getPartName(), id );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partActivated( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partClosed( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partDeactivated( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partHidden( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partInputChanged( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partOpened( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partVisible( IWorkbenchPartReference partRef )
+ {
+ String id = partRef.getId();
+
+ if ( ( id.equals( ObjectClassFormEditor.ID ) || ( id.equals( AttributeTypeFormEditor.ID ) ) ) )
+ {
+ linkViewWithEditor( partRef.getPartName(), id );
+ }
+ }
+ };
+
+ /** The listener listening on changes on the view */
+ private ISelectionListener viewListener = new ISelectionListener()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged( IWorkbenchPart part, ISelection selection )
+ {
+ ITreeSelection iSelection = ( ITreeSelection ) selection;
+
+ Object selectedObject = iSelection.getFirstElement();
+
+ if ( ( selectedObject instanceof SchemaWrapper ) || ( selectedObject instanceof ObjectClassWrapper )
+ || ( selectedObject instanceof AttributeTypeWrapper ) )
+ {
+ linkEditorWithView( ( DisplayableTreeElement ) selectedObject );
+ }
+ }
+ };
+
+
+ /**
+ * Creates a new instance of LinkWithEditorHierarchyView.
+ *
+ * @param view
+ * the associated view
+ */
+ public LinkWithEditorHierarchyView( HierarchicalViewer view )
+ {
+ super( "Link with editor", AS_CHECK_BOX );
+ super.setActionDefinitionId( Activator.PLUGIN_ID + "linkwitheditorschemasview" );
+ super.setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID,
+ IImageKeys.LINK_WITH_EDITOR ) );
+ super.setEnabled( true );
+ hierarchyView = view;
+
+ // Setting up the default key value (if needed)
+ if ( Activator.getDefault().getDialogSettings().get( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY ) == null )
+ {
+ Activator.getDefault().getDialogSettings().put( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY, false );
+ }
+
+ // Setting state from the dialog settings
+ super
+ .setChecked( Activator.getDefault().getDialogSettings().getBoolean( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY ) );
+
+ // Enabling the listeners
+ if ( isChecked() )
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener );
+ hierarchyView.getSite().getPage().addPostSelectionListener( HierarchicalViewer.ID, viewListener );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ setChecked( isChecked() );
+ Activator.getDefault().getDialogSettings().put( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY, isChecked() );
+
+ if ( isChecked() ) // Enabling the listeners
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener );
+
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActiveEditor();
+ if ( activeEditor instanceof ObjectClassFormEditor )
+ {
+ ObjectClassFormEditor editor = ( ObjectClassFormEditor ) activeEditor;
+ linkViewWithEditor( editor.getPartName(), ObjectClassFormEditor.ID );
+ }
+ else if ( activeEditor instanceof AttributeTypeFormEditor )
+ {
+ AttributeTypeFormEditor editor = ( AttributeTypeFormEditor ) activeEditor;
+ linkViewWithEditor( editor.getPartName(), AttributeTypeFormEditor.ID );
+ }
+
+ hierarchyView.getSite().getPage().addPostSelectionListener( HierarchicalViewer.ID, viewListener );
+ }
+ else
+ // Disabling the listeners
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener( editorListener );
+ hierarchyView.getSite().getPage().removePostSelectionListener( PoolManager.ID, viewListener );
+ }
+ }
+
+
+ /**
+ * Links the view with the right editor
+ *
+ * @param editorName
+ * the name of the editor
+ * @param editorID
+ * the id of the editor
+ */
+ private void linkViewWithEditor( String editorName, String editorID )
+ {
+ StructuredSelection structuredSelection = null;
+ DisplayableTreeElement wrapper = null;
+
+ // Only editors for attribute types and object class are accepted
+ if ( editorID.equals( AttributeTypeFormEditor.ID ) )
+ {
+ AttributeType at = SchemaPool.getInstance().getAttributeType( editorName );
+ wrapper = new AttributeTypeWrapper( at, null );
+ structuredSelection = new StructuredSelection( wrapper );
+
+ hierarchyView.getViewer().setSelection( structuredSelection, true );
+ }
+ else if ( editorID.equals( ObjectClassFormEditor.ID ) )
+ {
+ ObjectClass oc = SchemaPool.getInstance().getObjectClass( editorName );
+ wrapper = new ObjectClassWrapper( oc, null );
+ structuredSelection = new StructuredSelection( wrapper );
+ }
+ else
+ {
+ // If the editor isn't an attribute type editor or object class editor, we return
+ return;
+ }
+
+ Object foundItem = hierarchyView.getViewer().testFindItem( wrapper );
+ if ( foundItem != null ) // The node we are looking for is already loaded in the TreeViewer
+ {
+ hierarchyView.getViewer().setSelection( structuredSelection, true );
+ }
+ else
+ // The node we are looking for is not yet loaded in the TreeViewer, we have to find and load it.
+ {
+ DisplayableTreeElement foundElement = hierarchyView.findElementInTree( wrapper );
+
+ if ( foundElement != null )
+ {
+ expandFromTopToBottom( foundElement );
+ hierarchyView.getViewer().setSelection( structuredSelection );
+ }
+ }
+ }
+
+
+ /**
+ * Expands from top to bottom the element and its successive parent (if needed)
+ *
+ * @param element
+ * the bottom element
+ */
+ private void expandFromTopToBottom( Object element )
+ {
+ if ( element instanceof SchemaWrapper )
+ {
+ SchemaWrapper schemaWrapper = ( SchemaWrapper ) element;
+ if ( !hierarchyView.getViewer().getExpandedState( schemaWrapper ) )
+ {
+ hierarchyView.getViewer().setExpandedState( schemaWrapper, true );
+ }
+ }
+ else if ( element instanceof ObjectClassWrapper )
+ {
+ ObjectClassWrapper objectClassWrapper = ( ObjectClassWrapper ) element;
+ expandFromTopToBottom( objectClassWrapper.getParent() );
+ hierarchyView.getViewer().setExpandedState( objectClassWrapper, true );
+ }
+ else if ( element instanceof AttributeTypeWrapper )
+ {
+ AttributeTypeWrapper attributeTypeWrapper = ( AttributeTypeWrapper ) element;
+ expandFromTopToBottom( attributeTypeWrapper.getParent() );
+ hierarchyView.getViewer().setExpandedState( attributeTypeWrapper, true );
+ }
+ else if ( element instanceof IntermediateNode )
+ {
+ IntermediateNode intermediateNode = ( IntermediateNode ) element;
+ expandFromTopToBottom( intermediateNode.getParent() );
+ hierarchyView.getViewer().setExpandedState( intermediateNode, true );
+ }
+ }
+
+
+ /**
+ * Links the editor to the view
+ *
+ * @param wrapper
+ * the selected element in the view
+ */
+ private void linkEditorWithView( DisplayableTreeElement wrapper )
+ {
+ IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getEditorReferences();
+
+ for ( int i = 0; i < editorReferences.length; i++ )
+ {
+ IEditorReference reference = editorReferences[i];
+ IWorkbenchPart workbenchPart = reference.getPart( true );
+
+ if ( (
+ ( ( workbenchPart instanceof ObjectClassFormEditor ) && ( wrapper instanceof ObjectClassWrapper ) )
+ || ( ( workbenchPart instanceof AttributeTypeFormEditor ) && ( wrapper instanceof AttributeTypeWrapper ) )
+ || ( ( workbenchPart instanceof SchemaFormEditor ) && ( wrapper instanceof SchemaWrapper ) )
+ )
+ && ( reference.getPartName().equals( wrapper.getDisplayName() ) ) )
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().bringToTop( workbenchPart );
+ return;
+ }
+ }
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorSchemasView.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorSchemasView.java?view=auto&rev=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorSchemasView.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/LinkWithEditorSchemasView.java Thu Jan 25 08:04:06 2007
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.Activator;
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.model.AttributeType;
+import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
+import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.directory.ldapstudio.schemas.view.editors.AttributeTypeFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.editors.ObjectClassFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.editors.SchemaFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.viewers.PoolManager;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.AttributeTypeWrapper;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.DisplayableTreeElement;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.IntermediateNode;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ObjectClassWrapper;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.SchemaWrapper;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Link With Editor Action for the Schemas View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LinkWithEditorSchemasView extends Action
+{
+ /** The String for storing the checked state of the action */
+ private static final String LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY = LinkWithEditorSchemasView.class.getName()
+ + ".dialogsettingkey";
+
+ /** The associated view */
+ private PoolManager schemasView;
+
+ /** The listener listening on changes on editors */
+ private IPartListener2 editorListener = new IPartListener2()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partBroughtToTop( IWorkbenchPartReference partRef )
+ {
+ String id = partRef.getId();
+
+ if ( ( id.equals( ObjectClassFormEditor.ID ) || ( id.equals( AttributeTypeFormEditor.ID ) ) ) )
+ {
+ linkViewWithEditor( partRef.getPartName(), id );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partActivated( IWorkbenchPartReference partRef )
+ {
+ String id = partRef.getId();
+
+ if ( ( id.equals( ObjectClassFormEditor.ID ) || ( id.equals( AttributeTypeFormEditor.ID ) ) ) )
+ {
+ linkViewWithEditor( partRef.getPartName(), id );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partClosed( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partDeactivated( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partHidden( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partInputChanged( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partOpened( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
+ */
+ public void partVisible( IWorkbenchPartReference partRef )
+ {
+ }
+ };
+
+ /** The listener listening on changes on the view */
+ private ISelectionListener viewListener = new ISelectionListener()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged( IWorkbenchPart part, ISelection selection )
+ {
+ ITreeSelection iSelection = ( ITreeSelection ) selection;
+
+ Object selectedObject = iSelection.getFirstElement();
+
+ if ( ( selectedObject instanceof SchemaWrapper ) || ( selectedObject instanceof ObjectClassWrapper )
+ || ( selectedObject instanceof AttributeTypeWrapper ) )
+ {
+ linkEditorWithView( ( DisplayableTreeElement ) selectedObject );
+ }
+ }
+ };
+
+
+ /**
+ * Creates a new instance of LinkWithEditorSchemasView.
+ *
+ * @param view
+ * the associated view
+ */
+ public LinkWithEditorSchemasView( PoolManager view )
+ {
+ super( "Link with editor", AS_CHECK_BOX );
+ super.setActionDefinitionId( Activator.PLUGIN_ID + "linkwitheditorschemasview" );
+ super.setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID,
+ IImageKeys.LINK_WITH_EDITOR ) );
+ super.setEnabled( true );
+ schemasView = view;
+
+ // Setting up the default key value (if needed)
+ if ( Activator.getDefault().getDialogSettings().get( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY ) == null )
+ {
+ Activator.getDefault().getDialogSettings().put( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY, false );
+ }
+
+ // Setting state from the dialog settings
+ super
+ .setChecked( Activator.getDefault().getDialogSettings().getBoolean( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY ) );
+
+ // Enabling the listeners
+ if ( isChecked() )
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener );
+ schemasView.getSite().getPage().addPostSelectionListener( PoolManager.ID, viewListener );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ setChecked( isChecked() );
+ Activator.getDefault().getDialogSettings().put( LINK_WITH_EDITOR_SCHEMAS_VIEW_DS_KEY, isChecked() );
+
+ if ( isChecked() ) // Enabling the listeners
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener );
+
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActiveEditor();
+ if ( activeEditor instanceof ObjectClassFormEditor )
+ {
+ ObjectClassFormEditor editor = ( ObjectClassFormEditor ) activeEditor;
+ linkViewWithEditor( editor.getPartName(), ObjectClassFormEditor.ID );
+ }
+ else if ( activeEditor instanceof AttributeTypeFormEditor )
+ {
+ AttributeTypeFormEditor editor = ( AttributeTypeFormEditor ) activeEditor;
+ linkViewWithEditor( editor.getPartName(), AttributeTypeFormEditor.ID );
+ }
+
+ schemasView.getSite().getPage().addPostSelectionListener( PoolManager.ID, viewListener );
+ }
+ else
+ // Disabling the listeners
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener( editorListener );
+ schemasView.getSite().getPage().removePostSelectionListener( PoolManager.ID, viewListener );
+ }
+ }
+
+
+ /**
+ * Links the view with the right editor
+ *
+ * @param editorName
+ * the name of the editor
+ * @param editorID
+ * the id of the editor
+ */
+ private void linkViewWithEditor( String editorName, String editorID )
+ {
+ StructuredSelection structuredSelection = null;
+ DisplayableTreeElement wrapper = null;
+
+ // Only editors for attribute types and object class are accepted
+ if ( editorID.equals( AttributeTypeFormEditor.ID ) )
+ {
+ AttributeType at = SchemaPool.getInstance().getAttributeType( editorName );
+ wrapper = new AttributeTypeWrapper( at, null );
+ structuredSelection = new StructuredSelection( wrapper );
+
+ schemasView.getViewer().setSelection( structuredSelection, true );
+ }
+ else if ( editorID.equals( ObjectClassFormEditor.ID ) )
+ {
+ ObjectClass oc = SchemaPool.getInstance().getObjectClass( editorName );
+ wrapper = new ObjectClassWrapper( oc, null );
+ structuredSelection = new StructuredSelection( wrapper );
+ }
+ else
+ {
+ // If the editor isn't an attribute type editor or object class editor, we return
+ return;
+ }
+
+ Object foundItem = schemasView.getViewer().testFindItem( wrapper );
+ if ( foundItem != null ) // The node we are looking for is already loaded in the TreeViewer
+ {
+ schemasView.getViewer().setSelection( structuredSelection, true );
+ }
+ else
+ // The node we are looking for is not yet loaded in the TreeViewer, we have to find and load it.
+ {
+ DisplayableTreeElement foundElement = schemasView.findElementInTree( wrapper );
+
+ if ( foundElement != null )
+ {
+ expandFromTopToBottom( foundElement );
+ schemasView.getViewer().setSelection( structuredSelection );
+ }
+ }
+ }
+
+
+ /**
+ * Expands from top to bottom the element and its successive parent (if needed)
+ *
+ * @param element
+ * the bottom element
+ */
+ private void expandFromTopToBottom( Object element )
+ {
+ if ( element instanceof SchemaWrapper )
+ {
+ SchemaWrapper schemaWrapper = ( SchemaWrapper ) element;
+ if ( !schemasView.getViewer().getExpandedState( schemaWrapper ) )
+ {
+ schemasView.getViewer().setExpandedState( schemaWrapper, true );
+ }
+ }
+ else if ( element instanceof ObjectClassWrapper )
+ {
+ ObjectClassWrapper objectClassWrapper = ( ObjectClassWrapper ) element;
+ expandFromTopToBottom( objectClassWrapper.getParent() );
+ schemasView.getViewer().setExpandedState( objectClassWrapper, true );
+ }
+ else if ( element instanceof AttributeTypeWrapper )
+ {
+ AttributeTypeWrapper attributeTypeWrapper = ( AttributeTypeWrapper ) element;
+ expandFromTopToBottom( attributeTypeWrapper.getParent() );
+ schemasView.getViewer().setExpandedState( attributeTypeWrapper, true );
+ }
+ else if ( element instanceof IntermediateNode )
+ {
+ IntermediateNode intermediateNode = ( IntermediateNode ) element;
+ expandFromTopToBottom( intermediateNode.getParent() );
+ schemasView.getViewer().setExpandedState( intermediateNode, true );
+ }
+ }
+
+
+ /**
+ * Links the editor to the view
+ *
+ * @param wrapper
+ * the selected element in the view
+ */
+ private void linkEditorWithView( DisplayableTreeElement wrapper )
+ {
+ IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getEditorReferences();
+
+ for ( int i = 0; i < editorReferences.length; i++ )
+ {
+ IEditorReference reference = editorReferences[i];
+ IWorkbenchPart workbenchPart = reference.getPart( true );
+
+ if ( (
+ ( ( workbenchPart instanceof ObjectClassFormEditor ) && ( wrapper instanceof ObjectClassWrapper ) )
+ || ( ( workbenchPart instanceof AttributeTypeFormEditor ) && ( wrapper instanceof AttributeTypeWrapper ) )
+ || ( ( workbenchPart instanceof SchemaFormEditor ) && ( wrapper instanceof SchemaWrapper ) )
+ )
+ && ( reference.getPartName().equals( wrapper.getDisplayName() ) ) )
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().bringToTop( workbenchPart );
+ return;
+ }
+ }
+ }
+}
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/IImageKeys.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/IImageKeys.java?view=diff&rev=499825&r1=499824&r2=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/IImageKeys.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/IImageKeys.java Thu Jan 25 08:04:06 2007
@@ -41,6 +41,7 @@
public static final String SORT_ALPHABETICAL = "ressources/icons/sort_alphabetical.gif"; //$NON-NLS-1$
public static final String SORT_UNALPHABETICAL = "ressources/icons/sort_unalphabetical.gif"; //$NON-NLS-1$
public static final String SHOW_PREFERENCES = "ressources/icons/preferences.png"; //$NON-NLS-1$
+ public static final String LINK_WITH_EDITOR = "ressources/icons/link_with_editor.gif"; //$NON-NLS-1$
// Images for Views
public static final String ATTRIBUTE_TYPE = "ressources/icons/attribute_type.gif"; //$NON-NLS-1$
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalContentProvider.java?view=diff&rev=499825&r1=499824&r2=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalContentProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalContentProvider.java Thu Jan 25 08:04:06 2007
@@ -141,7 +141,7 @@
}
}
- //complete optionnal attributes
+ //complete optional attributes
String[] optAttributes = objectClass.getMay();
for ( String name : optAttributes )
{
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalViewer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalViewer.java?view=diff&rev=499825&r1=499824&r2=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalViewer.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/HierarchicalViewer.java Thu Jan 25 08:04:06 2007
@@ -25,10 +25,12 @@
import org.apache.directory.ldapstudio.schemas.controller.Application;
import org.apache.directory.ldapstudio.schemas.controller.HierarchicalViewerController;
+import org.apache.directory.ldapstudio.schemas.controller.actions.LinkWithEditorHierarchyView;
import org.apache.directory.ldapstudio.schemas.controller.actions.SortHierarchicalViewAction;
import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
import org.apache.directory.ldapstudio.schemas.model.PoolListener;
import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.DisplayableTreeElement;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
@@ -72,6 +74,7 @@
toolbar.add( new SortHierarchicalViewAction( PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
SortHierarchicalViewAction.SortType.unalphabetical, Messages
.getString( "HierarchicalViewer.Sort_unalphabetically" ) ) ); //$NON-NLS-1$
+ toolbar.add( new LinkWithEditorHierarchyView( this ) );
}
@@ -141,5 +144,53 @@
public void poolChanged( SchemaPool p, LDAPModelEvent e )
{
refresh();
+ }
+
+ /**
+ * Search for the given element in the Tree and returns it if it has been found.
+ *
+ * @param element
+ * the element to find
+ * @return
+ * the element if it has been found, null if has not been found
+ */
+ public DisplayableTreeElement findElementInTree( DisplayableTreeElement element )
+ {
+ DisplayableTreeElement input = ( DisplayableTreeElement ) getViewer().getInput();
+
+ return findElementInTree( element, input );
+ }
+
+
+ /**
+ * Search for the given element in the Tree and returns it if it has been found.
+ *
+ * @param element
+ * the element to find
+ * @param current
+ * the current element
+ * @return
+ */
+ private DisplayableTreeElement findElementInTree( DisplayableTreeElement element, DisplayableTreeElement current )
+ {
+ if ( element.equals( current ) )
+ {
+ return current;
+ }
+ else
+ {
+ Object[] children = contentProvider.getChildren( current );
+
+ for ( int i = 0; i < children.length; i++ )
+ {
+ DisplayableTreeElement item = ( DisplayableTreeElement ) children[i];
+ DisplayableTreeElement foundElement = findElementInTree( element, item );
+ if ( foundElement != null )
+ {
+ return foundElement;
+ }
+ }
+ }
+ return null;
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/PoolManager.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/PoolManager.java?view=diff&rev=499825&r1=499824&r2=499825
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/PoolManager.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/PoolManager.java Thu Jan 25 08:04:06 2007
@@ -29,6 +29,7 @@
import org.apache.directory.ldapstudio.schemas.controller.actions.CreateANewObjectClassAction;
import org.apache.directory.ldapstudio.schemas.controller.actions.CreateANewSchemaAction;
import org.apache.directory.ldapstudio.schemas.controller.actions.DeleteAction;
+import org.apache.directory.ldapstudio.schemas.controller.actions.LinkWithEditorSchemasView;
import org.apache.directory.ldapstudio.schemas.controller.actions.OpenLocalFileAction;
import org.apache.directory.ldapstudio.schemas.controller.actions.RemoveSchemaAction;
import org.apache.directory.ldapstudio.schemas.controller.actions.SortPoolManagerAction;
@@ -36,6 +37,7 @@
import org.apache.directory.ldapstudio.schemas.model.PoolListener;
import org.apache.directory.ldapstudio.schemas.model.Schema;
import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.DisplayableTreeElement;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IToolBarManager;
@@ -84,9 +86,13 @@
SortPoolManagerAction.SortType.alphabetical, Messages.getString( "PoolManager.Sort_alphabetically" ) ) ); //$NON-NLS-1$
toolbar.add( new SortPoolManagerAction( PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
SortPoolManagerAction.SortType.unalphabetical, Messages.getString( "PoolManager.Sort_unalphabetically" ) ) ); //$NON-NLS-1$
+ toolbar.add( new LinkWithEditorSchemasView( this ) );
// ContextMenu Creation
createContextMenu();
+
+ // Registering the Viewer, so other views can be notified when the viewer selection changes
+ getSite().setSelectionProvider( viewer );
}
@@ -270,4 +276,52 @@
return true;
}
+
+ /**
+ * Search for the given element in the Tree and returns it if it has been found.
+ *
+ * @param element
+ * the element to find
+ * @return
+ * the element if it has been found, null if has not been found
+ */
+ public DisplayableTreeElement findElementInTree( DisplayableTreeElement element )
+ {
+ DisplayableTreeElement input = ( DisplayableTreeElement ) getViewer().getInput();
+
+ return findElementInTree( element, input );
+ }
+
+
+ /**
+ * Search for the given element in the Tree and returns it if it has been found.
+ *
+ * @param element
+ * the element to find
+ * @param current
+ * the current element
+ * @return
+ */
+ private DisplayableTreeElement findElementInTree( DisplayableTreeElement element, DisplayableTreeElement current )
+ {
+ if ( element.equals( current ) )
+ {
+ return current;
+ }
+ else
+ {
+ Object[] children = contentProvider.getChildren( current );
+
+ for ( int i = 0; i < children.length; i++ )
+ {
+ DisplayableTreeElement item = ( DisplayableTreeElement ) children[i];
+ DisplayableTreeElement foundElement = findElementInTree( element, item );
+ if ( foundElement != null )
+ {
+ return foundElement;
+ }
+ }
+ }
+ return null;
+ }
}