Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 70145 invoked from network); 5 Nov 2007 17:21:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Nov 2007 17:21:52 -0000 Received: (qmail 60031 invoked by uid 500); 5 Nov 2007 17:16:24 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 59998 invoked by uid 500); 5 Nov 2007 17:16:24 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 59984 invoked by uid 99); 5 Nov 2007 17:16:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 09:16:24 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 17:16:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CCAD61A9842; Mon, 5 Nov 2007 09:16:05 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r592094 [3/35] - in /directory/sandbox/felixk/studio-schemaeditor: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/ma... Date: Mon, 05 Nov 2007 17:15:02 -0000 To: commits@directory.apache.org From: felixk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071105171605.CCAD61A9842@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ObjectClassListener.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,251 @@ +/* + * 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.studio.schemaeditor.controller; + + +import org.apache.directory.shared.ldap.schema.SchemaObject; +import org.apache.directory.studio.schemaeditor.Activator; +import org.apache.directory.studio.schemaeditor.PluginUtils; +import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl; +import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.schemaeditor.model.Project; +import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; +import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaCheckerListener; +import org.apache.directory.studio.schemaeditor.view.ViewUtils; +import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; +import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; +import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; +import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; +import org.apache.directory.studio.schemaeditor.view.views.ProblemsView; +import org.apache.directory.studio.schemaeditor.view.widget.Folder; +import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaErrorWrapper; +import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWarningWrapper; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + + +/** + * This class implements the Controller for the ProblemsView. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ProblemsViewController +{ + /** The associated view */ + private ProblemsView view; + + /** The SchemaCheckerListener */ + private SchemaCheckerListener schemaCheckerListener = new SchemaCheckerListener() + { + public void schemaCheckerUpdated() + { + Display.getDefault().asyncExec( new Runnable() + { + public void run() + { + view.reloadViewer(); + } + } ); + } + }; + + /** The ProjectHandlerListener */ + private ProjectsHandlerListener projectsHandlerListener = new ProjectsHandlerAdapter() + { + public void openProjectChanged( Project oldProject, Project newProject ) + { + if ( oldProject != null ) + { + removeSchemaCheckerListener( oldProject ); + + } + + if ( newProject != null ) + { + addSchemaCheckerListener( newProject ); + view.reloadViewer(); + } + else + { + view.setErrorsAndWarningsCount( 0, 0 ); + view.getViewer().setInput( null ); + } + } + }; + + + /** + * Creates a new instance of SchemasViewController. + * + * @param view + * the associated view + */ + public ProblemsViewController( ProblemsView view ) + { + this.view = view; + + // ProjectsHandlerListener + Activator.getDefault().getProjectsHandler().addListener( projectsHandlerListener ); + + // SchemaCheckerListener + Project project = Activator.getDefault().getProjectsHandler().getOpenProject(); + if ( project != null ) + { + addSchemaCheckerListener( project ); + } + + initDoubleClickListener(); + } + + + /** + * Adds the SchemaCheckerListener. + * + * @param project + * the project + */ + private void addSchemaCheckerListener( Project project ) + { + SchemaChecker schemaChecker = project.getSchemaChecker(); + if ( schemaChecker != null ) + { + schemaChecker.addListener( schemaCheckerListener ); + schemaChecker.enableModificationsListening(); + } + } + + + /** + * Removes the SchemaCheckerListener. + * + * @param project + * the project + */ + private void removeSchemaCheckerListener( Project project ) + { + SchemaChecker schemaChecker = project.getSchemaChecker(); + if ( schemaChecker != null ) + { + schemaChecker.removeListener( schemaCheckerListener ); + schemaChecker.disableModificationsListening(); + } + } + + + /** + * Initializes the DoubleClickListener. + */ + private void initDoubleClickListener() + { + view.getViewer().addDoubleClickListener( new IDoubleClickListener() + { + public void doubleClick( DoubleClickEvent event ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + + TreeViewer viewer = view.getViewer(); + + // What we get from the treeViewer is a StructuredSelection + StructuredSelection selection = ( StructuredSelection ) event.getSelection(); + + // Here's the real object (an AttributeTypeWrapper, ObjectClassWrapper or IntermediateNode) + Object objectSelection = selection.getFirstElement(); + IEditorInput input = null; + String editorId = null; + + // Selecting the right editor and input + if ( objectSelection instanceof SchemaErrorWrapper ) + { + SchemaObject object = ( ( SchemaErrorWrapper ) objectSelection ).getSchemaError().getSource(); + + if ( object instanceof AttributeTypeImpl ) + { + input = new AttributeTypeEditorInput( ( AttributeTypeImpl ) object ); + editorId = AttributeTypeEditor.ID; + } + else if ( object instanceof ObjectClassImpl ) + { + input = new ObjectClassEditorInput( ( ObjectClassImpl ) object ); + editorId = ObjectClassEditor.ID; + } + } + else if ( objectSelection instanceof SchemaWarningWrapper ) + { + SchemaObject object = ( ( SchemaWarningWrapper ) objectSelection ).getSchemaWarning().getSource(); + + if ( object instanceof AttributeTypeImpl ) + { + input = new AttributeTypeEditorInput( ( AttributeTypeImpl ) object ); + editorId = AttributeTypeEditor.ID; + } + else if ( object instanceof ObjectClassImpl ) + { + input = new ObjectClassEditorInput( ( ObjectClassImpl ) object ); + editorId = ObjectClassEditor.ID; + } + } + else if ( ( objectSelection instanceof Folder ) ) + { + // Here we don't open an editor, we just expand the node. + viewer.setExpandedState( objectSelection, !viewer.getExpandedState( objectSelection ) ); + } + + // Let's open the editor + if ( input != null ) + { + try + { + page.openEditor( input, editorId ); + } + catch ( PartInitException e ) + { + PluginUtils.logError( "An error occured when opening the editor.", e ); + ViewUtils.displayErrorMessageBox( "Error", "An error occured when opening the editor." ); + } + } + } + } ); + } + + + /** + * Disposes the listeners. + */ + public void dispose() + { + // ProjectsHandlerListener + Activator.getDefault().getProjectsHandler().removeListener( projectsHandlerListener ); + + // SchemaCheckerListener + Project project = Activator.getDefault().getProjectsHandler().getOpenProject(); + if ( project != null ) + { + removeSchemaCheckerListener( project ); + } + } +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,36 @@ +/* + * 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.studio.schemaeditor.controller; + + +/** + * Classes which implement this interface provide methods that deal with the + * events that are generated when an event occurs on a project. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public interface ProjectListener +{ + /** + * This method is called when the project is renamed. + */ + public void projectRenamed(); +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,360 @@ +/* + * 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.studio.schemaeditor.controller; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.collections.map.MultiValueMap; +import org.apache.directory.studio.schemaeditor.model.Project; +import org.apache.directory.studio.schemaeditor.model.Project.ProjectState; + + +/** + * This class represents the ProjectsHandler. + *

+ * It used to handle the schema projects. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ProjectsHandler +{ + /** The ProjectsHandler instance */ + private static ProjectsHandler instance; + + /** The projects List */ + private List projectsList; + + /** The projects Map */ + private Map projectsMap; + + /** The ProjectsHandler listeners */ + private List projectsHandlerListeners; + + /** The projects listeners */ + private MultiValueMap projectsListeners; + + /** The open project */ + private Project openProject; + + + /** + * Gets the singleton instance of the ProjectsHandler. + * + * @return + * the singleton instance of the ProjectsHandler + */ + public static ProjectsHandler getInstance() + { + if ( instance == null ) + { + instance = new ProjectsHandler(); + } + + return instance; + } + + + /** + * Private Constructor. + */ + private ProjectsHandler() + { + projectsList = new ArrayList(); + projectsMap = new HashMap(); + projectsHandlerListeners = new ArrayList(); + projectsListeners = new MultiValueMap(); + } + + + /** + * Adds a project. + * + * @param project + * a project + */ + public void addProject( Project project ) + { + projectsList.add( project ); + projectsMap.put( project.getName().toLowerCase(), project ); + + notifyProjectAdded( project ); + } + + + /** + * Removes the given project. + * + * @param project + * the project + */ + public void removeProject( Project project ) + { + projectsList.remove( project ); + projectsMap.remove( project.getName().toLowerCase() ); + + notifyProjectRemoved( project ); + } + + + /** + * Gets the project identified by the given name. + * + * @param name + * the name of the project + * @return + * the corresponding project + */ + public Project getProject( String name ) + { + return projectsMap.get( name.toLowerCase() ); + } + + + /** + * Gets the projects List. + * + * @return + * the projects List + */ + public List getProjects() + { + return projectsList; + } + + + /** + * Renames the given project. + * + * @param project + * the project + * @param name + * the new name + */ + public void renameProject( Project project, String name ) + { + projectsMap.remove( project.getName().toLowerCase() ); + project.setName( name ); + projectsMap.put( name.toLowerCase(), project ); + + notifyProjectRenamed( project ); + } + + + /** + * Return whether or not the given name is already taken by another project + * + * @param name + * the name + * @return + * true if the given name is already taken, false if not + */ + public boolean isProjectNameAlreadyTaken( String name ) + { + return projectsMap.containsKey( name.toLowerCase() ); + } + + + /** + * Opens the given project (and closes the previously opened project) + * + * @param project + * the project + */ + public void openProject( Project project ) + { + Project oldOpenProject = openProject; + if ( oldOpenProject != null ) + { + openProject.setState( ProjectState.CLOSED ); + } + + openProject = project; + openProject.setState( ProjectState.OPEN ); + + notifyOpenProjectChanged( oldOpenProject, openProject ); + } + + + /** + * Closes the given project + * + * @param project + * the project + */ + public void closeProject( Project project ) + { + Project oldOpenProject = openProject; + if ( oldOpenProject.equals( project ) ) + { + oldOpenProject.setState( ProjectState.CLOSED ); + openProject = null; + } + + notifyOpenProjectChanged( oldOpenProject, openProject ); + } + + + /** + * Gets the 'Open' project. + * + * @return + * the 'Open' project + */ + public Project getOpenProject() + { + return openProject; + } + + + /** + * Sets the 'Open' project + * + * @param project + * the project + */ + public void setOpenProject( Project project ) + { + openProject = project; + } + + + /** + * Adds a ProjectsHandlerListener to the ProjectsHandler. + * + * @param listener + * the listener + */ + public void addListener( ProjectsHandlerListener listener ) + { + projectsHandlerListeners.add( listener ); + } + + + /** + * Remove the given ProjectsHandlerListener. + * + * @param listener + * the listener + */ + public void removeListener( ProjectsHandlerListener listener ) + { + projectsHandlerListeners.remove( listener ); + } + + + /** + * Adds a ProjectListener to the given Project. + * + * @param project + * the project + * @param listener + * the listener + */ + public void addListener( Project project, ProjectListener listener ) + { + if ( !projectsListeners.containsValue( project, listener ) ) + { + projectsListeners.put( project, listener ); + } + } + + + /** + * Removes the given ProjectListener. + * + * @param project + * the project + * @param listener + * the listener + */ + public void removeListener( Project project, ProjectListener listener ) + { + projectsListeners.remove( project, listener ); + } + + + /** + * Notifies the ProjectsHandler's listener that a project has been added. + * + * @param project + * the added project + */ + private void notifyProjectAdded( Project project ) + { + for ( ProjectsHandlerListener listener : projectsHandlerListeners ) + { + listener.projectAdded( project ); + } + } + + + /** + * Notifies the ProjectsHandler's listener that a project has been removed. + * + * @param project + * the removed project + */ + private void notifyProjectRemoved( Project project ) + { + for ( ProjectsHandlerListener listener : projectsHandlerListeners ) + { + listener.projectRemoved( project ); + } + } + + + /** + * Notifies the project's Listeners that the project has been renamed. + * + * @param project + * the renamed project + */ + @SuppressWarnings("unchecked") + private void notifyProjectRenamed( Project project ) + { + List listeners = ( List ) projectsListeners.get( project ); + for ( ProjectListener listener : listeners ) + { + listener.projectRenamed(); + } + } + + + /** + * Notifies the ProjectsHandler's listener that a new project has been opened. + * + * @param oldProject + * the old opened project + * @param newProject + * the new opened project + */ + private void notifyOpenProjectChanged( Project oldProject, Project newProject ) + { + for ( ProjectsHandlerListener listener : projectsHandlerListeners ) + { + listener.openProjectChanged( oldProject, newProject ); + } + } +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerAdapter.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerAdapter.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerAdapter.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerAdapter.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,60 @@ +/* + * 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.studio.schemaeditor.controller; + + +import org.apache.directory.studio.schemaeditor.model.Project; + + +/** + * This adapter class provides default implementations for the methods + * described by the ProjectsHandlerListener interface. + *

+ * Classes that wish to deal with Project events can extend this class + * and override only the methods which they are interested in. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ProjectsHandlerAdapter implements ProjectsHandlerListener +{ + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.controller.ProjectsHandlerListener#projectAdded(org.apache.directory.studio.schemaeditor.model.Project) + */ + public void projectAdded( Project project ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.controller.ProjectsHandlerListener#projectRemoved(org.apache.directory.studio.schemaeditor.model.Project) + */ + public void projectRemoved( Project project ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.controller.ProjectsHandlerListener#openProjectChanged(org.apache.directory.studio.schemaeditor.model.Project, org.apache.directory.studio.schemaeditor.model.Project) + */ + public void openProjectChanged( Project oldProject, Project newProject ) + { + } +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,62 @@ +/* + * 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.studio.schemaeditor.controller; + + +import org.apache.directory.studio.schemaeditor.model.Project; + + +/** + * Classes which implement this interface provide methods that deal with the + * events that are generated when the ProjectsHandler is modified. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public interface ProjectsHandlerListener +{ + /** + * This method is called when a project is added. + * + * @param project + * the added project + */ + public void projectAdded( Project project ); + + + /** + * This method is called when a project is removed. + * + * @param project + * the removed project + */ + public void projectRemoved( Project project ); + + + /** + * This method is called when a project is opened. + * + * @param oldProject + * the old opened project + * @param newProject + * the new opened project + */ + public void openProjectChanged( Project oldProject, Project newProject ); +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,310 @@ +/* + * 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.studio.schemaeditor.controller; + + +import org.apache.directory.studio.schemaeditor.Activator; +import org.apache.directory.studio.schemaeditor.PluginConstants; +import org.apache.directory.studio.schemaeditor.controller.actions.CloseProjectAction; +import org.apache.directory.studio.schemaeditor.controller.actions.DeleteProjectAction; +import org.apache.directory.studio.schemaeditor.controller.actions.ExportProjectsAction; +import org.apache.directory.studio.schemaeditor.controller.actions.ImportProjectsAction; +import org.apache.directory.studio.schemaeditor.controller.actions.NewProjectAction; +import org.apache.directory.studio.schemaeditor.controller.actions.OpenProjectAction; +import org.apache.directory.studio.schemaeditor.controller.actions.RenameProjectAction; +import org.apache.directory.studio.schemaeditor.model.Project; +import org.apache.directory.studio.schemaeditor.model.Project.ProjectState; +import org.apache.directory.studio.schemaeditor.view.views.ProjectsView; +import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectWrapper; +import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectsViewRoot; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.commands.ActionHandler; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; + + +/** + * This class implements the Controller for the SchemaView. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ProjectsViewController +{ + /** The associated view */ + private ProjectsView view; + + /** The Context Menu */ + private MenuManager contextMenu; + + /** The TableViewer */ + private TableViewer viewer; + + /** The ProjectsHandler */ + private ProjectsHandler projectsHandler; + + /** Token used to activate and deactivate shortcuts in the view */ + private IContextActivation contextActivation; + + // The Actions + private NewProjectAction newProject; + private OpenProjectAction openProject; + private CloseProjectAction closeProject; + private RenameProjectAction renameProject; + private DeleteProjectAction deleteProject; + private ImportProjectsAction importProjects; + private ExportProjectsAction exportProjects; + + + /** + * Creates a new instance of SchemasViewController. + * + * @param view + * the associated view + */ + public ProjectsViewController( ProjectsView view ) + { + this.view = view; + viewer = view.getViewer(); + + projectsHandler = Activator.getDefault().getProjectsHandler(); + + initActions(); + initToolbar(); + initContextMenu(); + initViewer(); + initDoubleClickListener(); + initPartListener(); + } + + + /** + * Initializes the Actions. + */ + private void initActions() + { + newProject = new NewProjectAction(); + openProject = new OpenProjectAction( view.getViewer() ); + closeProject = new CloseProjectAction( view.getViewer() ); + renameProject = new RenameProjectAction( view.getViewer() ); + deleteProject = new DeleteProjectAction( view.getViewer() ); + importProjects = new ImportProjectsAction(); + exportProjects = new ExportProjectsAction( view.getViewer() ); + } + + + /** + * Initializes the Toolbar. + */ + private void initToolbar() + { + IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); + toolbar.add( newProject ); + } + + + /** + * Initializes the ContextMenu. + */ + private void initContextMenu() + { + contextMenu = new MenuManager( "" ); //$NON-NLS-1$ + contextMenu.setRemoveAllWhenShown( true ); + contextMenu.addMenuListener( new IMenuListener() + { + public void menuAboutToShow( IMenuManager manager ) + { + MenuManager importManager = new MenuManager( "&Import..." ); + MenuManager exportManager = new MenuManager( "Exp&ort..." ); + manager.add( newProject ); + manager.add( new Separator() ); + manager.add( openProject ); + manager.add( closeProject ); + manager.add( new Separator() ); + manager.add( renameProject ); + manager.add( new Separator() ); + manager.add( deleteProject ); + manager.add( new Separator() ); + manager.add( importManager ); + importManager.add( importProjects ); + manager.add( exportManager ); + exportManager.add( exportProjects ); + + manager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); + } + } ); + + // set the context menu to the table viewer + viewer.getControl().setMenu( contextMenu.createContextMenu( viewer.getControl() ) ); + + // register the context menu to enable extension actions + view.getSite().registerContextMenu( contextMenu, viewer ); + } + + + /** + * Initializes the Viewer. + */ + private void initViewer() + { + viewer.setInput( new ProjectsViewRoot( viewer ) ); + viewer.getTable().addKeyListener( new KeyAdapter() + { + public void keyReleased( KeyEvent e ) + { + if ( ( e.keyCode == Action.findKeyCode( "BACKSPACE" ) ) + || ( e.keyCode == Action.findKeyCode( "DELETE" ) ) ) + { + deleteProject.run(); + } + } + } ); + } + + + /** + * Initializes the DoubleClickListener. + */ + private void initDoubleClickListener() + { + viewer.addDoubleClickListener( new IDoubleClickListener() + { + public void doubleClick( DoubleClickEvent event ) + { + StructuredSelection selection = ( StructuredSelection ) viewer.getSelection(); + + if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) ) + { + Project project = ( ( ProjectWrapper ) selection.getFirstElement() ).getProject(); + if ( project.getState().equals( ProjectState.CLOSED ) ) + { + projectsHandler.openProject( project ); + } + } + } + } ); + } + + + /** + * Initializes the PartListener. + */ + private void initPartListener() + { + view.getSite().getPage().addPartListener( new IPartListener2() + { + /** + * This implementation deactivates the shortcuts when the part is deactivated. + */ + public void partDeactivated( IWorkbenchPartReference partRef ) + { + if ( partRef.getPart( false ) == view && contextActivation != null ) + { + ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( + ICommandService.class ); + if ( commandService != null ) + { + commandService.getCommand( newProject.getActionDefinitionId() ).setHandler( null ); + commandService.getCommand( renameProject.getActionDefinitionId() ).setHandler( null ); + commandService.getCommand( deleteProject.getActionDefinitionId() ).setHandler( null ); + } + + IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( + IContextService.class ); + contextService.deactivateContext( contextActivation ); + contextActivation = null; + } + } + + + /** + * This implementation activates the shortcuts when the part is activated. + */ + public void partActivated( IWorkbenchPartReference partRef ) + { + if ( partRef.getPart( false ) == view ) + { + IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( + IContextService.class ); + contextActivation = contextService.activateContext( PluginConstants.CONTEXT_PROJECTS_VIEW ); + + ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( + ICommandService.class ); + if ( commandService != null ) + { + commandService.getCommand( newProject.getActionDefinitionId() ).setHandler( + new ActionHandler( newProject ) ); + commandService.getCommand( renameProject.getActionDefinitionId() ).setHandler( + new ActionHandler( renameProject ) ); + commandService.getCommand( deleteProject.getActionDefinitionId() ).setHandler( + new ActionHandler( deleteProject ) ); + } + } + } + + + public void partBroughtToTop( IWorkbenchPartReference partRef ) + { + } + + + public void partClosed( IWorkbenchPartReference partRef ) + { + } + + + public void partHidden( IWorkbenchPartReference partRef ) + { + } + + + public void partInputChanged( IWorkbenchPartReference partRef ) + { + } + + + public void partOpened( IWorkbenchPartReference partRef ) + { + } + + + public void partVisible( IWorkbenchPartReference partRef ) + { + } + + } ); + } +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaAdapter.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaAdapter.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaAdapter.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaAdapter.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,135 @@ +/* + * 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.studio.schemaeditor.controller; + + +import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl; +import org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl; +import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.schemaeditor.model.SyntaxImpl; + + +/** + * This adapter class provides default implementations for the methods + * described by the SchemaListener interface. + *

+ * Classes that wish to deal with schema events can extend this class + * and override only the methods which they are interested in. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public abstract class SchemaAdapter implements SchemaListener +{ + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#attributeTypeAdded(org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl) + */ + public void attributeTypeAdded( AttributeTypeImpl at ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#attributeTypeModified(org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl) + */ + public void attributeTypeModified( AttributeTypeImpl at ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#attributeTypeRemoved(org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl) + */ + public void attributeTypeRemoved( AttributeTypeImpl at ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#matchingRuleAdded(org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl) + */ + public void matchingRuleAdded( MatchingRuleImpl mr ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#matchingRuleModified(org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl) + */ + public void matchingRuleModified( MatchingRuleImpl mr ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#matchingRuleRemoved(org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl) + */ + public void matchingRuleRemoved( MatchingRuleImpl mr ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#objectClassAdded(org.apache.directory.studio.schemaeditor.model.ObjectClassImpl) + */ + public void objectClassAdded( ObjectClassImpl oc ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#objectClassModified(org.apache.directory.studio.schemaeditor.model.ObjectClassImpl) + */ + public void objectClassModified( ObjectClassImpl oc ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#objectClassRemoved(org.apache.directory.studio.schemaeditor.model.ObjectClassImpl) + */ + public void objectClassRemoved( ObjectClassImpl oc ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#syntaxAdded(org.apache.directory.studio.schemaeditor.model.SyntaxImpl) + */ + public void syntaxAdded( SyntaxImpl syntax ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#syntaxModified(org.apache.directory.studio.schemaeditor.model.SyntaxImpl) + */ + public void syntaxModified( SyntaxImpl syntax ) + { + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.schemaeditor.model.SchemaListener#syntaxRemoved(org.apache.directory.studio.schemaeditor.model.SyntaxImpl) + */ + public void syntaxRemoved( SyntaxImpl syntax ) + { + } +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java?rev=592094&view=auto ============================================================================== --- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java (added) +++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java Mon Nov 5 09:14:24 2007 @@ -0,0 +1,1257 @@ +/* + * 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.studio.schemaeditor.controller; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.MultiMap; +import org.apache.commons.collections.map.MultiValueMap; +import org.apache.directory.shared.ldap.schema.SchemaObject; +import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl; +import org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl; +import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.schemaeditor.model.Schema; +import org.apache.directory.studio.schemaeditor.model.SyntaxImpl; + + +/** + * This class represents the SchemaHandler. + *

+ * It used to handle the whole Schema (including schemas, attribute types, + * object classes, matching rules and syntaxes). + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class SchemaHandler +{ + // + // The Lists + // + /** The schemas List */ + private List schemasList; + /** The attribute types List */ + private List attributeTypesList; + /** The matching rules List */ + private List matchingRulesList; + /** The object classes List */ + private List objectClassesList; + /** The syntaxes List */ + private List syntaxesList; + + // + // The MultiMap (for fast searching) + // + /** The schemas MultiMap */ + private MultiMap schemasMap; + /** The attribute types MultiMap */ + private MultiMap attributeTypesMap; + /** The matching rules MultiMap */ + private MultiMap matchingRulesMap; + /** The object classes MultiMap */ + private MultiMap objectClassesMap; + /** The syntaxes MultiMap */ + private MultiMap syntaxesMap; + + // + // The Listeners Lists + // + private List schemaHandlerListeners; + private MultiValueMap schemaListeners; + private MultiValueMap attributeTypeListeners; + private MultiValueMap objectClassListeners; + + + /** + * Creates a new instance of SchemaHandler. + */ + public SchemaHandler() + { + // Lists + schemasList = new ArrayList(); + attributeTypesList = new ArrayList(); + matchingRulesList = new ArrayList();; + objectClassesList = new ArrayList(); + syntaxesList = new ArrayList(); + + // Maps + schemasMap = new MultiValueMap(); + attributeTypesMap = new MultiValueMap(); + matchingRulesMap = new MultiValueMap(); + objectClassesMap = new MultiValueMap(); + syntaxesMap = new MultiValueMap(); + + // Listeners + schemaHandlerListeners = new ArrayList(); + schemaListeners = new MultiValueMap(); + attributeTypeListeners = new MultiValueMap(); + objectClassListeners = new MultiValueMap(); + } + + + /** + * Gets the List of all the attribute types. + * + * @return + * the List of all the attribute types + */ + public List getAttributeTypes() + { + return attributeTypesList; + } + + + /** + * Gets the List of all the matching rules. + * + * @return + * the List of all the matching rules + */ + public List getMatchingRules() + { + return matchingRulesList; + } + + + /** + * Gets the List of all the object classes. + * + * @return + * the List of all the object classes + */ + public List getObjectClasses() + { + return objectClassesList; + } + + + /** + * Gets the List of all the schemas. + * + * @return + * the List of all the schemas + */ + public List getSchemas() + { + return schemasList; + } + + + /** + * Gets the List of all the matching rules. + * + * @return + * the List of all the matching rules + */ + public List getSyntaxes() + { + return syntaxesList; + } + + + /** + * Gets an attribute type identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding attribute type, or null if no one is found + */ + public AttributeTypeImpl getAttributeType( String id ) + { + List list = getAttributeTypeList( id.toLowerCase() ); + + if ( ( list != null ) && ( list.size() >= 1 ) ) + { + return ( AttributeTypeImpl ) list.get( 0 ); + } + else + { + return null; + } + } + + + /** + * Get the attribute type(s) List identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding attribute type(s) List or null if no one is found + */ + public List getAttributeTypeList( String id ) + { + return ( List ) attributeTypesMap.get( id.toLowerCase() ); + } + + + /** + * Gets a matching rule identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding matching rule, or null if no one is found + */ + public MatchingRuleImpl getMatchingRule( String id ) + { + List list = getMatchingRuleList( id.toLowerCase() ); + + if ( ( list != null ) && ( list.size() >= 1 ) ) + { + return ( MatchingRuleImpl ) list.get( 0 ); + } + else + { + return null; + } + } + + + /** + * Gets a matching rule(s) List identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding matching rule(s) List, or null if no one is found + */ + public List getMatchingRuleList( String id ) + { + return ( List ) matchingRulesMap.get( id.toLowerCase() ); + } + + + /** + * Gets an object class identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding object class, or null if no one is found + */ + public ObjectClassImpl getObjectClass( String id ) + { + List list = getObjectClassList( id.toLowerCase() ); + + if ( ( list != null ) && ( list.size() >= 1 ) ) + { + return ( ObjectClassImpl ) list.get( 0 ); + } + else + { + return null; + } + } + + + /** + * Gets an object class(es) List identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding object class(es) List, or null if no one is found + */ + public List getObjectClassList( String id ) + { + return ( List ) objectClassesMap.get( id.toLowerCase() ); + } + + + /** + * Gets a schema identified by a name. + * + * @param name + * a name + * @return + * the corresponding schema, or null if no one is found + */ + public Schema getSchema( String name ) + { + List list = getSchemaList( name.toLowerCase() ); + + if ( ( list != null ) && ( list.size() >= 1 ) ) + { + return ( Schema ) list.get( 0 ); + } + else + { + return null; + } + } + + + /** + * Gets a schema(s) List identified by a name. + * + * @param name + * a name + * @return + * the corresponding schema(s) List, or null if no one is found + */ + public List getSchemaList( String name ) + { + return ( List ) schemasMap.get( name.toLowerCase() ); + } + + + /** + * Gets a syntax identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding syntax, or null if no one is found + */ + public SyntaxImpl getSyntax( String id ) + { + List list = getSyntaxList( id.toLowerCase() ); + + if ( ( list != null ) && ( list.size() >= 1 ) ) + { + return ( SyntaxImpl ) list.get( 0 ); + } + else + { + return null; + } + } + + + /** + * Gets a syntax(es) List identified by an OID, or an alias. + * + * @param id + * an OID or an alias + * @return + * the corresponding syntax(es) List, or null if no one is found + */ + public List getSyntaxList( String id ) + { + return ( List ) syntaxesMap.get( id.toLowerCase() ); + } + + + /** + * Adds a SchemaHandlerListener. + * + * @param listener + * the listener + */ + public void addListener( SchemaHandlerListener listener ) + { + if ( !schemaHandlerListeners.contains( listener ) ) + { + schemaHandlerListeners.add( listener ); + } + } + + + /** + * Removes a SchemaHandlerListener. + * + * @param listener + * the listener + */ + public void removeListener( SchemaHandlerListener listener ) + { + schemaHandlerListeners.remove( listener ); + } + + + /** + * Adds a SchemaListener to the given schema. + * + * @param schema + * the schema + * @param listener + * the listener + */ + public void addListener( Schema schema, SchemaListener listener ) + { + if ( !schemaListeners.containsValue( schema, listener ) ) + { + schemaListeners.put( schema, listener ); + } + } + + + /** + * Removes a SchemaListener to the given schema. + * + * @param schema + * the schema + * @param listener + * the listener + */ + public void removeListener( Schema schema, SchemaListener listener ) + { + schemaListeners.remove( schema, listener ); + } + + + /** + * Adds an AttributeTypeListener to the given attribute type. + * + * @param at + * the attribute type + * @param listener + * the listener + */ + public void addListener( AttributeTypeImpl at, AttributeTypeListener listener ) + { + if ( !attributeTypeListeners.containsValue( at, listener ) ) + { + attributeTypeListeners.put( at, listener ); + } + } + + + /** + * Removes an AttributeTypeListener to the given attribute type. + * + * @param at + * the attribute type + * @param listener + * the listener + */ + public void removeListener( AttributeTypeImpl at, AttributeTypeListener listener ) + { + attributeTypeListeners.remove( at, listener ); + } + + + /** + * Adds an ObjectClassListener to the given object class. + * + * @param oc + * the object class + * @param listener + * the listener + */ + public void addListener( ObjectClassImpl oc, ObjectClassListener listener ) + { + if ( !objectClassListeners.containsValue( oc, listener ) ) + { + objectClassListeners.put( oc, listener ); + } + } + + + /** + * Removes an ObjectClassListener to the given object class. + * + * @param oc + * the object class + * @param listener + * the listener + */ + public void removeListener( ObjectClassImpl oc, ObjectClassListener listener ) + { + objectClassListeners.remove( oc, listener ); + } + + + /** + * Adds a schema + * + * @param schema + * the schema + */ + public void addSchema( Schema schema ) + { + // Adding the schema + schemasList.add( schema ); + schemasMap.put( schema.getName().toLowerCase(), schema ); + + // Adding its attribute types + for ( AttributeTypeImpl at : schema.getAttributeTypes() ) + { + addSchemaObject( at ); + } + + // Adding its matching rules + for ( MatchingRuleImpl mr : schema.getMatchingRules() ) + { + addSchemaObject( mr ); + } + + // Adding its object classes + for ( ObjectClassImpl oc : schema.getObjectClasses() ) + { + addSchemaObject( oc ); + } + + // Adding its syntaxes + for ( SyntaxImpl syntax : schema.getSyntaxes() ) + { + addSchemaObject( syntax ); + } + + notifySchemaAdded( schema ); + } + + + /** + * Adds the given SchemaObject to the corresponding List and Map + * + * @param object + * the SchemaObject + */ + private void addSchemaObject( SchemaObject object ) + { + if ( object instanceof AttributeTypeImpl ) + { + AttributeTypeImpl at = ( AttributeTypeImpl ) object; + attributeTypesList.add( at ); + String[] names = at.getNames(); + if ( names != null ) + { + for ( String name : names ) + { + attributeTypesMap.put( name.toLowerCase(), at ); + } + } + attributeTypesMap.put( at.getOid(), at ); + } + else if ( object instanceof MatchingRuleImpl ) + { + MatchingRuleImpl mr = ( MatchingRuleImpl ) object; + matchingRulesList.add( mr ); + String[] names = mr.getNames(); + if ( names != null ) + { + for ( String name : names ) + { + matchingRulesMap.put( name.toLowerCase(), mr ); + } + } + matchingRulesMap.put( mr.getOid(), mr ); + } + else if ( object instanceof ObjectClassImpl ) + { + ObjectClassImpl oc = ( ObjectClassImpl ) object; + objectClassesList.add( oc ); + String[] names = oc.getNames(); + if ( names != null ) + { + for ( String name : names ) + { + objectClassesMap.put( name.toLowerCase(), oc ); + } + } + objectClassesMap.put( oc.getOid(), oc ); + } + else if ( object instanceof SyntaxImpl ) + { + SyntaxImpl syntax = ( SyntaxImpl ) object; + syntaxesList.add( syntax ); + String[] names = syntax.getNames(); + if ( names != null ) + { + for ( String name : names ) + { + syntaxesMap.put( name.toLowerCase(), syntax ); + } + } + syntaxesMap.put( syntax.getOid(), syntax ); + } + } + + + /** + * Removes the given schema. + * + * @param schema + * the schema + */ + public void removeSchema( Schema schema ) + { + // Removing the schema + schemasList.remove( schema ); + schemasMap.remove( schema.getName().toLowerCase() ); + + // Removing its attribute types + for ( AttributeTypeImpl at : schema.getAttributeTypes() ) + { + removeSchemaObject( at ); + } + + // Removing its matching rules + for ( MatchingRuleImpl mr : schema.getMatchingRules() ) + { + removeSchemaObject( mr ); + } + + // Removing its object classes + for ( ObjectClassImpl oc : schema.getObjectClasses() ) + { + removeSchemaObject( oc ); + } + + // Removing its syntaxes + for ( SyntaxImpl syntax : schema.getSyntaxes() ) + { + removeSchemaObject( syntax ); + } + + notifySchemaRemoved( schema ); + } + + + /** + * Removes the given SchemaObject to the corresponding List and Map + * + * @param object + * the SchemaObject + */ + private void removeSchemaObject( SchemaObject object ) + { + if ( object instanceof AttributeTypeImpl ) + { + AttributeTypeImpl at = ( AttributeTypeImpl ) object; + attributeTypesList.remove( at ); + String[] names = at.getNames(); + if ( names != null ) + { + for ( String name : names ) + { + attributeTypesMap.remove( name.toLowerCase() ); + } + } + attributeTypesMap.remove( at.getOid() ); + } + else if ( object instanceof MatchingRuleImpl ) + { + MatchingRuleImpl mr = ( MatchingRuleImpl ) object; + matchingRulesList.remove( mr ); + String[] names = mr.getNames(); + if ( names != null ) + { + for ( String name : mr.getNames() ) + { + matchingRulesMap.remove( name.toLowerCase() ); + } + } + matchingRulesMap.remove( mr.getOid() ); + } + else if ( object instanceof ObjectClassImpl ) + { + ObjectClassImpl oc = ( ObjectClassImpl ) object; + objectClassesList.remove( oc ); + String[] names = oc.getNames(); + if ( names != null ) + { + for ( String name : oc.getNames() ) + { + objectClassesMap.remove( name.toLowerCase() ); + } + } + objectClassesMap.remove( oc.getOid() ); + } + else if ( object instanceof SyntaxImpl ) + { + SyntaxImpl syntax = ( SyntaxImpl ) object; + syntaxesList.remove( syntax ); + String[] names = syntax.getNames(); + if ( names != null ) + { + for ( String name : syntax.getNames() ) + { + syntaxesMap.remove( name.toLowerCase() ); + } + } + syntaxesMap.remove( syntax.getOid() ); + } + } + + + /** + * Adds the given attribute type. + * + * @param at + * the attribute type + */ + public void addAttributeType( AttributeTypeImpl at ) + { + Schema schema = getSchema( at.getSchema() ); + + if ( schema == null ) + { + // TODO Throw an exception + } + + schema.addAttributeType( at ); + addSchemaObject( at ); + + // Notifying the listeners + notifyAttributeTypeAdded( at ); + } + + + /** + * Update the source attribute type with the values of the + * destination attribute type. + * + * @param at1 + * the source attribute type + * @param at2 + * the destination attribute type + */ + public void modifyAttributeType( AttributeTypeImpl at1, AttributeTypeImpl at2 ) + { + // Removing the references (in case of the names or oid have changed) + removeSchemaObject( at1 ); + + // Updating the attribute type + at1.setNames( at2.getNames() ); + at1.setOid( at2.getOid() ); + at1.setDescription( at2.getDescription() ); + at1.setSuperiorName( at2.getSuperiorName() ); + at1.setUsage( at2.getUsage() ); + at1.setSyntaxOid( at2.getSyntaxOid() ); + at1.setLength( at2.getLength() ); + at1.setObsolete( at2.isObsolete() ); + at1.setSingleValue( at2.isSingleValue() ); + at1.setCollective( at2.isCollective() ); + at1.setCanUserModify( at2.isCanUserModify() ); + at1.setEqualityName( at1.getEqualityName() ); + at1.setOrderingName( at2.getOrderingName() ); + at1.setSubstrName( at2.getSubstrName() ); + + // Adding the references (in case of the names or oid have changed) + addSchemaObject( at1 ); + + // Notifying the listeners + notifyAttributeTypeModified( at1 ); + } + + + /** + * Removes the given attribute type. + * + * @param at + * the attribute type + */ + public void removeAttributeType( AttributeTypeImpl at ) + { + Schema schema = getSchema( at.getSchema() ); + + if ( schema == null ) + { + // TODO Throw an exception + } + + schema.removeAttributeType( at ); + removeSchemaObject( at ); + + // Notifying the listeners + notifyAttributeTypeRemoved( at ); + } + + + /** + * Adds the given object class. + * + * @param oc + * the object class + */ + public void addObjectClass( ObjectClassImpl oc ) + { + Schema schema = getSchema( oc.getSchema() ); + + if ( schema == null ) + { + // TODO Throw an exception + } + + schema.addObjectClass( oc ); + addSchemaObject( oc ); + + // Notifying the listeners + notifyObjectClassAdded( oc ); + } + + + /** + * Update the source object class with the values of the + * destination object class. + * + * @param oc1 + * the source object class + * @param oc2 + * the destination object class + */ + public void modifyObjectClass( ObjectClassImpl oc1, ObjectClassImpl oc2 ) + { + // Removing the references (in case of the names or oid have changed) + removeSchemaObject( oc1 ); + + // Updating the object class + oc1.setNames( oc2.getNames() ); + oc1.setOid( oc2.getOid() ); + oc1.setDescription( oc2.getDescription() ); + oc1.setSuperClassesNames( oc2.getSuperClassesNames() ); + oc1.setType( oc2.getType() ); + oc1.setObsolete( oc2.isObsolete() ); + oc1.setMustNamesList( oc2.getMustNamesList() ); + oc1.setMayNamesList( oc2.getMayNamesList() ); + + // Adding the references (in case of the names or oid have changed) + addSchemaObject( oc1 ); + + // Notifying the listeners + notifyObjectClassModified( oc1 ); + } + + + /** + * Removes the given object class. + * + * @param oc + * the object class + */ + public void removeObjectClass( ObjectClassImpl oc ) + { + Schema schema = getSchema( oc.getSchema() ); + + if ( schema == null ) + { + // TODO Throw an exception + } + + schema.removeObjectClass( oc ); + removeSchemaObject( oc ); + + notifyObjectClassRemoved( oc ); + } + + + /** + * Notifies the SchemaHandler listeners that a schema has been added. + * + * @param schema + * the added schema + */ + private void notifySchemaAdded( Schema schema ) + { + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.schemaAdded( schema ); + } + } + + + /** + * Notifies the given listeners that a schema has been removed. + * + * @param schema + * the added schema + */ + private void notifySchemaRemoved( Schema schema ) + { + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.schemaRemoved( schema ); + } + } + + + /** + * Notifies the SchemaHandler listeners that an attribute type has been added. + * + * @param at + * the added attribute type + */ + private void notifyAttributeTypeAdded( AttributeTypeImpl at ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.attributeTypeAdded( at ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( at.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).attributeTypeAdded( at ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that an attribute type has been modified. + * + * @param at + * the modified attribute type + */ + private void notifyAttributeTypeModified( AttributeTypeImpl at ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.attributeTypeModified( at ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( at.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).attributeTypeModified( at ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that an attribute type has been removed. + * + * @param at + * the removed attribute type + */ + private void notifyAttributeTypeRemoved( AttributeTypeImpl at ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.attributeTypeRemoved( at ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( at.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).attributeTypeRemoved( at ); + } + } + + // Attribute Type Listeners + List atListeners = ( List ) attributeTypeListeners.get( at ); + if ( atListeners != null ) + { + for ( Object object : atListeners.toArray() ) + { + ( ( AttributeTypeListener ) object ).attributeTypeRemoved(); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that an object class has been added. + * + * @param oc + * the added object class + */ + private void notifyObjectClassAdded( ObjectClassImpl oc ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.objectClassAdded( oc ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( oc.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).objectClassAdded( oc ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that an object class has been modified. + * + * @param oc + * the modified object class + */ + private void notifyObjectClassModified( ObjectClassImpl oc ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.objectClassModified( oc ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( oc.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).objectClassModified( oc ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that an object class has been removed. + * + * @param oc + * the removed object class + */ + private void notifyObjectClassRemoved( ObjectClassImpl oc ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.objectClassRemoved( oc ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( oc.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).objectClassModified( oc ); + } + } + + // Object Class Listeners + List ocListeners = ( List ) objectClassListeners.get( oc ); + if ( ocListeners != null ) + { + for ( Object object : ocListeners.toArray() ) + { + ( ( ObjectClassListener ) object ).objectClassRemoved(); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that a matching rule has been added. + * + * @param mr + * the added matching rule + */ + private void notifyMatchingRuleAdded( MatchingRuleImpl mr ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.matchingRuleAdded( mr ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( mr.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).matchingRuleAdded( mr ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that a matching rule has been modified. + * + * @param mr + * the modified matching rule + */ + private void notifyMatchingRuleModified( MatchingRuleImpl mr ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.matchingRuleModified( mr ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( mr.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).matchingRuleModified( mr ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that a matching rule has been removed. + * + * @param mr + * the removed matching rule + */ + private void notifyMatchingRuleRemoved( MatchingRuleImpl mr ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.matchingRuleRemoved( mr ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( mr.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).matchingRuleRemoved( mr ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that a syntax has been added. + * + * @param syntax + * the added syntax + */ + private void notifySyntaxRuleAdded( SyntaxImpl syntax ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.syntaxAdded( syntax ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( syntax.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).syntaxAdded( syntax ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that a syntax has been modified. + * + * @param syntax + * the modified syntax + */ + private void notifySyntaxRuleModified( SyntaxImpl syntax ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.syntaxModified( syntax ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( syntax.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).syntaxModified( syntax ); + } + } + } + + + /** + * Notifies the SchemaHandler listeners that a syntax has been removed. + * + * @param syntax + * the removed syntax + */ + private void notifySyntaxRemoved( SyntaxImpl syntax ) + { + // SchemaHandler Listeners + for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) + { + listener.syntaxRemoved( syntax ); + } + + // Schema Listeners + List listeners = ( List ) schemaListeners.get( getSchema( syntax.getSchema() ) ); + if ( listeners != null ) + { + for ( Object object : listeners.toArray() ) + { + ( ( SchemaListener ) object ).syntaxRemoved( syntax ); + } + } + } + + + /** + * Verifies if the given alias or oid is already taken by a schema object + * + * @param id + * the alias or oid + * @return + * true if the the alias or oid is already taken + */ + public boolean isAliasOrOidAlreadyTaken( String id ) + { + String lowerCasedId = id.toLowerCase(); + if ( attributeTypesMap.containsKey( lowerCasedId ) ) + { + return true; + } + else if ( objectClassesMap.containsKey( lowerCasedId ) ) + { + return true; + } + else if ( matchingRulesMap.containsKey( lowerCasedId ) ) + { + return true; + } + else if ( syntaxesMap.containsKey( lowerCasedId ) ) + { + return true; + } + + return false; + } + + + /** + * Verifies if the given name for a schema is already taken by another schema. + * + * @param name + * the name + * @return + * true if the the name is already taken + */ + public boolean isSchemaNameAlreadyTaken( String name ) + { + return schemasMap.containsKey( name.toLowerCase() ); + } +} Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java ------------------------------------------------------------------------------ svn:eol-style = native