directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1669604 [3/14] - in /directory/studio/trunk/plugins/templateeditor: ./ resources/ resources/icons/ resources/templates/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main...
Date Fri, 27 Mar 2015 15:27:30 GMT
Added: directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-edit.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-edit.xml?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-edit.xml (added)
+++ directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-edit.xml Fri Mar 27 15:27:27 2015
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!--
+  @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+-->
+<template id="organizationalUnit-edit" title="OrganizationalUnit - Edit">
+	<objectClasses>
+		<structural>organizationalUnit</structural>
+	</objectClasses>
+	<form>
+		<composite numberOfColumns="2" equalColumns="false"
+			horizontalAlignment="fill" grabExcessHorizontalSpace="true"
+			verticalAlignment="fill" grabExcessVerticalSpace="true">
+			<!-- GENERAL INFORMATION -->
+			<section title="General Information" numberOfColumns="2"
+				equalColumns="false" horizontalAlignment="fill"
+				grabExcessHorizontalSpace="true">
+
+				<!-- Name -->
+				<label value="Name:" horizontalAlignment="end" width="70" />
+				<textfield attributeType="ou" horizontalAlignment="fill"
+					grabExcessHorizontalSpace="true" />
+
+				<!-- Description -->
+				<label value="Description:" horizontalAlignment="end" />
+				<textfield attributeType="description" numberOfRows="3"
+					horizontalAlignment="fill" grabExcessHorizontalSpace="true" />
+
+			</section>
+
+			<!-- Image -->
+			<image imageWidth="64" imageHeight="64" showSaveAsButton="false"
+				showClearButton="false" showBrowseButton="false">
+				<data>R0lGODlhQABAAOYAAD5imTlbkjtelDxglzFSiTNVjERpoEVqoU+HVEyEUYFVFYRY
+					F1OLWFGJVp11JoNWFh5UJzFTikNnnp53JoBTFRhNIZ94J0Ron5t0JRZLHzJUixtQJPPz883PZ9T
+					Uaf/z0peuW6PAzP7txLTM152xXNrm7qfEzzdZkKy7YMXKZf7xzPfQePzlr8LV373FY/fMcNrXav
+					vhpPnYjdDe5/3quq3I08na47TAYqS2Xt7o8Nbi6/rcmLvR2/jTgt7aa0Jmnfv7+9vb245kHUBln
+					DVWjYxhHD9jmiJXKjJTikV9S4pfGjZsPJJpH5BmHjVXjpRrISlfMTFoOZZuIjpdlEmATjtelT1g
+					l4ZaGDZYjzpwQEJ5SIhcGSVbLZpyJD51RJhwIzhbki1kNcvLy0Non0Bkm+Pj48PDw+/v78/Pz//
+					//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+					AAAAAAAAAAAAAAACH5BAAAAAAALAAAAABAAEAAAAf/gGmCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXm
+					Jmam5oWnp+goaKfHECcihOpqqusrapBHKeJDrS1tre4tWhnsogYv8DBwsPAu72HXcldH8zNzs8f
+					yl3Gx4Vf118q2tvc3SrYX9TVg1LlUiLo6errIuZS4uNpT/NPNPb3+Pk09E/w40wAmbAYSLCgQRY
+					Bmfir1qRhkxgQI0qcGMNhk4XHhGgUsqOjx48gd2wUgrFXkZNFZKhcybKlDJRFSspSQlNJj5s4c+
+					rsUVOJzFNbgm5ZQbSo0aMrhG75yemK0ysvokqdSvXF0ytMNy3YyrWr169cs2p6QLas2bNoy4rNp
+					KCt27dw/+O6XYuJgt27ePPqvUv3EocgaAILDnyg8AEzYgYPhhVvEBAOZyJLjmygsgExZSZPLtWY
+					0ZjPY/p2LvSj9A/RoweRWU0GdSYAsGPLnk27Nm3Omwbo3s27t+/fvhlvEkC8uPHjyJMjd50ogPP
+					n0KNLny6dOaIT2E8gVsy9O/fsJ6wfckLeCWbN6NOjL+9EvKEC8Au4TxNfPq9NSPIjma9//31NBA
+					RIwHwCDvjfI4YlqOCCC+ImCAMQRijhhBRG6GAhlmWo4YYbCidIAyCGKOKIJIboYSEXpKjiiiy2q
+					CI8CMQo44w01ihjSRLkqOOOPPaoIzwJBCnkkEQWKWRJpv2Qw/+STDbpZA5JwkPFlFT4YOWVWGbp
+					A5VUlDTEl0OUIOaYZJZZAphDwJPEmknA4OabcMYJA5tJlGTEnUbooOeefPapA55GwKPFoFp4YOi
+					hiCbqAaFalCTbDJBGKumkM8gGjxeYetHBppx26mkHmXpRkhWkWmHDqaimqqoNpVoBTxawZpHCrL
+					TWamsKsWZRUhW8VtHCr8AGK2wLvVYBzxLILuHCssw266wLyS5R0hTUTsHDtdhmqy0P1U4BTxTgR
+					nHDuOSWa+4N4UZREhjsgjHCu/DGK+8I7YIBTxj4hoHCvvz26y8K+YZREng1FGzwwQjXAB48UDQM
+					BQ4QRyzxxDg4DEWqSVhkjIUJHHfs8ccmaIwFPFyUzAUJKKes8sokmMxFSUTETEQINNds880hyEw
+					EPEf0fAQIQAct9NAg+HxESfUlrfTS8MEDwdNQRy311FCXpMHVWGet9dZYw7PB12CHLfbYYJcUwd
+					lop6322mjDU8HbcMct99xwl1Tg3XjnHSA8GfTt99+AB+53SX95Z7hiJxZ++OInEvKYepBrduHjk
+					Vd+YWqYZ6755pwbEggAOw==</data>
+			</image>
+		</composite>
+	</form>
+</template>

Added: directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-view.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-view.xml?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-view.xml (added)
+++ directory/studio/trunk/plugins/templateeditor/resources/templates/organizationalUnit-view.xml Fri Mar 27 15:27:27 2015
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!--
+  @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+-->
+<template id="organizationalUnit-view" title="OrganizationalUnit - View">
+	<objectClasses>
+		<structural>organizationalUnit</structural>
+	</objectClasses>
+	<form>
+		<composite numberOfColumns="2" equalColumns="false"
+			horizontalAlignment="fill" grabExcessHorizontalSpace="true"
+			verticalAlignment="fill" grabExcessVerticalSpace="true">
+			<!-- GENERAL INFORMATION -->
+			<section title="General Information" numberOfColumns="2"
+				equalColumns="false" horizontalAlignment="fill"
+				grabExcessHorizontalSpace="true">
+
+				<!-- Name -->
+				<label value="Name:" horizontalAlignment="end" width="70" />
+				<label attributeType="ou" horizontalAlignment="fill"
+					grabExcessHorizontalSpace="true" />
+
+				<!-- Description -->
+				<label value="Description:" horizontalAlignment="end" />
+				<label attributeType="description" numberOfRows="3" />
+
+			</section>
+
+			<!-- Image -->
+			<image imageWidth="64" imageHeight="64" showSaveAsButton="false"
+				showClearButton="false" showBrowseButton="false">
+				<data>R0lGODlhQABAAOYAAD5imTlbkjtelDxglzFSiTNVjERpoEVqoU+HVEyEUYFVFYRY
+					F1OLWFGJVp11JoNWFh5UJzFTikNnnp53JoBTFRhNIZ94J0Ron5t0JRZLHzJUixtQJPPz883PZ9T
+					Uaf/z0peuW6PAzP7txLTM152xXNrm7qfEzzdZkKy7YMXKZf7xzPfQePzlr8LV373FY/fMcNrXav
+					vhpPnYjdDe5/3quq3I08na47TAYqS2Xt7o8Nbi6/rcmLvR2/jTgt7aa0Jmnfv7+9vb245kHUBln
+					DVWjYxhHD9jmiJXKjJTikV9S4pfGjZsPJJpH5BmHjVXjpRrISlfMTFoOZZuIjpdlEmATjtelT1g
+					l4ZaGDZYjzpwQEJ5SIhcGSVbLZpyJD51RJhwIzhbki1kNcvLy0Non0Bkm+Pj48PDw+/v78/Pz//
+					//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+					AAAAAAAAAAAAAAACH5BAAAAAAALAAAAABAAEAAAAf/gGmCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXm
+					Jmam5oWnp+goaKfHECcihOpqqusrapBHKeJDrS1tre4tWhnsogYv8DBwsPAu72HXcldH8zNzs8f
+					yl3Gx4Vf118q2tvc3SrYX9TVg1LlUiLo6errIuZS4uNpT/NPNPb3+Pk09E/w40wAmbAYSLCgQRY
+					Bmfir1qRhkxgQI0qcGMNhk4XHhGgUsqOjx48gd2wUgrFXkZNFZKhcybKlDJRFSspSQlNJj5s4c+
+					rsUVOJzFNbgm5ZQbSo0aMrhG75yemK0ysvokqdSvXF0ytMNy3YyrWr169cs2p6QLas2bNoy4rNp
+					KCt27dw/+O6XYuJgt27ePPqvUv3EocgaAILDnyg8AEzYgYPhhVvEBAOZyJLjmygsgExZSZPLtWY
+					0ZjPY/p2LvSj9A/RoweRWU0GdSYAsGPLnk27Nm3Omwbo3s27t+/fvhlvEkC8uPHjyJMjd50ogPP
+					n0KNLny6dOaIT2E8gVsy9O/fsJ6wfckLeCWbN6NOjL+9EvKEC8Au4TxNfPq9NSPIjma9//31NBA
+					RIwHwCDvjfI4YlqOCCC+ImCAMQRijhhBRG6GAhlmWo4YYbCidIAyCGKOKIJIboYSEXpKjiiiy2q
+					CI8CMQo44w01ihjSRLkqOOOPPaoIzwJBCnkkEQWKWRJpv2Qw/+STDbpZA5JwkPFlFT4YOWVWGbp
+					A5VUlDTEl0OUIOaYZJZZAphDwJPEmknA4OabcMYJA5tJlGTEnUbooOeefPapA55GwKPFoFp4YOi
+					hiCbqAaFalCTbDJBGKumkM8gGjxeYetHBppx26mkHmXpRkhWkWmHDqaimqqoNpVoBTxawZpHCrL
+					TWamsKsWZRUhW8VtHCr8AGK2wLvVYBzxLILuHCssw266wLyS5R0hTUTsHDtdhmqy0P1U4BTxTgR
+					nHDuOSWa+4N4UZREhjsgjHCu/DGK+8I7YIBTxj4hoHCvvz26y8K+YZREng1FGzwwQjXAB48UDQM
+					BQ4QRyzxxDg4DEWqSVhkjIUJHHfs8ccmaIwFPFyUzAUJKKes8sokmMxFSUTETEQINNds880hyEw
+					EPEf0fAQIQAct9NAg+HxESfUlrfTS8MEDwdNQRy311FCXpMHVWGet9dZYw7PB12CHLfbYYJcUwd
+					lop6322mjDU8HbcMct99xwl1Tg3XjnHSA8GfTt99+AB+53SX95Z7hiJxZ++OInEvKYepBrduHjk
+					Vd+YWqYZ6755pwbEggAOw==</data>
+			</image>
+		</composite>
+	</form>
+</template>

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,185 @@
+/*
+ *  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.templateeditor;
+
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.PropertyResourceBundle;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryTemplatePlugin extends AbstractUIPlugin
+{
+    /** The shared instance */
+    private static EntryTemplatePlugin plugin;
+
+    /** The plugin properties */
+    private PropertyResourceBundle properties;
+
+    /** The templates manager */
+    private TemplatesManager templatesManager;
+
+
+    /**
+     * The constructor
+     */
+    public EntryTemplatePlugin()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void start( BundleContext context ) throws Exception
+    {
+        super.start( context );
+        plugin = this;
+
+        // Creating the templates manager
+        templatesManager = new TemplatesManager( getPreferenceStore() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void stop( BundleContext context ) throws Exception
+    {
+        plugin = null;
+        super.stop( context );
+    }
+
+
+    /**
+     * Returns the shared instance
+     *
+     * @return the shared instance
+     */
+    public static EntryTemplatePlugin getDefault()
+    {
+        return plugin;
+    }
+
+
+    /**
+     * Gets the templates manager.
+     *
+     * @return
+     *      the templates manager
+     */
+    public TemplatesManager getTemplatesManager()
+    {
+        return templatesManager;
+    }
+
+
+    /**
+     * Use this method to get SWT images. Use the IMG_ constants from
+     * PluginConstants for the key.
+     *
+     * @param key
+     *                The key (relative path to the image in filesystem)
+     * @return The image descriptor or null
+     */
+    public ImageDescriptor getImageDescriptor( String key )
+    {
+        if ( key != null )
+        {
+            URL url = FileLocator.find( getBundle(), new Path( key ), null );
+            if ( url != null )
+                return ImageDescriptor.createFromURL( url );
+            else
+                return null;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Use this method to get SWT images. Use the IMG_ constants from
+     * PluginConstants for the key. A ImageRegistry is used to manage the
+     * the key->Image mapping.
+     * <p>
+     * Note: Don't dispose the returned SWT Image. It is disposed
+     * automatically when the plugin is stopped.
+     *
+     * @param key
+     *                The key (relative path to the image in filesystem)
+     * @return The SWT Image or null
+     */
+    public Image getImage( String key )
+    {
+        Image image = getImageRegistry().get( key );
+        if ( image == null )
+        {
+            ImageDescriptor id = getImageDescriptor( key );
+            if ( id != null )
+            {
+                image = id.createImage();
+                getImageRegistry().put( key, image );
+            }
+        }
+        return image;
+    }
+
+
+    /**
+     * Gets the plugin properties.
+     *
+     * @return
+     *      the plugin properties
+     */
+    public PropertyResourceBundle getPluginProperties()
+    {
+        if ( properties == null )
+        {
+            try
+            {
+                properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path(
+                    "plugin.properties" ), false ) ); //$NON-NLS-1$
+            }
+            catch ( IOException e )
+            {
+                // We can't use the PLUGIN_ID constant since loading the plugin.properties file has failed,
+                // So we're using a default plugin id.
+                getLog().log( new Status( Status.ERROR, "org.apache.directory.studio.templateeditor", Status.OK, //$NON-NLS-1$
+                    Messages.getString( "EntryTemplatePlugin.UnableToGetPluginProperties" ), e ) ); //$NON-NLS-1$
+            }
+        }
+
+        return properties;
+    }
+}
\ No newline at end of file

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginConstants.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginConstants.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginConstants.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,67 @@
+/*
+ *  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.templateeditor;
+
+
+/**
+ * This interface contains all the Constants used in the Plugin.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface EntryTemplatePluginConstants
+{
+    /** The plug-in ID */
+    public static final String PLUGIN_ID = EntryTemplatePlugin.getDefault().getPluginProperties().getString(
+        "Plugin_id" ); //$NON-NLS-1$
+
+    // Images
+    public static final String IMG_EXPORT_TEMPLATES_WIZARD = "resources/icons/export_templates_wizard.gif"; //$NON-NLS-1$
+    public static final String IMG_FILE = "resources/icons/file.gif"; //$NON-NLS-1$
+    public static final String IMG_IMPORT_TEMPLATES_WIZARD = "resources/icons/import_templates_wizard.gif"; //$NON-NLS-1$
+    public static final String IMG_NO_IMAGE = "resources/icons/no_image.gif"; //$NON-NLS-1$
+    public static final String IMG_OBJECT_CLASS = "resources/icons/object_class.png"; //$NON-NLS-1$
+    public static final String IMG_SWITCH_TEMPLATE = "resources/icons/switch_template.gif"; //$NON-NLS-1$
+    public static final String IMG_TEMPLATE = "resources/icons/template.gif"; //$NON-NLS-1$
+    public static final String IMG_TEMPLATE_DISABLED = "resources/icons/template_disabled.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_ADD_VALUE = "resources/icons/toolbar_add_value.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_BROWSE_FILE = "resources/icons/toolbar_browse_file.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_BROWSE_IMAGE = "resources/icons/toolbar_browse_image.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_CLEAR = "resources/icons/toolbar_clear.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_DELETE_VALUE = "resources/icons/toolbar_delete_value.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_EDIT_PASSWORD = "resources/icons/toolbar_edit_password.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_EDIT_DATE = "resources/icons/toolbar_edit_date.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_EDIT_VALUE = "resources/icons/toolbar_edit_value.gif"; //$NON-NLS-1$
+    public static final String IMG_TOOLBAR_SAVE_AS = "resources/icons/toolbar_save_as.gif"; //$NON-NLS-1$
+
+    // Preferences
+    public static final String PREF_TEMPLATE_ENTRY_EDITOR_PAGE_ID = "org.apache.directory.studio.templateeditor.view.preferences.TemplateEntryEditorPreferencePage"; //$NON-NLS-1$
+    public static final String PREF_TEMPLATES_PRESENTATION = PLUGIN_ID + ".prefs.TemplatesPresentation"; //$NON-NLS-1$
+    public static final int PREF_TEMPLATES_PRESENTATION_TEMPLATE = 1;
+    public static final int PREF_TEMPLATES_PRESENTATION_OBJECT_CLASS = 2;
+    public static final String PREF_DISABLED_TEMPLATES = PLUGIN_ID + ".prefs.DisabledTemplates"; //$NON-NLS-1$
+    public static final String PREF_USE_TEMPLATE_EDITOR_FOR = PLUGIN_ID + ".prefs.UseTemplateEditorFor"; //$NON-NLS-1$
+    public static final int PREF_USE_TEMPLATE_EDITOR_FOR_ANY_ENTRY = 1;
+    public static final int PREF_USE_TEMPLATE_EDITOR_FOR_ENTRIES_WITH_TEMPLATE = 2;
+    public static final String PREF_DEFAULT_TEMPLATES = PLUGIN_ID + ".prefs.DefaultTemplates"; //$NON-NLS-1$
+
+    // Dialogs
+    public static final String DIALOG_IMPORT_TEMPLATES = PLUGIN_ID + ".dialog.ImportTemplates"; //$NON-NLS-1$
+    public static final String DIALOG_EXPORT_TEMPLATES = PLUGIN_ID + ".dialog.ExportTemplates"; //$NON-NLS-1$
+}

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginUtils.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginUtils.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePluginUtils.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,496 @@
+/*
+ *  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.templateeditor;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.collections.map.MultiValueMap;
+import org.apache.directory.api.ldap.model.schema.ObjectClass;
+import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.eclipse.core.runtime.Status;
+
+import org.apache.directory.studio.templateeditor.model.Template;
+
+
+/**
+ * This class is a helper class for the Entry Template plugin.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryTemplatePluginUtils
+{
+    /** The line separator */
+    public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); //$NON-NLS-1$
+
+    /** The default schema */
+    private static final Schema DEFAULT_SCHEMA = Schema.DEFAULT_SCHEMA;
+
+
+    /**
+     * Logs the given message and exception with the ERROR status level.
+     * 
+     * @param exception
+     *      the exception, can be <code>null</code>
+     * @param message
+     *      the message
+     * @param args
+     *      the arguments to use when formatting the message
+     */
+    public static void logError( Throwable exception, String message, Object... args )
+    {
+        EntryTemplatePlugin.getDefault().getLog().log(
+            new Status( Status.ERROR, EntryTemplatePlugin.getDefault().getBundle().getSymbolicName(), Status.OK,
+                MessageFormat.format( message, args ), exception ) );
+    }
+
+
+    /**
+     * Logs the given message and exception with the WARNING status level.
+     * 
+     * @param exception
+     *      the exception, can be <code>null</code>
+     * @param message
+     *      the message
+     * @param args
+     *      the arguments to use when formatting the message
+     */
+    public static void logWarning( Throwable exception, String message, Object... args )
+    {
+        EntryTemplatePlugin.getDefault().getLog().log(
+            new Status( Status.WARNING, EntryTemplatePlugin.getDefault().getBundle().getSymbolicName(), Status.OK,
+                MessageFormat.format( message, args ), exception ) );
+    }
+
+
+    /**
+     * Logs the given message and exception with the INFO status level.
+     * 
+     * @param exception
+     *      the exception, can be <code>null</code>
+     * @param message
+     *      the message
+     * @param args
+     *      the arguments to use when formatting the message
+     */
+    public static void logInfo( Throwable exception, String message, Object... args )
+    {
+        EntryTemplatePlugin.getDefault().getLog().log(
+            new Status( Status.INFO, EntryTemplatePlugin.getDefault().getBundle().getSymbolicName(), Status.OK,
+                MessageFormat.format( message, args ), exception ) );
+    }
+
+
+    /**
+     * Logs the given message and exception with the OK status level.
+     * 
+     * @param exception
+     *      the exception, can be <code>null</code>
+     * @param message
+     *      the message
+     * @param args
+     *      the arguments to use when formatting the message
+     */
+    public static void logOk( Throwable exception, String message, Object... args )
+    {
+        EntryTemplatePlugin.getDefault().getLog().log(
+            new Status( Status.OK, EntryTemplatePlugin.getDefault().getBundle().getSymbolicName(), Status.OK,
+                MessageFormat.format( message, args ), exception ) );
+    }
+
+
+    /**
+     * Copies a file from the given streams.
+     *
+     * @param source
+     *      the source file
+     * @param destination
+     *      the destination file
+     * @throws IOException
+     *      if an error occurs when copying the file
+     */
+    public static void copyFile( File source, File destination ) throws IOException
+    {
+        copyFile( new FileInputStream( source ), new FileOutputStream( destination ) );
+    }
+
+
+    /**
+     * Copies the input stream to the output stream.
+     *
+     * @param inputStream
+     *      the input stream
+     * @param outputStream
+     *      the output stream
+     * @throws IOException
+     *      if an error occurs when copying the stream
+     */
+    public static void copyFile( InputStream inputStream, OutputStream outputStream ) throws IOException
+    {
+        byte[] buf = new byte[1024];
+        int i = 0;
+        while ( ( i = inputStream.read( buf ) ) != -1 )
+        {
+            outputStream.write( buf, 0, i );
+        }
+    }
+
+
+    /**
+     * Gets a list of templates matching the given entry.
+     * 
+     * @param entry
+     *      the entry
+     * @return
+     *      a list of templates matching the given entry
+     */
+    public static List<Template> getMatchingTemplates( IEntry entry )
+    {
+        if ( entry != null )
+        {
+            // Looking for the highest (most specialized one) structural object class in the entry
+            ObjectClass highestStructuralObjectClass = getHighestStructuralObjectClassFromEntry( entry );
+            if ( highestStructuralObjectClass != null )
+            {
+                // We were able to determine the highest object class in the entry.
+
+                // Based on that information, we will use the entry's schema to retrieve the list of matching templates
+                return getTemplatesFromHighestObjectClass( highestStructuralObjectClass, entry.getBrowserConnection()
+                    .getSchema() );
+            }
+            else
+            {
+                // We were not able to determine the highest object class in the entry.
+                // This means that either the schema information we received from the server is not sufficient,
+                // or the list of object classes in the entry is not complete.
+
+                // In that case we can't use the schema information to determine the list of templates.
+                // Instead we're going to gather all the templates associated with each object class description.
+                return getTemplatesFromObjectClassDescriptions( entry.getObjectClassDescriptions() );
+            }
+        }
+
+        return new ArrayList<Template>();
+    }
+
+
+    /**
+     * Gets the highest (most specialized one) object class description of the given entry 
+     * if it can be found, or <code>null</code> if not.
+     *
+     * @param entry
+     *      the entry
+     * @return
+     *      the highest object class description of the given entry if it can be found, 
+     *      or <code>null</code> if not
+     */
+    private static ObjectClass getHighestStructuralObjectClassFromEntry( IEntry entry )
+    {
+        if ( entry != null )
+        {
+            if ( ( entry.getBrowserConnection() != null ) && ( entry.getBrowserConnection().getSchema() != null ) )
+            {
+                // Getting the schema from the entry
+                Schema schema = entry.getBrowserConnection().getSchema();
+
+                // Getting object class descriptions
+                Collection<ObjectClass> objectClassDescriptions = entry.getObjectClassDescriptions();
+                if ( objectClassDescriptions != null )
+                {
+                    // Creating the candidates list based on the initial list
+                    List<ObjectClass> candidatesList = new ArrayList<ObjectClass>();
+
+                    // Adding each structural object class description to the list
+                    for ( ObjectClass objectClassDescription : objectClassDescriptions )
+                    {
+                        if ( objectClassDescription.getType() == ObjectClassTypeEnum.STRUCTURAL )
+                        {
+                            candidatesList.add( objectClassDescription );
+                        }
+                    }
+
+                    // Looping on the given collection of ObjectClassDescription until the end of the list, 
+                    // or until the candidates list is reduced to one.
+                    Iterator<ObjectClass> iterator = objectClassDescriptions.iterator();
+                    while ( ( candidatesList.size() > 1 ) && ( iterator.hasNext() ) )
+                    {
+                        ObjectClass ocd = iterator.next();
+                        removeSuperiors( ocd, candidatesList, schema );
+                    }
+
+                    // Looking if we've found the highest object class description
+                    if ( candidatesList.size() == 1 )
+                    {
+                        return candidatesList.get( 0 );
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Recursively removes superiors of the given object class description from the list.
+     *
+     * @param ocd
+     *      the object class description
+     * @param ocdList
+     *      the list of object class description
+     * @param schema
+     *      the schema
+     */
+    private static void removeSuperiors( ObjectClass ocd, List<ObjectClass> ocdList, Schema schema )
+    {
+        if ( ocd != null )
+        {
+            for ( String superior : ocd.getSuperiorOids() )
+            {
+                // Getting the ObjectClassDescription associated with the superior
+                ObjectClass superiorOcd = getObjectClass( superior, schema );
+
+                // Removing it from the list and recursively removing its superiors
+                ocdList.remove( superiorOcd );
+                removeSuperiors( superiorOcd, ocdList, schema );
+            }
+        }
+    }
+
+
+    /**
+     * Gets the list of matching templates for the given object class description.
+     * <p>
+     * To do this, we're using a "Breadth First Search" algorithm to go through all
+     * the superiors (and the superiors of these superiors, etc.).
+     *
+     * @param objectClassDescription
+     *      the object class description
+     * @param schema
+     *      the associated schema
+     * @return
+     *      the list of matching templates for the given object class description
+     */
+    private static List<Template> getTemplatesFromHighestObjectClass( ObjectClass objectClassDescription,
+        Schema schema )
+    {
+        // Creating a set to hold all the matching templates
+        List<Template> matchingTemplates = new ArrayList<Template>();
+
+        // Getting the templates manager
+        TemplatesManager manager = EntryTemplatePlugin.getDefault().getTemplatesManager();
+
+        // Getting the list of all the available templates
+        Template[] templates = manager.getTemplates();
+
+        // Creating a MultiValueMap that holds the templates ordered by ObjectClassDescription object
+        MultiValueMap templatesByOcd = new MultiValueMap();
+
+        // Populating this map
+        for ( Template template : templates )
+        {
+            templatesByOcd.put( getObjectClass( template.getStructuralObjectClass(), schema ), template );
+        }
+
+        // Initializing the LIFO queue with the highest ObjectClassDescription object
+        LinkedList<ObjectClass> ocdQueue = new LinkedList<ObjectClass>();
+        ocdQueue.add( objectClassDescription );
+
+        // Looking if we need to test a new ObjectClassDescription object
+        while ( !ocdQueue.isEmpty() )
+        {
+            // Dequeuing the last object for testing
+            ObjectClass currentOcd = ocdQueue.removeLast();
+
+            // Adds the templates for the current object class description to the list of matching templates
+            addTemplatesForObjectClassDescription( currentOcd, matchingTemplates, manager );
+
+            // Adding each superior object to the queue
+            List<String> currentOcdSups = currentOcd.getSuperiorOids();
+            if ( currentOcdSups != null )
+            {
+                for ( String currentOcdSup : currentOcdSups )
+                {
+                    ocdQueue.addFirst( getObjectClass( currentOcdSup, schema ) );
+                }
+            }
+        }
+
+        return matchingTemplates;
+    }
+
+
+    /**
+     * Gets the list of matching templates for the given object class descriptions.
+     *
+     * @param objectClasses
+     *      the object classes
+     * @return
+     *      the list of matching templates for the given object class description
+     */
+    private static List<Template> getTemplatesFromObjectClassDescriptions(
+        Collection<ObjectClass> objectClasses )
+    {
+        if ( objectClasses != null )
+        {
+            // Creating a set to hold all the matching templates
+            List<Template> matchingTemplates = new ArrayList<Template>();
+
+            // Getting the templates manager
+            TemplatesManager manager = EntryTemplatePlugin.getDefault().getTemplatesManager();
+
+            for ( ObjectClass objectClassDescription : objectClasses )
+            {
+                // Adds the templates for the current object class description to the list of matching templates
+                addTemplatesForObjectClassDescription( objectClassDescription, matchingTemplates, manager );
+            }
+
+            return matchingTemplates;
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Adds the templates found for the given object class description to the given templates set.
+     *
+     * @param ocd
+     *      the object class description
+     * @param matchingTemplates
+     *      the list of matching templates
+     * @param manager
+     *      the manager
+     */
+    private static void addTemplatesForObjectClassDescription( ObjectClass ocd,
+        List<Template> matchingTemplates, TemplatesManager manager )
+    {
+        // Creating a list of containing the names and OID of the current ObjectClassDescription object
+        List<String> namesAndOid = new ArrayList<String>();
+        for ( String name : ocd.getNames() )
+        {
+            namesAndOid.add( name );
+        }
+        String currentOcdOid = ocd.getOid();
+        if ( ( currentOcdOid != null ) && ( !"".equals( currentOcdOid ) ) ) //$NON-NLS-1$
+        {
+            namesAndOid.add( currentOcdOid );
+        }
+
+        // Looping on the names and OID to find all corresponding templates
+        for ( String nameOrOid : namesAndOid )
+        {
+            // Getting the default template and complete list of templates for the given name or OID
+            Template currentOcdDefaultTemplate = manager.getDefaultTemplate( nameOrOid );
+            List<Template> currentOcdTemplates = manager.getTemplatesByObjectClass( nameOrOid );
+
+            // Adding the default template
+            if ( currentOcdDefaultTemplate != null )
+            {
+                if ( !matchingTemplates.contains( currentOcdDefaultTemplate ) )
+                {
+                    matchingTemplates.add( currentOcdDefaultTemplate );
+                }
+            }
+
+            // Adding the other templates
+            if ( currentOcdTemplates != null )
+            {
+                for ( Template template : currentOcdTemplates )
+                {
+                    // Adding the template only if it is different from the default one (which is already added)
+                    if ( ( !template.equals( currentOcdDefaultTemplate ) ) && ( manager.isEnabled( template ) )
+                        && ( !matchingTemplates.contains( template ) ) )
+                    {
+                        matchingTemplates.add( template );
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Gets the object class description of the given name or OID found in the default schema.
+     * <p>
+     * If no object class description is found in the default schema, a new object class description
+     * is created with the given name or OID and returned.
+     *
+     * @param nameOrOid
+     *      the name or OID
+     * @return
+     *      the object class description of the given name or OID found in the default schema,
+     *      or a new object class description created with the given name or OID if none can be found
+     */
+    public static ObjectClass getObjectClassDescriptionFromDefaultSchema( String nameOrOid )
+    {
+        return getObjectClass( nameOrOid, DEFAULT_SCHEMA );
+    }
+
+
+    /**
+     * Gets the object class description of the given name or OID found in the given schema.
+     * <p>
+     * If no object class description is found in the given schema, a new object class description
+     * is created with the given name or OID and returned.
+     *
+     * @param nameOrOid
+     *      the name or OID
+     * @param schema
+     *      the schema
+     * @return
+     *      the object class description of the given name or OID found in the given schema,
+     *      or a new object class description created with the given name or OID if none can be found
+     */
+    private static ObjectClass getObjectClass( String nameOrOid, Schema schema )
+    {
+        ObjectClass ocd = null;
+
+        // Looking for the object class description in the given schema
+        if ( schema != null )
+        {
+            ocd = schema.getObjectClassDescription( nameOrOid );
+        }
+
+        // Creating a new object class description if none could be found in the given schema
+        if ( ocd == null )
+        {
+            ocd = new ObjectClass( null );
+            ocd.setNames( Arrays.asList( new String[]
+                { nameOrOid.toLowerCase() } ) );
+        }
+
+        return ocd;
+    }
+}

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/Messages.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/Messages.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/Messages.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/Messages.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,53 @@
+/*
+ *  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.templateeditor;
+
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Messages
+{
+    private static final String BUNDLE_NAME = "org.apache.directory.studio.templateeditor.messages"; //$NON-NLS-1$
+
+    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
+
+
+    private Messages()
+    {
+    }
+
+
+    public static String getString( String key )
+    {
+        try
+        {
+            return RESOURCE_BUNDLE.getString( key );
+        }
+        catch ( MissingResourceException e )
+        {
+            return '!' + key + '!';
+        }
+    }
+}

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/PreferenceInitializer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/PreferenceInitializer.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/PreferenceInitializer.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/PreferenceInitializer.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,51 @@
+/*
+ *  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.templateeditor;
+
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+
+/**
+ * This class initializes the preferences of the plugin.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer
+{
+    /**
+     * {@inheritDoc}
+     */
+    public void initializeDefaultPreferences()
+    {
+        IPreferenceStore store = EntryTemplatePlugin.getDefault().getPreferenceStore();
+
+        // Preferences
+        store.setDefault( EntryTemplatePluginConstants.PREF_TEMPLATES_PRESENTATION,
+            EntryTemplatePluginConstants.PREF_TEMPLATES_PRESENTATION_OBJECT_CLASS );
+        store.setDefault( EntryTemplatePluginConstants.PREF_DISABLED_TEMPLATES, "" ); //$NON-NLS-1$
+        store.setDefault( EntryTemplatePluginConstants.PREF_USE_TEMPLATE_EDITOR_FOR,
+            EntryTemplatePluginConstants.PREF_USE_TEMPLATE_EDITOR_FOR_ENTRIES_WITH_TEMPLATE );
+
+        // Dialogs
+        store.setDefault( EntryTemplatePluginConstants.DIALOG_IMPORT_TEMPLATES, System.getProperty( "user.home" ) ); //$NON-NLS-1$
+    }
+}

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManager.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManager.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManager.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,875 @@
+/*
+ *  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.templateeditor;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.commons.collections.map.MultiValueMap;
+import org.apache.directory.api.ldap.model.schema.ObjectClass;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import org.apache.directory.studio.templateeditor.model.ExtensionPointTemplate;
+import org.apache.directory.studio.templateeditor.model.FileTemplate;
+import org.apache.directory.studio.templateeditor.model.Template;
+import org.apache.directory.studio.templateeditor.model.parser.TemplateIO;
+import org.apache.directory.studio.templateeditor.model.parser.TemplateIOException;
+
+
+/**
+ * This class is used to manage the templates.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TemplatesManager
+{
+    /** The preference delimiter used for default and disabled templates */
+    private static String PREFERENCE_DELIMITER = ";"; //$NON-NLS-1$
+
+    /** The preference sub delimiter used for default templates */
+    private static String PREFERENCE_SUB_DELIMITER = ":"; //$NON-NLS-1$
+
+    /** The plugin's preference store */
+    private IPreferenceStore preferenceStore;
+
+    /** The list containing all the templates */
+    private List<Template> templatesList = new ArrayList<Template>();
+
+    /** The maps containing all the templates by their id */
+    private Map<String, Template> templatesByIdMap = new HashMap<String, Template>();
+
+    /** The maps containing all the templates by ObjectClassDescription */
+    private MultiValueMap templatesByStructuralObjectClassMap = new MultiValueMap();
+
+    /** The list containing *only* the IDs of the disabled templates */
+    private List<String> disabledTemplatesList = new ArrayList<String>();
+
+    /** The map containing the default templates */
+    private Map<ObjectClass, String> defaultTemplatesMap = new HashMap<ObjectClass, String>();
+
+    /** The list of listeners */
+    private List<TemplatesManagerListener> listeners = new ArrayList<TemplatesManagerListener>();
+
+
+    /**
+     * Creates a new instance of TemplatesManager.
+     *
+     * @param preferenceStore
+     *      the plugin's preference store
+     */
+    public TemplatesManager( IPreferenceStore preferenceStore )
+    {
+        this.preferenceStore = preferenceStore;
+
+        loadDefaultTemplates();
+        loadDisabledTemplates();
+        loadTemplates();
+        setDefaultTemplates();
+    }
+
+
+    /**
+     * Adds a listener.
+     *
+     * @param listener
+     *      the listener
+     * @return
+     *      <code>true</code> (as per the general contract of the
+     *      <code>Collection.add</code> method).
+     */
+    public boolean addListener( TemplatesManagerListener listener )
+    {
+        return listeners.add( listener );
+    }
+
+
+    /**
+     * Removes a listener.
+     *
+     * @param listener
+     *      the listener
+     * @return
+     *      <code>true</code> if this templates manager contained 
+     *      the specified listener.
+     */
+    public boolean removeListener( TemplatesManagerListener listener )
+    {
+        return listeners.remove( listener );
+    }
+
+
+    /**
+     * Fires a "fireTemplateAdded" event to all the listeners.
+     *
+     * @param template
+     *      the added template
+     */
+    private void fireTemplateAdded( Template template )
+    {
+        for ( TemplatesManagerListener listener : listeners.toArray( new TemplatesManagerListener[0] ) )
+        {
+            listener.templateAdded( template );
+        }
+    }
+
+
+    /**
+     * Fires a "templateRemoved" event to all the listeners.
+     *
+     * @param template
+     *      the removed template
+     */
+    private void fireTemplateRemoved( Template template )
+    {
+        for ( TemplatesManagerListener listener : listeners.toArray( new TemplatesManagerListener[0] ) )
+        {
+            listener.templateRemoved( template );
+        }
+    }
+
+
+    /**
+     * Fires a "templateEnabled" event to all the listeners.
+     *
+     * @param template
+     *      the enabled template
+     */
+    private void fireTemplateEnabled( Template template )
+    {
+        for ( TemplatesManagerListener listener : listeners.toArray( new TemplatesManagerListener[0] ) )
+        {
+            listener.templateEnabled( template );
+        }
+    }
+
+
+    /**
+    * Fires a "templateDisabled" event to all the listeners.
+    *
+    * @param template
+    *      the disabled template
+    */
+    private void fireTemplateDisabled( Template template )
+    {
+        for ( TemplatesManagerListener listener : listeners.toArray( new TemplatesManagerListener[0] ) )
+        {
+            listener.templateDisabled( template );
+        }
+    }
+
+
+    /**
+     * Loads the templates
+     */
+    private void loadTemplates()
+    {
+        // Loading the templates added using the extension point
+        loadExtensionPointTemplates();
+
+        // Loading the templates added via files on the disk (added by the user)
+        loadFileTemplates();
+    }
+
+
+    /**
+     * Loads the templates added using the extension point.
+     */
+    private void loadExtensionPointTemplates()
+    {
+        // Getting the extension point
+        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
+            "org.apache.directory.studio.templateeditor.templates" ); //$NON-NLS-1$
+
+        // Getting all the extensions
+        IConfigurationElement[] members = extensionPoint.getConfigurationElements();
+        if ( members != null )
+        {
+            // For each extension: load the template
+            for ( int m = 0; m < members.length; m++ )
+            {
+                IConfigurationElement member = members[m];
+
+                // Getting the URL of the file associated with the extension
+                String contributorName = member.getContributor().getName();
+                String filePathInPlugin = member.getAttribute( "file" ); //$NON-NLS-1$
+                URL fileUrl = Platform.getBundle( contributorName ).getResource( filePathInPlugin );
+
+                // Checking if the URL is null
+                if ( filePathInPlugin == null )
+                {
+                    // Logging the error
+                    EntryTemplatePluginUtils.logError( new NullPointerException(), Messages
+                        .getString( "TemplatesManager.AnErrorOccurredWhenParsingTheTemplate3Params" ), contributorName, //$NON-NLS-1$
+                        filePathInPlugin, Messages.getString( "TemplatesManager.URLCreatedForTheTemplateIsNull" ) ); //$NON-NLS-1$
+                }
+
+                // Parsing the template and adding it to the templates list
+                try
+                {
+                    InputStream is = fileUrl.openStream();
+
+                    ExtensionPointTemplate template = TemplateIO.readAsExtensionPointTemplate( is );
+
+                    templatesList.add( template );
+                    templatesByIdMap.put( template.getId(), template );
+                    templatesByStructuralObjectClassMap.put( EntryTemplatePluginUtils
+                        .getObjectClassDescriptionFromDefaultSchema( template.getStructuralObjectClass() ), template );
+
+                    is.close();
+                }
+                catch ( TemplateIOException e )
+                {
+                    // Logging the error
+                    EntryTemplatePluginUtils.logError( e, Messages
+                        .getString( "TemplatesManager.AnErrorOccurredWhenParsingTheTemplate3Params" ), //$NON-NLS-1$
+                        contributorName, filePathInPlugin, e.getMessage() );
+                }
+                catch ( IOException e )
+                {
+                    // Logging the error
+                    EntryTemplatePluginUtils.logError( e, Messages
+                        .getString( "TemplatesManager.AnErrorOccurredWhenParsingTheTemplate3Params" ), contributorName, //$NON-NLS-1$
+                        filePathInPlugin, e.getMessage() );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Loads the templates added via files on the disk (added by the user).
+     */
+    private void loadFileTemplates()
+    {
+        // Getting the templates folder
+        File templatesFolder = getTemplatesFolder().toFile();
+
+        // If the templates folder does not exist, we exit
+        if ( !templatesFolder.exists() )
+        {
+            return;
+        }
+
+        // Loading the templates contained in the templates folder
+        String[] templateNames = templatesFolder.list( new FilenameFilter()
+        {
+            public boolean accept( File dir, String name )
+            {
+                return name.endsWith( ".xml" ); //$NON-NLS-1$
+            }
+        } );
+
+        // If there are no templates available, we exit
+        if ( ( templateNames == null ) || ( templateNames.length == 0 ) )
+        {
+            return;
+        }
+
+        // Loading each template
+        for ( String templateName : templateNames )
+        {
+            // Creating the template file
+            File templateFile = new File( templatesFolder, templateName );
+
+            // Parsing the template and adding it to the templates list
+            try
+            {
+                InputStream is = new FileInputStream( templateFile );
+
+                FileTemplate template = TemplateIO.readAsFileTemplate( is );
+                templatesList.add( template );
+                templatesByIdMap.put( template.getId(), template );
+                templatesByStructuralObjectClassMap.put( EntryTemplatePluginUtils
+                    .getObjectClassDescriptionFromDefaultSchema( template.getStructuralObjectClass() ), template );
+
+                is.close();
+            }
+            catch ( TemplateIOException e )
+            {
+                // Logging the error
+                EntryTemplatePluginUtils.logError( e, Messages
+                    .getString( "TemplatesManager.AnErrorOccurredWhenParsingTheTemplate2Params" ), //$NON-NLS-1$
+                    templateFile.getAbsolutePath(), e.getMessage() );
+            }
+            catch ( IOException e )
+            {
+                // Logging the error
+                EntryTemplatePluginUtils.logError( e, Messages
+                    .getString( "TemplatesManager.AnErrorOccurredWhenParsingTheTemplate2Params" ), //$NON-NLS-1$
+                    templateFile.getAbsolutePath(), e.getMessage() );
+            }
+        }
+    }
+
+
+    /**
+     * Adds a template from a file on the disk.
+     *
+     * @param templateFile
+     *      the template file
+     * @return
+     *      <code>true</code> if the template file has been successfully added,
+     *      <code>false</code> if the template file has not been added
+     */
+    public boolean addTemplate( File templateFile )
+    {
+        // Getting the file template
+        FileTemplate fileTemplate = getFileTemplate( templateFile );
+        if ( fileTemplate == null )
+        {
+            // If the file is not valid, we simply return
+            return false;
+        }
+
+        // Verifying if a template with a similar ID does not already exist
+        if ( templatesByIdMap.containsKey( fileTemplate.getId() ) )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils.logError( null, Messages
+                .getString( "TemplatesManager.TheTemplateFileCouldNotBeAddedBecauseATemplateWithSameIDAlreadyExist" ), //$NON-NLS-1$
+                templateFile.getAbsolutePath() );
+            return false;
+        }
+
+        // Verifying the folder containing the templates already exists
+        // If not we create it
+        File templatesFolder = getTemplatesFolder().toFile();
+        if ( !templatesFolder.exists() )
+        {
+            // The folder does not exist, we need to create it.
+            templatesFolder.mkdirs();
+        }
+
+        // Copying the template in the plugin's folder
+        try
+        {
+            // Creating the file object where the template will be saved
+            File destinationFile = getTemplatesFolder().append( fileTemplate.getId() + ".xml" ).toFile(); //$NON-NLS-1$
+
+            // Checking if the file does not already exist
+            if ( destinationFile.exists() )
+            {
+                // Logging the error
+                EntryTemplatePluginUtils
+                    .logError(
+                        null,
+                        Messages
+                            .getString( "TemplatesManager.TheTemplateFileCouldNotBeAddedBecauseATemplateWithSameIDAlreadyExist" ), //$NON-NLS-1$
+                        templateFile.getAbsolutePath() );
+                return false;
+            }
+
+            // Copying the file
+            EntryTemplatePluginUtils.copyFile( templateFile, destinationFile );
+        }
+        catch ( IOException e )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils
+                .logError(
+                    null,
+                    Messages.getString( "TemplatesManager.TheTemplateFileCouldNotBeCopiedToThePluginsFolder" ), templateFile.getAbsolutePath() ); //$NON-NLS-1$
+            return false;
+        }
+
+        // Adding the template
+        templatesList.add( fileTemplate );
+        templatesByIdMap.put( fileTemplate.getId(), fileTemplate );
+        templatesByStructuralObjectClassMap.put( EntryTemplatePluginUtils
+            .getObjectClassDescriptionFromDefaultSchema( fileTemplate.getStructuralObjectClass() ), fileTemplate );
+
+        // Firing the event
+        fireTemplateAdded( fileTemplate );
+
+        return true;
+    }
+
+
+    /**
+     * Get the file template associate with the template file.
+     *
+     * @param templateFile
+     *      the template file
+     * @return
+     *      the associated file template
+     */
+    private FileTemplate getFileTemplate( File templateFile )
+    {
+        // Checking if the file exists
+        if ( !templateFile.exists() )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils.logError( null, Messages
+                .getString( "TemplatesManager.TheTemplateFileCouldNotBeAddedBecauseItDoesNotExist" ), templateFile //$NON-NLS-1$
+                .getAbsolutePath() );
+            return null;
+        }
+
+        // Checking if the file is readable
+        if ( !templateFile.canRead() )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils
+                .logError(
+                    null,
+                    Messages.getString( "TemplatesManager.TheTemplateFileCouldNotBeAddedBecauseItCantBeRead" ), templateFile.getAbsolutePath() ); //$NON-NLS-1$
+            return null;
+        }
+
+        // Trying to parse the template file
+        FileTemplate fileTemplate = null;
+        try
+        {
+            FileInputStream fis = new FileInputStream( templateFile );
+            fileTemplate = TemplateIO.readAsFileTemplate( fis );
+        }
+        catch ( FileNotFoundException e )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils.logError( e, Messages
+                .getString( "TemplatesManager.TheTemplateFileCouldNotBeAddedBecauseOfTheFollowingError" ), templateFile //$NON-NLS-1$
+                .getAbsolutePath(), e.getMessage() );
+            return null;
+        }
+        catch ( TemplateIOException e )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils.logError( e, Messages
+                .getString( "TemplatesManager.TheTemplateFileCouldNotBeAddedBecauseOfTheFollowingError" ), templateFile //$NON-NLS-1$
+                .getAbsolutePath(), e.getMessage() );
+            return null;
+        }
+
+        // Everything went fine, the file is valid
+        return fileTemplate;
+    }
+
+
+    /**
+     * Removes a template.
+     * 
+     * @param fileTemplate
+     *      the file template to remove
+     * @return
+     *      <code>true</code> if the file template has been successfully removed,
+     *      <code>false</code> if the template file has not been removed
+     */
+    public boolean removeTemplate( FileTemplate fileTemplate )
+    {
+        // Checking if the file template is null
+        if ( fileTemplate == null )
+        {
+            return false;
+        }
+
+        // Checking if the file template exists in the templates set
+        if ( !templatesList.contains( fileTemplate ) )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils
+                .logError(
+                    null,
+                    Messages.getString( "TemplatesManager.TheTemplateCouldNotBeRemovedBecauseOfTheFollowingError" ) //$NON-NLS-1$
+                        + Messages.getString( "TemplatesManager.TheTemplateDoesNotExistInTheTemplateManager" ), fileTemplate.getTitle(), fileTemplate //$NON-NLS-1$
+                        .getId() );
+            return false;
+        }
+
+        // Creating the file object associated with the template
+        File templateFile = getTemplatesFolder().append( fileTemplate.getId() + ".xml" ).toFile(); //$NON-NLS-1$
+
+        // Checking if the file exists
+        if ( !templateFile.exists() )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils
+                .logError(
+                    null,
+                    Messages.getString( "TemplatesManager.TheTemplateCouldNotBeRemovedBecauseOfTheFollowingError" ) //$NON-NLS-1$
+                        + Messages.getString( "TemplatesManager.TheFileAssociatedWithTheTemplateCouldNotBeFoundAt" ), fileTemplate.getTitle(), //$NON-NLS-1$
+                    fileTemplate.getId(), templateFile.getAbsolutePath() );
+            return false;
+        }
+
+        // Checking if the file can be written, and thus deleted
+        if ( !templateFile.canWrite() )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils
+                .logError(
+                    null,
+                    Messages.getString( "TemplatesManager.TheTemplateCouldNotBeRemovedBecauseOfTheFollowingError" ) //$NON-NLS-1$
+                        + Messages.getString( "TemplatesManager.TheFileAssociatedWithTheTemplateCanNotBeModified" ), fileTemplate.getTitle(), //$NON-NLS-1$
+                    fileTemplate.getId(), templateFile.getAbsolutePath() );
+            return false;
+        }
+
+        // Deleting the file
+        if ( !templateFile.delete() )
+        {
+            // Logging the error
+            EntryTemplatePluginUtils
+                .logError(
+                    null,
+                    Messages.getString( "TemplatesManager.TheTemplateCouldNotBeRemovedBecauseOfTheFollowingError" ) //$NON-NLS-1$
+                        + Messages
+                            .getString( "TemplatesManager.AnErrorOccurredWhenRemovingTheFileAssociatedWithTheTemplate" ), fileTemplate //$NON-NLS-1$
+                        .getTitle(), fileTemplate.getId(), templateFile.getAbsolutePath() );
+            return false;
+        }
+
+        // Removing the template from the disabled templates files
+        disabledTemplatesList.remove( fileTemplate );
+
+        // Removing the template for the templates list
+        templatesList.remove( fileTemplate );
+        templatesByIdMap.remove( fileTemplate.getId() );
+        templatesByStructuralObjectClassMap.remove( EntryTemplatePluginUtils
+            .getObjectClassDescriptionFromDefaultSchema( fileTemplate.getStructuralObjectClass() ) );
+
+        // Firing the event
+        fireTemplateRemoved( fileTemplate );
+
+        return true;
+    }
+
+
+    /**
+     * Gets the templates.
+     *
+     * @return
+     *      the templates
+     */
+    public Template[] getTemplates()
+    {
+        return templatesList.toArray( new Template[0] );
+    }
+
+
+    /**
+     * Gets the templates folder.
+     *
+     * @return
+     *      the templates folder
+     */
+    private static IPath getTemplatesFolder()
+    {
+        return EntryTemplatePlugin.getDefault().getStateLocation().append( "templates" ); //$NON-NLS-1$
+    }
+
+
+    /**
+     * Loads the {@link List} of disabled templates from the preference store.
+     */
+    private void loadDisabledTemplates()
+    {
+        StringTokenizer tokenizer = new StringTokenizer( preferenceStore
+            .getString( EntryTemplatePluginConstants.PREF_DISABLED_TEMPLATES ), PREFERENCE_DELIMITER );
+        while ( tokenizer.hasMoreTokens() )
+        {
+            disabledTemplatesList.add( tokenizer.nextToken() );
+        }
+    }
+
+
+    /**
+     * Saves the {@link List} of disabled templates to the preference store.
+     */
+    private void saveDisabledTemplates()
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( String disabledTemplateId : disabledTemplatesList )
+        {
+            sb.append( disabledTemplateId );
+            sb.append( PREFERENCE_DELIMITER );
+        }
+        preferenceStore.setValue( EntryTemplatePluginConstants.PREF_DISABLED_TEMPLATES, sb.toString() );
+    }
+
+
+    /**
+     * Enables the given template.
+     *
+     * @param template
+     *      the template
+     */
+    public void enableTemplate( Template template )
+    {
+        if ( disabledTemplatesList.contains( template.getId() ) )
+        {
+            // Removing the id of the template to the list of disabled templates
+            disabledTemplatesList.remove( template.getId() );
+
+            // Saving the disabled templates list
+            saveDisabledTemplates();
+
+            // Firing the event
+            fireTemplateEnabled( template );
+        }
+    }
+
+
+    /**
+     * Disables the given template.
+     *
+     * @param template
+     *      the template
+     */
+    public void disableTemplate( Template template )
+    {
+        if ( !disabledTemplatesList.contains( template.getId() ) )
+        {
+            // Adding the id of the template to the list of disabled templates
+            disabledTemplatesList.add( template.getId() );
+
+            // Saving the disabled templates list
+            saveDisabledTemplates();
+
+            // Firing the event
+            fireTemplateDisabled( template );
+        }
+    }
+
+
+    /**
+     * Indicates if the given template is enabled or not.
+     *
+     * @param template  
+     *      the template
+     * @return
+     *      <code>true</code> if the template is enabled,
+     *      <code>false</code> if the template is disabled
+     */
+    public boolean isEnabled( Template template )
+    {
+        return !disabledTemplatesList.contains( template.getId() );
+    }
+
+
+    /**
+     * Loads the {@link Map} of default templates from the preference store.
+     */
+    private void loadDefaultTemplates()
+    {
+        // Getting each default set
+        StringTokenizer tokenizer = new StringTokenizer( preferenceStore
+            .getString( EntryTemplatePluginConstants.PREF_DEFAULT_TEMPLATES ), PREFERENCE_DELIMITER );
+        while ( tokenizer.hasMoreTokens() )
+        {
+            String token = tokenizer.nextToken();
+
+            // Splitting the default set
+            String[] splittedToken = token.split( ":" ); //$NON-NLS-1$
+            if ( splittedToken.length == 2 )
+            {
+                // Adding the default template value
+                defaultTemplatesMap.put( EntryTemplatePluginUtils
+                    .getObjectClassDescriptionFromDefaultSchema( splittedToken[0] ), splittedToken[1] );
+            }
+        }
+    }
+
+
+    /**
+     * Saves the {@link Map} of default templates to the preference store.
+     */
+    private void saveDefaultTemplates()
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( ObjectClass objectClassDescription : defaultTemplatesMap.keySet() )
+        {
+            sb.append( objectClassDescription.getNames().get( 0 ) );
+            sb.append( PREFERENCE_SUB_DELIMITER );
+            sb.append( defaultTemplatesMap.get( objectClassDescription ) );
+            sb.append( PREFERENCE_DELIMITER );
+        }
+        preferenceStore.setValue( EntryTemplatePluginConstants.PREF_DEFAULT_TEMPLATES, sb.toString() );
+    }
+
+
+    /**
+     * Sets the default templates.
+     */
+    private void setDefaultTemplates()
+    {
+        for ( Template template : templatesList )
+        {
+            if ( isEnabled( template ) )
+            {
+                String structuralObjectClass = template.getStructuralObjectClass();
+
+                // Checking if a default template is defined
+                if ( defaultTemplatesMap.get( EntryTemplatePluginUtils
+                    .getObjectClassDescriptionFromDefaultSchema( structuralObjectClass ) ) == null )
+                {
+                    // Assigning this template as the default one
+                    defaultTemplatesMap.put( EntryTemplatePluginUtils
+                        .getObjectClassDescriptionFromDefaultSchema( structuralObjectClass ), template.getId() );
+                }
+            }
+        }
+
+        // Saving default templates
+        saveDefaultTemplates();
+    }
+
+
+    /**
+     * Sets the given template as default for its structural object class.
+     *
+     * @param template
+     *      the template
+     */
+    public void setDefaultTemplate( Template template )
+    {
+        if ( isEnabled( template ) )
+        {
+            // Removing the old value
+            defaultTemplatesMap.remove( EntryTemplatePluginUtils.getObjectClassDescriptionFromDefaultSchema( template
+                .getStructuralObjectClass() ) );
+
+            // Setting the new value
+            defaultTemplatesMap.put( EntryTemplatePluginUtils.getObjectClassDescriptionFromDefaultSchema( template
+                .getStructuralObjectClass() ), template.getId() );
+
+            // Saving default templates
+            saveDefaultTemplates();
+        }
+    }
+
+
+    /**
+     * Unsets the given template as default for its structural object class.
+     *
+     * @param template
+     *      the template
+     */
+    public void unSetDefaultTemplate( Template template )
+    {
+        if ( isDefaultTemplate( template ) )
+        {
+            defaultTemplatesMap.remove( EntryTemplatePluginUtils.getObjectClassDescriptionFromDefaultSchema( template
+                .getStructuralObjectClass() ) );
+
+            // Saving default template
+            saveDefaultTemplates();
+        }
+    }
+
+
+    /**
+     * Indicates if the given template is the default one 
+     *      for its structural object class or not.
+     *
+     * @param template
+     *      the template
+     * @return
+     *      <code>true</code> if the given template is the default one 
+     *      for its structural object class,
+     *      <code>false</code> if not
+     */
+    public boolean isDefaultTemplate( Template template )
+    {
+        String defaultTemplateID = defaultTemplatesMap.get( EntryTemplatePluginUtils
+            .getObjectClassDescriptionFromDefaultSchema( template.getStructuralObjectClass() ) );
+        if ( defaultTemplateID != null )
+        {
+            return defaultTemplateID.equalsIgnoreCase( template.getId() );
+        }
+
+        return false;
+    }
+
+
+    /**
+     * Indicates whether the given name or OID for an object class has a default template.
+     *
+     * @param nameOrOid
+     *      the name or OID
+     * @return
+     *      <code>true</code> if the given name or OID for an object class has a default template
+     */
+    public boolean hasDefaultTemplate( String nameOrOid )
+    {
+        return getDefaultTemplate( nameOrOid ) != null;
+    }
+
+
+    /**
+     * Gets the default template associated with given name or OID for an object class.
+     *
+     * @param nameOrOid
+     * @return
+     *      the default template associated with given name or OID for an object class,
+     *      or <code>null</code> if there's no default template
+     */
+    public Template getDefaultTemplate( String nameOrOid )
+    {
+        return getTemplateById( defaultTemplatesMap.get( EntryTemplatePluginUtils
+            .getObjectClassDescriptionFromDefaultSchema( nameOrOid ) ) );
+    }
+
+
+    /**
+     * Gets the template identified by the given ID.
+     *
+     * @param id
+     *      the ID
+     * @return
+     *      the template identified by the given ID
+     */
+    private Template getTemplateById( String id )
+    {
+        return templatesByIdMap.get( id );
+    }
+
+
+    /**
+     * Gets the list of templates associated with the given name or OID for an object class.
+     *
+     * @param nameOrOid
+     *      the name or OID
+     * @return
+     *      the list of templates associated with the given name or OID for an object class
+     *      or <code>null</code> if there's no associated template
+     */
+    @SuppressWarnings("unchecked")
+    public List<Template> getTemplatesByObjectClass( String nameOrOid )
+    {
+        return ( List<Template> ) templatesByStructuralObjectClassMap.get( EntryTemplatePluginUtils
+            .getObjectClassDescriptionFromDefaultSchema( nameOrOid ) );
+    }
+
+}

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManagerListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManagerListener.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManagerListener.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/TemplatesManagerListener.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,69 @@
+/*
+ *  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.templateeditor;
+
+
+import org.apache.directory.studio.templateeditor.model.Template;
+
+
+/**
+ * This interface defines a listener for the templates manager events.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface TemplatesManagerListener
+{
+    /**
+     * This method is fired when a file template is added to the
+     * templates manager.
+     *
+     * @param template
+     *      the added template
+     */
+    public void templateAdded( Template template );
+
+
+    /**
+     * This method is fired when a file template is removed from the
+     * templates manager.
+     *
+     * @param template
+     *      the removed template
+     */
+    public void templateRemoved( Template template );
+
+
+    /**
+     * This method is fired when a template is enabled.
+     *
+     * @param template
+     *      the enabled template
+     */
+    public void templateEnabled( Template template );
+
+
+    /**
+     * This method is fired when a template is disabled.
+     *
+     * @param template
+     *      the disabled template
+     */
+    public void templateDisabled( Template template );
+}

Added: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/actions/DisplayEntryInTemplateAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/actions/DisplayEntryInTemplateAction.java?rev=1669604&view=auto
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/actions/DisplayEntryInTemplateAction.java (added)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/actions/DisplayEntryInTemplateAction.java Fri Mar 27 15:27:27 2015
@@ -0,0 +1,79 @@
+/*
+ *  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.templateeditor.actions;
+
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.ui.PlatformUI;
+
+import org.apache.directory.studio.templateeditor.EntryTemplatePlugin;
+import org.apache.directory.studio.templateeditor.EntryTemplatePluginConstants;
+import org.apache.directory.studio.templateeditor.editor.TemplateEditorWidget;
+
+
+/**
+ * This action is used to display a drop-down menu with the available
+ * templates for the entry in the editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DisplayEntryInTemplateAction extends Action
+{
+    /** The associated {@link TemplateEditorWidget} */
+    private TemplateEditorWidget templateEditorPage;
+
+
+    /**
+     * Creates a new instance of DisplayEntryInTemplateAction.
+     *
+     * @param templateEditorPage
+     *      the associated editor page
+     */
+    public DisplayEntryInTemplateAction( TemplateEditorWidget templateEditorPage )
+    {
+        super( Messages.getString( "DisplayEntryInTemplateAction.DisplayEntryIn" ), Action.AS_DROP_DOWN_MENU ); //$NON-NLS-1$
+        setImageDescriptor( EntryTemplatePlugin.getDefault().getImageDescriptor(
+            EntryTemplatePluginConstants.IMG_SWITCH_TEMPLATE ) );
+        this.templateEditorPage = templateEditorPage;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        MenuManager menuManager = new MenuManager();
+        DisplayEntryInTemplateMenuManager.fillInMenuManager( menuManager, templateEditorPage );
+
+        menuManager.createContextMenu( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+        menuManager.getMenu().setVisible( true );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled()
+    {
+        return true;
+    }
+}



Mime
View raw message