### Eclipse Workspace Patch 1.0
#P org.eclipse.ui.workbench.texteditor
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF,v
retrieving revision 1.19
diff -u -r1.19 MANIFEST.MF
--- META-INF/MANIFEST.MF 6 Aug 2007 13:19:00 -0000 1.19
+++ META-INF/MANIFEST.MF 17 Sep 2007 10:25:48 -0000
@@ -19,7 +19,8 @@
org.eclipse.ui.texteditor.quickdiff,
org.eclipse.ui.texteditor.rulers,
org.eclipse.ui.texteditor.spelling,
- org.eclipse.ui.texteditor.templates
+ org.eclipse.ui.texteditor.templates,
+ org.eclipse.ui.texteditor.templates.view
Require-Bundle:
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
Index: src/org/eclipse/ui/texteditor/templates/TemplatePreferencePage.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/TemplatePreferencePage.java,v
retrieving revision 1.56
diff -u -r1.56 TemplatePreferencePage.java
--- src/org/eclipse/ui/texteditor/templates/TemplatePreferencePage.java 12 Sep 2007 08:20:10 -0000 1.56
+++ src/org/eclipse/ui/texteditor/templates/TemplatePreferencePage.java 17 Sep 2007 10:25:52 -0000
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
*******************************************************************************/
package org.eclipse.ui.texteditor.templates;
@@ -136,7 +137,7 @@
*
* @since 3.3
*/
- protected static class EditTemplateDialog extends StatusDialog {
+ public static class EditTemplateDialog extends StatusDialog {
private class TextViewerAction extends Action implements IUpdate {
Index: src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.java
===================================================================
RCS file: src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.java
diff -N src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor.templates.view;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Helper class to get NLSed messages.
+ *
+ * @since 3.0
+ */
+final class TemplatesPageMessages extends NLS {
+
+ private static final String BUNDLE_NAME= TemplatesPageMessages.class.getName();
+ private TemplatesPageMessages() {
+ // Do not instantiate
+ }
+
+ // TemplatesView
+ public static String TemplatesPage_column_context;
+ public static String TemplatesPage_column_description;
+ public static String TemplatesPage_column_name;
+ public static String TemplatesPage_insert;
+ public static String TemplatesPage_edit;
+ public static String TemplatesPage_copy;
+ public static String TemplatesPage_paste;
+ public static String TemplatesPage_preference_page;
+ public static String TemplatesPage_link_to_editor;
+ public static String TemplatesPage_collapse_all;
+ public static String TemplatesPage_new;
+ public static String TemplatesPage_remove;
+ public static String TemplatesPage_insert_tooltip;
+ public static String TemplatesPage_edit_tooltip;
+ public static String TemplatesPage_preference_page_tooltip;
+ public static String TemplatesPage_link_to_editor_tooltip;
+ public static String TemplatesPage_collapse_all_tooltip;
+ public static String TemplatesPage_new_tooltip;
+ public static String TemplatesPage_remove_tooltip;
+ public static String TemplatesPage_preview;
+ public static String TemplatesPage_question_create_new_message;
+ public static String TemplatesPage_question_create_new_title;
+ public static String TemplatesPage_save_error_message;
+ public static String TemplatesPage_snippet;
+ public static String TemplatesPage_paste_description;
+ public static String TemplatesPage_remove_message_single;
+ public static String TemplatesPage_remove_message_multi;
+ public static String TemplatesPage_remove_title_single;
+ public static String TemplatesPage_remove_title_multi;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, TemplatesPageMessages.class);
+ }
+
+}
Index: src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.properties
===================================================================
RCS file: src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.properties
diff -N src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/texteditor/templates/view/TemplatesPageMessages.properties 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,41 @@
+###############################################################################
+# Copyright (c) 2007 Dakshinamurthy Karra and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+###############################################################################
+
+# templates page (view)
+TemplatesPage_collapse_all=Collapse All
+TemplatesPage_column_context=Context
+TemplatesPage_column_description=Description
+TemplatesPage_save_error_message=Error Saving the Templates
+TemplatesPage_column_name=Name
+TemplatesPage_edit=&Edit...
+TemplatesPage_insert=&Insert...
+TemplatesPage_copy=Copy
+TemplatesPage_paste=Paste
+TemplatesPage_preference_page=&Preferences...
+TemplatesPage_paste_description=Pasted from editor
+TemplatesPage_link_to_editor=Link with Editor
+TemplatesPage_new=&New...
+TemplatesPage_preview=Preview
+TemplatesPage_snippet=snippet
+TemplatesPage_question_create_new_message= The name of the template has been changed. Click 'Yes' to create an additional template with the new name or 'No' to rename the existing one.
+TemplatesPage_remove_title_single=Removing Template
+TemplatesPage_remove_title_multi=Removing Templates
+TemplatesPage_remove_message_single=Are you sure you want to remove the selected template?
+TemplatesPage_remove_message_multi=Are you sure you want to remove {0} selected templates?
+TemplatesPage_question_create_new_title= Edit Template
+TemplatesPage_remove=&Remove
+TemplatesPage_insert_tooltip=Insert into Editor
+TemplatesPage_edit_tooltip=Edit the Template
+TemplatesPage_preference_page_tooltip=Show Preference Page
+TemplatesPage_link_to_editor_tooltip=Link with Editor
+TemplatesPage_collapse_all_tooltip=Collapse All
+TemplatesPage_new_tooltip=Create a New Template
+TemplatesPage_remove_tooltip=Remove the Template
Index: src/org/eclipse/ui/texteditor/templates/view/TemplatesPageImages.java
===================================================================
RCS file: src/org/eclipse/ui/texteditor/templates/view/TemplatesPageImages.java
diff -N src/org/eclipse/ui/texteditor/templates/view/TemplatesPageImages.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/texteditor/templates/view/TemplatesPageImages.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor.templates.view;
+
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
+import org.osgi.framework.Bundle;
+
+/**
+ * The images provided by the texteditor plugin
+ *
+ * @since 3.4
+ */
+public class TemplatesPageImages {
+
+ static final String PREFIX_ELCL = TextEditorPlugin.PLUGIN_ID + ".elcl."; //$NON-NLS-1$
+ static final String PREFIX_DLCL = TextEditorPlugin.PLUGIN_ID + ".dlcl."; //$NON-NLS-1$
+ static final String PREFIX_OBJ = TextEditorPlugin.PLUGIN_ID + ".obj."; //$NON-NLS-1$
+
+ static final String IMG_ELCL_TEMPLATE_NEW = PREFIX_ELCL + "new_template.gif"; //$NON-NLS-1$
+ static final String IMG_ELCL_TEMPLATE_DELETE = PREFIX_ELCL + "delete_template.gif"; //$NON-NLS-1$
+ static final String IMG_ELCL_TEMPLATE_EDIT = PREFIX_ELCL + "edit_template.gif"; //$NON-NLS-1$
+ static final String IMG_ELCL_TEMPLATE_INSERT = PREFIX_ELCL + "insert_template.gif"; //$NON-NLS-1$
+ static final String IMG_ELCL_TEMPLATE_LINK = PREFIX_ELCL + "link_to_editor.gif"; //$NON-NLS-1$
+ static final String IMG_ELCL_TEMPLATE_COLLAPSE_ALL = PREFIX_ELCL + "collapseall.gif"; //$NON-NLS-1$
+ static final String IMG_DLCL_TEMPLATE_DELETE = PREFIX_DLCL + "delete_template.gif"; //$NON-NLS-1$
+ static final String IMG_DLCL_TEMPLATE_EDIT = PREFIX_DLCL + "edit_template.gif"; //$NON-NLS-1$
+ static final String IMG_DLCL_TEMPLATE_INSERT = PREFIX_DLCL + "insert_template.gif"; //$NON-NLS-1$
+
+ static final String IMG_OBJ_PREVIEW = PREFIX_OBJ + "preview.gif"; //$NON-NLS-1$
+ static final String IMG_OBJ_CONTEXT = PREFIX_OBJ + "context.gif"; //$NON-NLS-1$
+ static final String IMG_OBJ_TEMPLATE = PREFIX_OBJ + "template_obj.gif"; //$NON-NLS-1$
+
+ /**
+ * The image registry containing
+ * Clients who are defining an editor may elect to provide a corresponding
+ * templates page. This templates page will be presented to the user via the
+ * Templates View (the user decides whether their workbench window contains this
+ * view) whenever that editor is active. This class should be subclassed by
+ * clients.
+ *
+ * Internally, a TemplatesPage uses the template store to display different
+ * categories. A link to editor mode on the templates page allows to filtering
+ * of the categories to only that are supported in this context.
+ *
+ * This standard view has id Image
s.
+ */
+ private static ImageRegistry imageRegistry;
+
+ private static String ICONS_PATH = "$nl$/icons/full/"; //$NON-NLS-1$
+
+ // Use IPath and toOSString to build the names to ensure they have the
+ // slashes correct
+ private final static String ELCL = ICONS_PATH + "elcl16/"; //$NON-NLS-1$
+ private final static String DLCL = ICONS_PATH + "dlcl16/"; //$NON-NLS-1$
+ private final static String OBJ = ICONS_PATH + "obj16/"; //$NON-NLS-1$
+
+ /**
+ * Declare all images
+ */
+ private static void declareImages() {
+ // Ant Editor images
+ declareRegistryImage(IMG_ELCL_TEMPLATE_NEW, ELCL + "new_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_ELCL_TEMPLATE_INSERT, ELCL + "insert_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_DLCL_TEMPLATE_INSERT, DLCL + "insert_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_ELCL_TEMPLATE_DELETE, ELCL + "delete_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_DLCL_TEMPLATE_DELETE, DLCL + "delete_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_ELCL_TEMPLATE_EDIT, ELCL + "edit_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_DLCL_TEMPLATE_EDIT, DLCL + "edit_template.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_ELCL_TEMPLATE_LINK, ELCL + "link_to_editor.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_ELCL_TEMPLATE_COLLAPSE_ALL, ELCL + "collapseall.gif"); //$NON-NLS-1$
+
+ declareRegistryImage(IMG_OBJ_PREVIEW, OBJ + "preview.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_OBJ_CONTEXT, OBJ + "context.gif"); //$NON-NLS-1$
+ declareRegistryImage(IMG_OBJ_TEMPLATE, OBJ + "template_obj.gif"); //$NON-NLS-1$
+ }
+
+ /**
+ * Declare an Image in the registry table.
+ *
+ * @param key
+ * The key to use when registering the image
+ * @param path
+ * The path where the image can be found. This path is relative
+ * to where this plugin class is found (i.e. typically the
+ * packages directory)
+ */
+ private final static void declareRegistryImage(String key, String path) {
+ ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
+ Bundle bundle = Platform.getBundle(TextEditorPlugin.PLUGIN_ID);
+ URL url = null;
+ if (bundle != null) {
+ url = FileLocator.find(bundle, new Path(path), null);
+ desc = ImageDescriptor.createFromURL(url);
+ }
+ imageRegistry.put(key, desc);
+ }
+
+ /**
+ * Returns the ImageRegistry.
+ *
+ * @return image registry
+ */
+ public static ImageRegistry getImageRegistry() {
+ if (imageRegistry == null) {
+ initializeImageRegistry();
+ }
+ return imageRegistry;
+ }
+
+ /**
+ * Initialize the image registry by declaring all of the required graphics.
+ * This involves creating JFace image descriptors describing how to
+ * create/find the image should it be needed. The image is not actually
+ * allocated until requested.
+ *
+ * Prefix conventions Wizard Banners WIZBAN_ Preference Banners PREF_BAN_
+ * Property Page Banners PROPBAN_ Color toolbar CTOOL_ Enable toolbar ETOOL_
+ * Disable toolbar DTOOL_ Local enabled toolbar ELCL_ Local Disable toolbar
+ * DLCL_ Object large OBJL_ Object small OBJS_ View VIEW_ Product images
+ * PROD_ Misc images MISC_
+ *
+ * Where are the images? The images (typically gifs) are found in the same
+ * location as this plugin class. This may mean the same package directory
+ * as the package holding this class. The images are declared using
+ * this.getClass() to ensure they are looked up via this plugin class.
+ *
+ * @return the image registry
+ * @see org.eclipse.jface.resource.ImageRegistry
+ */
+ public static ImageRegistry initializeImageRegistry() {
+ imageRegistry = TextEditorPlugin.getDefault().getImageRegistry();
+ declareImages();
+ return imageRegistry;
+ }
+
+ /**
+ * Returns the Image
identified by the given key,
+ * or
null
if it does not exist.
+ * @param key
+ * @return the image
+ */
+ public static Image getImage(String key) {
+ return getImageRegistry().get(key);
+ }
+
+ /**
+ * Returns the ImageDescriptor
identified by the given key,
+ * or
null
if it does not exist.
+ * @param key
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String key) {
+ return getImageRegistry().getDescriptor(key);
+ }
+}
Index: src/org/eclipse/ui/texteditor/templates/view/TemplateTransfer.java
===================================================================
RCS file: src/org/eclipse/ui/texteditor/templates/view/TemplateTransfer.java
diff -N src/org/eclipse/ui/texteditor/templates/view/TemplateTransfer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/texteditor/templates/view/TemplateTransfer.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor.templates.view;
+
+import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.TransferData;
+
+/**
+ * Transfer type used for clip board and DnD operations for template objects
+ *
+ * @see TemplatesPage
+ *
+ * @since 3.4
+ */
+public class TemplateTransfer extends ByteArrayTransfer {
+
+ private static TemplateTransfer instance;
+
+ private static final String LOCAL_NAME = TemplateTransfer.class.getName()
+ + System.currentTimeMillis();
+ private static final int LOCAL_TYPE = registerType(LOCAL_NAME);
+
+ private static String[] names = null;
+ private static int types[] = null;
+
+ private TemplatePersistenceData[] fObject ;
+
+ /**
+ * @return the registered Transfer instance
+ */
+ public static TemplateTransfer getInstance() {
+ if (instance == null) {
+ instance = new TemplateTransfer();
+ types = new int[] { LOCAL_TYPE };
+ names = new String[] { LOCAL_NAME };
+ }
+ return instance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.Transfer#getTypeIds()
+ */
+ protected int[] getTypeIds() {
+ return types;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.Transfer#getTypeNames()
+ */
+ protected String[] getTypeNames() {
+ return names;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.ByteArrayTransfer#javaToNative(java.lang.Object,
+ * org.eclipse.swt.dnd.TransferData)
+ */
+ protected void javaToNative(Object object, TransferData transferData) {
+ if (object == null || !(object instanceof TemplatePersistenceData[])
+ || !isSupportedType(transferData)) {
+ fObject = null ;
+ return;
+ }
+ fObject = (TemplatePersistenceData[]) object ;
+ super.javaToNative(LOCAL_NAME.getBytes(), transferData);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.ByteArrayTransfer#nativeToJava(org.eclipse.swt.dnd.TransferData)
+ */
+ protected Object nativeToJava(TransferData transferData) {
+ Object result = super.nativeToJava(transferData);
+ if (!(result instanceof byte[])
+ || !LOCAL_NAME.equals(new String((byte[]) result)))
+ return null ;
+ return fObject ;
+ }
+}
Index: src/org/eclipse/ui/texteditor/templates/view/TemplatesPage.java
===================================================================
RCS file: src/org/eclipse/ui/texteditor/templates/view/TemplatesPage.java
diff -N src/org/eclipse/ui/texteditor/templates/view/TemplatesPage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/texteditor/templates/view/TemplatesPage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,1392 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor.templates.view;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+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.dialogs.MessageDialog;
+import org.eclipse.jface.layout.TreeColumnLayout;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.templates.ContextTypeRegistry;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
+import org.eclipse.jface.text.templates.persistence.TemplateStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ColumnPixelData;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.ViewForm;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.dnd.IDragAndDropService;
+import org.eclipse.ui.internal.texteditor.NLSUtility;
+import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+import com.ibm.icu.text.Collator;
+
+/**
+ * An abstract base class for template pages.
+ * null
if the
+ * editing failed
+ */
+ abstract protected Template editTemplate(Template template, boolean edit,
+ boolean isNameModifiable);
+
+ /**
+ * Get the pattern viewer.
+ *
+ * @param parent
+ * @return the viewer
+ */
+ abstract protected Viewer createPatternViewer(Composite parent);
+
+ /**
+ * Get the transfers supported by this editor.
+ *
+ * @return array of transfers supported
+ */
+ abstract protected Transfer[] getTransfers();
+
+ /**
+ * Create the template pattern from a DnD operation.
+ *
+ * @param transfer
+ * @param data
+ * @return pattern or null if the transfer is not supported
+ */
+ abstract protected String getTemplateDataFromDrop(Transfer transfer, Object data);
+
+ /**
+ * Update the pattern viewer to show the current template.
+ *
+ * @param template
+ */
+ abstract protected void updatePatternViewer(Template template);
+
+ /**
+ * Setup the preference store
+ */
+ private void setupPreferenceStore() {
+ fPreferenceStore = TextEditorPlugin.getDefault().getPreferenceStore();
+ fPreferenceStore.setDefault(LINK_ACTION_PREF_ID, true);
+ fPreferenceStore.setDefault(SASH_SIZE_PREF_ID, 80);
+ }
+
+ /**
+ * Setup the menu, context menu and toolbar actions.
+ */
+ private void setupActions() {
+ createActions();
+ IActionBars actionBars = getSite().getActionBars();
+
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), fPasteAction);
+ fPasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
+ fPasteAction.setText(TemplatesPageMessages.TemplatesPage_paste);
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
+ fCopyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
+ fCopyAction.setText(TemplatesPageMessages.TemplatesPage_copy);
+ fillToolbar(actionBars);
+ fillMenu(actionBars);
+ }
+
+ /**
+ * Create all the actions
+ */
+ private void createActions() {
+ fInsertAction = new Action(TemplatesPageMessages.TemplatesPage_insert) {
+ public void run() {
+ TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
+ insertTemplate(selectedTemplates[0].getTemplate(), null);
+ }
+ };
+ fInsertAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_INSERT));
+ fInsertAction.setDisabledImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_INSERT));
+ fInsertAction.setToolTipText(TemplatesPageMessages.TemplatesPage_insert_tooltip);
+
+ fAddAction = new Action(TemplatesPageMessages.TemplatesPage_new) {
+ public void run() {
+ addTemplate();
+ }
+ };
+ fAddAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_NEW));
+ fAddAction.setToolTipText(TemplatesPageMessages.TemplatesPage_new_tooltip);
+
+ fEditAction = new Action(TemplatesPageMessages.TemplatesPage_edit) {
+ public void run() {
+ editTemplate();
+ }
+ };
+ fEditAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_EDIT));
+ fEditAction.setDisabledImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_EDIT));
+ fEditAction.setToolTipText(TemplatesPageMessages.TemplatesPage_edit_tooltip);
+
+ fRemoveAction = new Action(TemplatesPageMessages.TemplatesPage_remove) {
+ public void run() {
+ removeTemplates();
+ }
+ };
+ fRemoveAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_DELETE));
+ fRemoveAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_DELETE));
+ fRemoveAction.setToolTipText(TemplatesPageMessages.TemplatesPage_remove_tooltip);
+
+ fLinkWithEditorAction = new Action(TemplatesPageMessages.TemplatesPage_link_to_editor,
+ IAction.AS_CHECK_BOX) {
+ public void run() {
+ fPreferenceStore.setValue(LINK_ACTION_PREF_ID, fLinkWithEditorAction.isChecked());
+ refresh();
+ }
+ };
+ fLinkWithEditorAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_LINK));
+ fLinkWithEditorAction.setChecked(fPreferenceStore.getBoolean(LINK_ACTION_PREF_ID));
+ fLinkWithEditorAction
+ .setToolTipText(TemplatesPageMessages.TemplatesPage_link_to_editor_tooltip);
+ fCollapseAllAction = new Action(TemplatesPageMessages.TemplatesPage_collapse_all) {
+ public void run() {
+ fTreeViewer.collapseAll();
+ }
+ };
+ fCollapseAllAction.setImageDescriptor(TemplatesPageImages
+ .getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_COLLAPSE_ALL));
+ fCollapseAllAction
+ .setToolTipText(TemplatesPageMessages.TemplatesPage_collapse_all_tooltip);
+
+ if (getPreferencePageId() != null) {
+ fPreferencePageAction = new Action(
+ TemplatesPageMessages.TemplatesPage_preference_page) {
+ public void run() {
+ showPreferencePage();
+ }
+ };
+ fPreferencePageAction
+ .setToolTipText(TemplatesPageMessages.TemplatesPage_preference_page_tooltip);
+ }
+
+ fPasteAction = new Action() {
+ public void run() {
+ final Template template = readClipboardContents();
+ if (template != null)
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ addTemplate(template);
+ }
+ });
+ }
+
+ private Template readClipboardContents() {
+ Clipboard clipBoard = new Clipboard(getShell().getDisplay());
+ String pattern = getTemplateDataFromClipboard(clipBoard);
+ if (pattern != null)
+ return new Template(createTemplateName(),
+ TemplatesPageMessages.TemplatesPage_paste_description,
+ getContextTypeId(), pattern, true);
+ return getTemplateFromClipboard(clipBoard);
+ }
+ };
+
+ fCopyAction = new Action() {
+ public void run() {
+ Clipboard clipBoard = new Clipboard(getShell().getDisplay());
+ clipBoard.setContents(new Object[] { getSelectedTemplates() }, new Transfer[] { TemplateTransfer
+ .getInstance() });
+ }
+ };
+ }
+
+ /**
+ * Fill the view menu
+ *
+ * @param actionBars
+ */
+ private void fillMenu(IActionBars actionBars) {
+ IMenuManager menuManager = actionBars.getMenuManager();
+
+ if (fPreferencePageAction != null) {
+ menuManager.add(fPreferencePageAction);
+ menuManager.add(new Separator());
+ }
+
+ menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ /**
+ * Fill the toolbar
+ *
+ * @param actionBars
+ */
+ private void fillToolbar(IActionBars actionBars) {
+ IToolBarManager toolBarManager = actionBars.getToolBarManager();
+ toolBarManager.add(fInsertAction);
+ toolBarManager.add(fAddAction);
+ toolBarManager.add(fEditAction);
+ toolBarManager.add(fRemoveAction);
+
+ toolBarManager.add(new Separator());
+
+ toolBarManager.add(fLinkWithEditorAction);
+ toolBarManager.add(fCollapseAllAction);
+ }
+
+ /**
+ * Hookup the context menu
+ */
+ private void hookContextMenu() {
+ MenuManager menuMgr = new MenuManager(POPUP_MENU_ID);
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ fillContextMenu(manager);
+ }
+ });
+ fContextMenu = menuMgr.createContextMenu(fTreeViewer.getControl());
+ fTreeViewer.getControl().setMenu(fContextMenu);
+ getSite().registerContextMenu(POPUP_MENU_ID, menuMgr, fTreeViewer);
+ }
+
+ /**
+ * Fill the context menu items
+ *
+ * @param manager
+ */
+ private void fillContextMenu(IMenuManager manager) {
+ manager.add(fInsertAction);
+ manager.add(new Separator());
+ manager.add(fAddAction);
+ manager.add(fEditAction);
+ manager.add(fRemoveAction);
+ manager.add(new Separator());
+ manager.add(fCopyAction);
+ manager.add(fPasteAction);
+ // Other plug-ins can contribute there actions here
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ /**
+ * Create the tree to display templates
+ * @param parent
+ */
+ private void createTemplateTree(Composite parent) {
+ Composite treeComposite = new Composite(parent, SWT.NONE);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ treeComposite.setLayoutData(data);
+
+ TreeColumnLayout columnLayout = new TreeColumnLayout();
+ treeComposite.setLayout(columnLayout);
+ fTemplatesTree = new Tree(treeComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
+ | SWT.FULL_SELECTION);
+ fTemplatesTree.setHeaderVisible(true);
+ fTemplatesTree.setLinesVisible(true);
+ GC gc = new GC(getShell());
+ gc.setFont(JFaceResources.getDialogFont());
+
+ TreeColumn columnName = new TreeColumn(fTemplatesTree, SWT.NONE);
+ columnName.setText(TemplatesPageMessages.TemplatesPage_column_name);
+ int minWidth = fPreferenceStore.getInt(COLUMN_NAME_WIDTH_PREF_ID);
+ if (minWidth == 0)
+ minWidth = gc.stringExtent("XXXXXXXXXXXXXXX").x; //$NON-NLS-1$
+ columnLayout.setColumnData(columnName, new ColumnPixelData(minWidth, true));
+ columnName.addControlListener(new ControlListener() {
+ public void controlMoved(ControlEvent e) {
+ }
+
+ public void controlResized(ControlEvent e) {
+ int nameWidth = ((TreeColumn) e.getSource()).getWidth();
+ fPreferenceStore.setValue(COLUMN_NAME_WIDTH_PREF_ID, nameWidth);
+ }
+ });
+
+ TreeColumn columnDescription = new TreeColumn(fTemplatesTree, SWT.NONE);
+ columnDescription.setText(TemplatesPageMessages.TemplatesPage_column_description);
+ minWidth = fPreferenceStore.getInt(COLUMN_DESCRIPTION_WIDTH_PREF_ID);
+ if (minWidth == 0)
+ minWidth = gc.stringExtent("XXXXXXXXXXXXXXXXXXXXXXXXX").x; //$NON-NLS-1$
+ columnLayout.setColumnData(columnDescription, new ColumnPixelData(minWidth, false));
+ columnDescription.addControlListener(new ControlListener() {
+ public void controlMoved(ControlEvent e) {
+ }
+
+ public void controlResized(ControlEvent e) {
+ int descriptionWidth = ((TreeColumn) e.getSource()).getWidth();
+ fPreferenceStore.setValue(COLUMN_DESCRIPTION_WIDTH_PREF_ID, descriptionWidth);
+ }
+ });
+
+ gc.dispose();
+
+ createTreeViewer(fTemplatesTree);
+ }
+
+ /**
+ * Create the tree viewer and setup the providers
+ * @param templatesTree
+ */
+ private void createTreeViewer(Tree templatesTree) {
+ fTreeViewer = new TreeViewer(fTemplatesTree);
+ fTreeViewer.setLabelProvider(new TemplateLabelProvider());
+ fTreeViewer.setContentProvider(new TemplatesContentProvider());
+
+ fTreeViewer.setComparator(new TemplateViewerComparator());
+ fTreeViewer.setInput(getTemplatePreferenceStore());
+ fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent e) {
+ updateSelectedItems();
+ TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
+ insertTemplate(selectedTemplates[0].getTemplate(), null);
+ }
+ });
+
+ fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent e) {
+ updateSelectedItems();
+ updateButtons();
+ }
+ });
+ fTreeViewer.expandAll();
+ }
+
+ /**
+ * Setup the pattern viewer
+ *
+ * @param parent
+ */
+ private void createPatternForm(Composite parent) {
+ ViewForm viewForm = new ViewForm(parent, SWT.NONE);
+ viewForm.setBorderVisible(false);
+ CLabel previewLabel = new CLabel(viewForm, SWT.NONE);
+ previewLabel.setText(TemplatesPageMessages.TemplatesPage_preview);
+ previewLabel.setImage(TemplatesPageImages.getImage(TemplatesPageImages.IMG_OBJ_PREVIEW));
+ viewForm.setTopLeft(previewLabel);
+
+ Viewer viewer = createPatternViewer(viewForm);
+ viewForm.setContent(viewer.getControl());
+ viewForm.addControlListener(new ControlListener() {
+ public void controlMoved(ControlEvent e) {
+ }
+
+ public void controlResized(ControlEvent e) {
+ int[] weights = fControl.getWeights();
+ int sashSize = (int) (weights[0] * 100.0 / (weights[0] + weights[1]));
+ fPreferenceStore.setValue(SASH_SIZE_PREF_ID, sashSize);
+ }
+ });
+ }
+
+ /**
+ * Update the selected items.
+ */
+ private void updateSelectedItems() {
+ setSelectedTemplates();
+ TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
+
+ if (selectedTemplates.length == 1)
+ updatePatternViewer(selectedTemplates[0].getTemplate());
+ else
+ updatePatternViewer(null);
+ }
+
+ /**
+ * Show the preference page. The action is enabled only if
+ * getPreferencePageId() returns non-null.
+ */
+ private void showPreferencePage() {
+ PreferencesUtil.createPreferenceDialogOn(getShell(), getPreferencePageId(), null, null)
+ .open();
+ }
+
+ /**
+ * Update the state of the buttons
+ */
+ private void updateButtons() {
+ TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
+ fCopyAction.setEnabled(selectedTemplates.length > 0);
+ fInsertAction.setEnabled(selectedTemplates.length == 1);
+ fEditAction.setEnabled(selectedTemplates.length == 1);
+ fRemoveAction.setEnabled(selectedTemplates.length > 0);
+ }
+
+ /**
+ * Set the selected templates
+ */
+ private void setSelectedTemplates() {
+ IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
+
+ Iterator it = selection.iterator();
+ TemplatePersistenceData[] data = new TemplatePersistenceData[selection.size()];
+ int i = 0 ;
+ try {
+ while (it.hasNext()) {
+ data[i++] = (TemplatePersistenceData) it.next();
+ }
+ fSelectedTemplates = data;
+ } catch (ClassCastException e) {
+ // A context also must have been selected - ignore the selection
+ fSelectedTemplates = new TemplatePersistenceData[0];
+ }
+ }
+
+ /**
+ * Get the currently selected templates
+ *
+ * @return selected tempaltes
+ */
+ private TemplatePersistenceData[] getSelectedTemplates() {
+ return fSelectedTemplates ;
+ }
+
+ /**
+ * Add a template
+ */
+ private void addTemplate() {
+ String id = getContextTypeId();
+ if (id != null) {
+ Template template = new Template("", "", id, "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ addTemplate(template);
+ }
+ }
+
+ /**
+ * Get contextType of the selected template
+ *
+ * @return contextType of the selected template or the first from the
+ * registry if no templates are selected
+ */
+ private String getContextTypeId() {
+ IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
+ Object item ;
+
+ if (selection.size() == 0)
+ return ((TemplateContextType) getContextTypeRegistry().contextTypes().next()).getId();
+
+ if (selection.size() == 1) {
+ item = selection.getFirstElement();
+ if (item instanceof TemplatePersistenceData)
+ return ((TemplatePersistenceData)item).getTemplate().getContextTypeId() ;
+ return ((TemplateContextType)item).getId();
+ }
+ Iterator it = selection.iterator();
+ String contextId = null ;
+ while (it.hasNext()) {
+ item = it.next();
+ if (contextId == null)
+ contextId = getContextId(item);
+ else if (!contextId.equals(getContextId(item)))
+ return ((TemplateContextType) getContextTypeRegistry().contextTypes().next()).getId();
+ }
+ return contextId;
+ }
+
+ private String getContextId(Object item) {
+ String contextId;
+ if (item instanceof TemplatePersistenceData)
+ contextId = ((TemplatePersistenceData)item).getTemplate().getContextTypeId();
+ else
+ contextId = ((TemplateContextType)item).getId();
+ return contextId;
+ }
+
+ /**
+ * Add a template. The dialog is filled with the values from the given
+ * template.
+ *
+ * @param template
+ */
+ private void addTemplate(Template template) {
+ Template newTemplate;
+ newTemplate = editTemplate(template, false, true);
+ if (newTemplate != null) {
+ TemplatePersistenceData data = new TemplatePersistenceData(newTemplate, true);
+ getTemplateStore().add(data);
+ saveTemplateStore();
+ refresh();
+ fTreeViewer.setSelection(new StructuredSelection(data), true);
+ }
+ }
+
+ /**
+ * Save the template store
+ */
+ private void saveTemplateStore() {
+ try {
+ getTemplateStore().save();
+ } catch (IOException e) {
+ e.printStackTrace();
+ MessageDialog.openError(getShell(),
+ TemplatesPageMessages.TemplatesPage_save_error_message, e.getMessage());
+ }
+ }
+
+ /**
+ * Edit the selected template
+ */
+ private void editTemplate() {
+ Template oldTemplate = getSelectedTemplates()[0].getTemplate();
+ Template newTemplate = editTemplate(new Template(oldTemplate), true, true);
+ if (newTemplate != null) {
+ if (!newTemplate.getName().equals(oldTemplate.getName())
+ && MessageDialog.openQuestion(getShell(),
+ TemplatesPageMessages.TemplatesPage_question_create_new_title,
+ TemplatesPageMessages.TemplatesPage_question_create_new_message)) {
+ TemplatePersistenceData templateData = new TemplatePersistenceData(newTemplate,
+ true);
+ getTemplateStore().add(templateData);
+ refresh();
+ fTreeViewer.setSelection(new StructuredSelection(templateData), true);
+ } else {
+ getSelectedTemplates()[0].setTemplate(newTemplate);
+ }
+ }
+ saveTemplateStore();
+ }
+
+ /**
+ * Move the selected template from one context to another
+ * @param templates
+ * @param contextId
+ *
+ */
+ private void moveTemplates(TemplatePersistenceData[] templates, String contextId) {
+ for (int i = 0; i < templates.length; i++) {
+ Template t = templates[i].getTemplate();
+ templates[i].setTemplate(new Template(t.getName(), t.getDescription(), contextId, t.getPattern(), t.isAutoInsertable()));
+ }
+ saveTemplateStore();
+ fTreeViewer.setSelection(new StructuredSelection(templates), true);
+ }
+
+ /**
+ * Copy the selected templates to another context
+ * @param templates
+ * @param contextId
+ *
+ */
+ private void copyTemplates(TemplatePersistenceData[] templates, String contextId) {
+ TemplatePersistenceData[] newTemplates = new TemplatePersistenceData[templates.length];
+ for (int i = 0; i < templates.length; i++) {
+ Template t = templates[i].getTemplate();
+ newTemplates[i] = new TemplatePersistenceData(new Template(t.getName(), t.getDescription(), contextId, t.getPattern(), t.isAutoInsertable()), true);
+ getTemplateStore().add(newTemplates[i]);
+ }
+ saveTemplateStore();
+ refresh();
+ fTreeViewer.setSelection(new StructuredSelection(newTemplates), true);
+ }
+
+ /**
+ * Remove one or more selected templates
+ */
+ private void removeTemplates() {
+ String title ;
+ TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
+ if (selectedTemplates.length == 1)
+ title = TemplatesPageMessages.TemplatesPage_remove_title_single;
+ else
+ title = TemplatesPageMessages.TemplatesPage_remove_title_multi;
+ String message ;
+ if (selectedTemplates.length == 1)
+ message = TemplatesPageMessages.TemplatesPage_remove_message_single ;
+ else
+ message = NLSUtility.format(TemplatesPageMessages.TemplatesPage_remove_message_multi,
+ new Object[] { new Integer(selectedTemplates.length) });
+ if (!MessageDialog.openQuestion(getShell(), title, message))
+ return;
+ for (int i = 0; i < selectedTemplates.length; i++) {
+ getTemplateStore().delete(selectedTemplates[i]);
+ }
+ saveTemplateStore();
+ fTreeViewer.setSelection(new StructuredSelection(new Object[] {}), true);
+ }
+
+ /**
+ * Initialize drag and drop the template items
+ */
+ private void initializeDND() {
+ DragSourceAdapter dragListener = new DragSourceAdapter() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
+ */
+ public void dragStart(DragSourceEvent event) {
+ if (getSelectedTemplates().length == 0) {
+ event.doit = false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
+ */
+ public void dragSetData(DragSourceEvent event) {
+ if (TemplateTransfer.getInstance().isSupportedType(event.dataType)) {
+ event.data = getSelectedTemplates() ;
+ }
+ }
+ };
+ fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplateTransfer
+ .getInstance() }, dragListener);
+ DropTargetAdapter dropListener = new DropTargetAdapter() {
+ Transfer[] transfers = getTransfers();
+ TemplateTransfer templateTransfer = TemplateTransfer.getInstance();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.DropTargetAdapter#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
+ */
+ public void dragEnter(DropTargetEvent event) {
+ if (event.detail == DND.DROP_DEFAULT)
+ event.detail = DND.DROP_COPY;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.DropTargetAdapter#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent)
+ */
+ public void dragOperationChanged(DropTargetEvent event) {
+ if (event.detail == DND.DROP_DEFAULT)
+ event.detail = DND.DROP_COPY;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.DropTargetAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
+ */
+ public void dragOver(DropTargetEvent event) {
+ event.feedback |= DND.FEEDBACK_SCROLL;
+ if (event.item == null) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ int index = 0;
+ boolean isTemplateTransfer = false;
+ while (index < event.dataTypes.length) {
+ int i = 0;
+ while (i < transfers.length) {
+ if (transfers[i].isSupportedType(event.dataTypes[index]))
+ break;
+ i++;
+ }
+ if (i < transfers.length)
+ break;
+ if (templateTransfer.isSupportedType(event.dataTypes[index])) {
+ isTemplateTransfer = true;
+ break;
+ }
+ index++;
+ }
+ if (index < event.dataTypes.length) {
+ event.currentDataType = event.dataTypes[index];
+ if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer)
+ event.detail = DND.DROP_COPY;
+ return;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd.DropTargetEvent)
+ */
+ public void drop(DropTargetEvent event) {
+ if (event.item == null)
+ return;
+ Object object = ((TreeItem) event.item).getData();
+ final String contextId;
+ if (object instanceof TemplateContextType)
+ contextId = ((TemplateContextType) object).getId();
+ else
+ contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
+ for (int i = 0; i < transfers.length; i++) {
+ if (transfers[i].isSupportedType(event.currentDataType)) {
+ String text = getTemplateDataFromDrop(transfers[i], event.data);
+ final Template template = new Template(createTemplateName(),
+ TemplatesPageMessages.TemplatesPage_paste_description,
+ contextId, text, true);
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ addTemplate(template);
+ }
+ });
+ return;
+ }
+ }
+ if (templateTransfer.isSupportedType(event.currentDataType)) {
+ final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data;
+ final int dropType = event.detail;
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (dropType == DND.DROP_COPY)
+ copyTemplates(templates, contextId);
+ else
+ moveTemplates(templates, contextId);
+ }
+ });
+ }
+ }
+ };
+ Transfer[] transfers = new Transfer[getTransfers().length + 1];
+ System.arraycopy(getTransfers(), 0, transfers, 0, getTransfers().length);
+ transfers[getTransfers().length] = TemplateTransfer.getInstance();
+ fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener);
+ }
+
+ /**
+ * Create a template name
+ *
+ * @return a new template name
+ */
+ private String createTemplateName() {
+ for (int i = 1; i < Integer.MAX_VALUE; i++) {
+ String name = TemplatesPageMessages.TemplatesPage_snippet + i;
+ if (getTemplateStore().findTemplate(name) == null)
+ return name;
+ }
+ return null;
+ }
+
+ /**
+ * Store the collapse state of a context
+ */
+ private void storeCollapseState() {
+ TreeItem[] items = fTreeViewer.getTree().getItems();
+ for (int i = 0; i < items.length; i++) {
+ fPreferenceStore.setValue(CONTEXT_COLLAPSE_PREF_ID + ((TemplateContextType)items[i].getData()).getId(), !items[i].getExpanded());
+ }
+ }
+
+ /**
+ * Refresh the template tree contents
+ */
+ private void refresh() {
+ storeCollapseState();
+ fTreeViewer.getTree().setRedraw(false);
+ try {
+ fTreeViewer.refresh();
+ TreeItem[] items = fTreeViewer.getTree().getItems();
+ for (int i = 0; i < items.length; i++) {
+ boolean isExpanded = !fPreferenceStore.getBoolean(CONTEXT_COLLAPSE_PREF_ID + ((TemplateContextType)items[i].getData()).getId());
+ if (isExpanded)
+ fTreeViewer.expandToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS);
+ else
+ fTreeViewer.collapseToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS);
+ }
+ } finally {
+ fTreeViewer.getTree().setRedraw(true);
+ }
+ }
+}
Index: src/org/eclipse/ui/texteditor/templates/view/TextEditorTemplatesPage.java
===================================================================
RCS file: src/org/eclipse/ui/texteditor/templates/view/TextEditorTemplatesPage.java
diff -N src/org/eclipse/ui/texteditor/templates/view/TextEditorTemplatesPage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/texteditor/templates/view/TextEditorTemplatesPage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,347 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor.templates.view;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewerExtension5;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+import org.eclipse.ui.texteditor.templates.TemplatePreferencePage.EditTemplateDialog;
+
+/**
+ * A TemplatesPage implementation for Editors based on AbstractTextEditor.
+ *
+ * @since 3.4
+ */
+public abstract class TextEditorTemplatesPage extends TemplatesPage {
+ /**
+ * A post selection changed listener for the editor. Depending on the caret position
+ * updates the templates
+ */
+ private final class SelectionChangedListener implements ISelectionChangedListener {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ String[] contextTypes = getContextTypes() ;
+ if (needUpdate(contextTypes)) {
+ fCurrentContextTypes = contextTypes ;
+ updateContextTypes(fCurrentContextTypes);
+ return ;
+ }
+ }
+
+ /**
+ * Check whether an update of the TemplatesPage is needed
+ *
+ * @param contextTypes
+ * @return true if update is needed
+ */
+ private boolean needUpdate(String[] contextTypes) {
+ return fCurrentContextTypes == null || fCurrentContextTypes.length != contextTypes.length ||
+ contextTypeChanged(contextTypes);
+ }
+
+ /**
+ * Check whether there is any change in the context types needed
+ *
+ * @param contextTypes
+ * @return true if any of the context types changed
+ */
+ private boolean contextTypeChanged(String[] contextTypes) {
+ for (int i = 0; i < contextTypes.length; i++) {
+ if (!contextTypes[i].equals(fCurrentContextTypes[i]))
+ return false ;
+ }
+ return true;
+ }
+ }
+
+ /**
+ * The editor
+ */
+ private final AbstractTextEditor fEditor;
+ /**
+ * The SourceViewer attached to this editor
+ */
+ private final ISourceViewer fViewer;
+ /**
+ * The pattern viewer to be used with this view
+ */
+ private SourceViewer fPatternViewer;
+
+ /* Caches to improve performance while dropping a template */
+ private int fCachedOffset;
+ private boolean fCachedResult;
+ private Point fCachedPosition;
+
+ /**
+ * The current context types
+ */
+ private String[] fCurrentContextTypes;
+ /**
+ * The selection changed listener to monitor the editor selections
+ */
+ private SelectionChangedListener fSelectionChangedListener;
+
+ /**
+ * Paste action support
+ */
+ private IAction fOldPasteAction;
+ private IAction fPasteAction;
+
+ /**
+ * Create a new TemplatesPage
+ *
+ * @param editor
+ * @param viewer
+ */
+ public TextEditorTemplatesPage(AbstractTextEditor editor, ISourceViewer viewer) {
+ super();
+ fEditor= editor;
+ fViewer= viewer;
+ setupEditorDropTarget(fEditor.getSite(), (Control) fEditor.getAdapter(Control.class));
+ setupSelectionProvider();
+ setupPasteOperation();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#dispose()
+ */
+ public void dispose() {
+ ISelectionProvider selectionProvider = fViewer.getSelectionProvider();
+ if (selectionProvider instanceof IPostSelectionProvider)
+ ((IPostSelectionProvider)selectionProvider).removePostSelectionChangedListener(fSelectionChangedListener);
+ else
+ selectionProvider.removeSelectionChangedListener(fSelectionChangedListener);
+ fEditor.setAction(ITextEditorActionConstants.PASTE, fOldPasteAction);
+ super.dispose();
+ }
+
+ /**
+ * Get the editor associated with this view
+ *
+ * @return the editor
+ */
+ protected AbstractTextEditor getEditor() {
+ return fEditor ;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#isValidTemplateForPosition(org.eclipse.jface.text.templates.Template, org.eclipse.swt.graphics.Point)
+ */
+ protected boolean isValidTemplateForPosition(Template template, Point position) {
+ StyledText textWidget= (StyledText) fEditor.getAdapter(Control.class);
+ IDocument document= fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+ try {
+ if (position.equals(fCachedPosition))
+ return fCachedResult;
+ fCachedPosition= position;
+ int offset= getOffset(document, textWidget, textWidget.toControl(position.x, position.y));
+ if (fCachedOffset == offset)
+ return fCachedResult;
+ fCachedOffset= offset;
+ if (isValidTemplate(document, template, offset, 0))
+ return fCachedResult= true;
+ } catch (BadLocationException e) {
+ }
+ return fCachedResult= false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#isEditorModifiable()
+ */
+ protected boolean isEditorModifiable() {
+ return fEditor.isEditorInputModifiable();
+ }
+
+ /**
+ * Creates, configures and returns a source viewer to present the template
+ * pattern on the templates page. Clients may override to provide a custom
+ * source viewer featuring e.g. syntax coloring.
+ *
+ * @param parent
+ * the parent control
+ * @return a configured source viewer
+ */
+ protected Viewer createPatternViewer(Composite parent) {
+ if (parent == null)
+ return fPatternViewer ;
+ fPatternViewer = new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL
+ | SWT.H_SCROLL);
+ SourceViewerConfiguration configuration = new SourceViewerConfiguration();
+ fPatternViewer.configure(configuration);
+ IDocument document = new Document();
+ fPatternViewer.setDocument(document);
+ fPatternViewer.setEditable(false);
+ return fPatternViewer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#updatePatternViewer(org.eclipse.jface.text.templates.Template)
+ */
+ protected void updatePatternViewer(Template template) {
+ if (template != null)
+ fPatternViewer.getDocument().set(template.getPattern());
+ else
+ fPatternViewer.getDocument().set(""); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getTemplateDataFromClipboard(org.eclipse.swt.dnd.Clipboard)
+ */
+ protected String getTemplateDataFromClipboard(Clipboard clipBoard) {
+ String pattern = ((String) clipBoard.getContents(TextTransfer.getInstance()));
+ if (pattern != null)
+ return pattern.replaceAll("\\$", "\\$\\$"); //$NON-NLS-1$//$NON-NLS-2$
+ return null ;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getTemplateDataFromDrop(org.eclipse.swt.dnd.Transfer, java.lang.Object)
+ */
+ protected String getTemplateDataFromDrop(Transfer transfer, Object data) {
+ if (transfer instanceof TextTransfer)
+ return ((String)data).replaceAll("\\$", "\\$\\$"); //$NON-NLS-1$//$NON-NLS-2$
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getTransfers()
+ */
+ protected Transfer[] getTransfers() {
+ return new Transfer[] { TextTransfer.getInstance() };
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#editTemplate(org.eclipse.jface.text.templates.Template, boolean, boolean)
+ */
+ protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) {
+ EditTemplateDialog dialog = new EditTemplateDialog(getShell(), template, edit,
+ isNameModifiable, getContextTypeRegistry());
+ if (dialog.open() == Window.OK) {
+ return dialog.getTemplate();
+ }
+ return null;
+ }
+
+ /**
+ * Get the context types supported at the current caret position of the editor
+ *
+ * @return the ids of the context types
+ */
+ protected abstract String[] getContextTypes() ;
+
+ /**
+ * Check whether the given template is valid for the document at the given position
+ *
+ * @param document
+ * @param template
+ * @param offset
+ * @param length
+ * @return true if the template is valid
+ */
+ protected abstract boolean isValidTemplate(IDocument document, Template template, int offset, int length);
+
+ /**
+ * Setup the paste operation
+ *
+ * We get the editors Paste operation and sets up a new operation that checks for the clipboard contents for
+ * TemplateTransfer data.
+ */
+ private void setupPasteOperation() {
+ fOldPasteAction = fEditor.getAction(ITextEditorActionConstants.PASTE);
+ fPasteAction = new Action(TemplatesPageMessages.TemplatesPage_paste) {
+ public void run() {
+ Clipboard clipBoard = new Clipboard(getShell().getDisplay());
+ Template template = getTemplateFromClipboard(clipBoard);
+ if (template != null)
+ insertTemplate(template, null);
+ else
+ fOldPasteAction.run();
+ }
+ public void runWithEvent(Event event) {
+ Clipboard clipBoard = new Clipboard(getShell().getDisplay());
+ Template template = getTemplateFromClipboard(clipBoard);
+ if (template != null)
+ insertTemplate(template, null);
+ else
+ fOldPasteAction.runWithEvent(event);
+ }
+ };
+ fPasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
+ fEditor.setAction(ITextEditorActionConstants.PASTE, fPasteAction);
+ }
+
+ /**
+ * Setup a selection listener to monitor the editor
+ */
+ private void setupSelectionProvider() {
+ ISelectionProvider selectionProvider = fViewer.getSelectionProvider();
+ fSelectionChangedListener = new SelectionChangedListener();
+ if (selectionProvider instanceof IPostSelectionProvider)
+ ((IPostSelectionProvider)selectionProvider).addPostSelectionChangedListener(fSelectionChangedListener);
+ else
+ selectionProvider.addSelectionChangedListener(fSelectionChangedListener);
+ }
+
+ /**
+ * Get the document relative offset from the textwidget relative point
+ *
+ * @param document
+ * @param textWidget
+ * @param point
+ * @return the offset
+ * @throws BadLocationException
+ */
+ private int getOffset(IDocument document, StyledText textWidget, Point point) throws BadLocationException {
+ int widgetCaret= fViewer.getTextWidget().getCaretOffset();
+ if (fViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 ext= (ITextViewerExtension5) fViewer;
+ try {
+ return ext.widgetOffset2ModelOffset(textWidget.getOffsetAtLocation(point));
+ } catch (IllegalArgumentException e) {
+ int docLineIndex= ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y));
+ String lineDelimiter= document.getLineDelimiter(docLineIndex);
+ int delimLength= lineDelimiter == null ? 0 : lineDelimiter.length();
+ return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex) - delimLength;
+ }
+ }
+ IRegion visible= fViewer.getVisibleRegion();
+ return widgetCaret + visible.getOffset();
+ }
+}
#P org.eclipse.jdt.ui
Index: ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java,v
retrieving revision 1.434
diff -u -r1.434 JavaEditor.java
--- ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java 28 Aug 2007 13:45:47 -0000 1.434
+++ ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java 17 Sep 2007 10:26:10 -0000
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;
@@ -142,6 +143,7 @@
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.templates.ITemplatesPage;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -197,6 +199,7 @@
import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectNextAction;
import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectPreviousAction;
import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectionAction;
+import org.eclipse.jdt.internal.ui.preferences.JavaTemplatesPage;
import org.eclipse.jdt.internal.ui.search.BreakContinueTargetFinder;
import org.eclipse.jdt.internal.ui.search.ExceptionOccurrencesFinder;
import org.eclipse.jdt.internal.ui.search.ImplementOccurrencesFinder;
@@ -1336,6 +1339,12 @@
protected JavaOutlinePage fOutlinePage;
/** Outliner context menu Id */
protected String fOutlinerContextMenuId;
+ /** The templates page
+ *
+ * @since 3.4
+ */
+ private JavaTemplatesPage fTemplatesPage;
+
/**
* The editor selection changed listener.
*
@@ -1791,6 +1800,10 @@
return fOutlinePage;
}
+ if (required.equals(ITemplatesPage.class)) {
+ return getTemplatesPage();
+ }
+
if (IEncodingSupport.class.equals(required))
return fEncodingSupport;
@@ -1846,6 +1859,17 @@
}
/**
+ * @since 3.4
+ */
+ private JavaTemplatesPage getTemplatesPage() {
+ if (fTemplatesPage == null) {
+ fTemplatesPage= new JavaTemplatesPage(this);
+
+ }
+ return fTemplatesPage;
+ }
+
+ /**
* React to changed selection.
*
* @since 3.0
Index: ui/org/eclipse/jdt/internal/ui/JavaPerspectiveFactory.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPerspectiveFactory.java,v
retrieving revision 1.44
diff -u -r1.44 JavaPerspectiveFactory.java
--- ui/org/eclipse/jdt/internal/ui/JavaPerspectiveFactory.java 29 May 2007 18:41:36 -0000 1.44
+++ ui/org/eclipse/jdt/internal/ui/JavaPerspectiveFactory.java 17 Sep 2007 10:25:55 -0000
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
*******************************************************************************/
package org.eclipse.jdt.internal.ui;
@@ -45,7 +46,9 @@
outputfolder.addPlaceholder(IPageLayout.ID_BOOKMARKS);
outputfolder.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID);
- layout.addView(IPageLayout.ID_OUTLINE, IPageLayout.RIGHT, (float)0.75, editorArea);
+ IFolderLayout outlineFolder = layout.createFolder("right", IPageLayout.RIGHT, (float)0.75, editorArea); //$NON-NLS-1$
+ outlineFolder.addView(IPageLayout.ID_OUTLINE);
+ outlineFolder.addView(IPageLayout.ID_TEMPLATES);
layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET);
layout.addActionSet(JavaUI.ID_ACTION_SET);
@@ -66,6 +69,7 @@
// views - standard workbench
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
+ layout.addShowViewShortcut(IPageLayout.ID_TEMPLATES);
layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
layout.addShowViewShortcut(IPageLayout.ID_RES_NAV);
layout.addShowViewShortcut(IPageLayout.ID_TASK_LIST);
Index: ui/org/eclipse/jdt/internal/ui/preferences/JavaTemplatesPage.java
===================================================================
RCS file: ui/org/eclipse/jdt/internal/ui/preferences/JavaTemplatesPage.java
diff -N ui/org/eclipse/jdt/internal/ui/preferences/JavaTemplatesPage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ui/org/eclipse/jdt/internal/ui/preferences/JavaTemplatesPage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,392 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.jdt.internal.ui.preferences;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewerExtension;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.templates.ContextTypeRegistry;
+import org.eclipse.jface.text.templates.DocumentTemplateContext;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.text.templates.persistence.TemplateStore;
+
+import org.eclipse.ui.texteditor.templates.view.TextEditorTemplatesPage;
+
+import org.eclipse.ui.views.templates.ITemplatesPage;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+
+import org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType;
+import org.eclipse.jdt.internal.corext.template.java.JavaContext;
+import org.eclipse.jdt.internal.corext.template.java.JavaContextType;
+import org.eclipse.jdt.internal.corext.template.java.JavaDocContext;
+import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType;
+import org.eclipse.jdt.internal.corext.template.java.SWTContextType;
+
+import org.eclipse.jdt.ui.PreferenceConstants;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jdt.ui.text.JavaTextTools;
+
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
+import org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
+import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateProposal;
+import org.eclipse.jdt.internal.ui.text.template.preferences.TemplateVariableProcessor;
+
+/**
+ * An implementation of TemplatesPage for JavaEditor
+ */
+public class JavaTemplatesPage extends TextEditorTemplatesPage implements ITemplatesPage {
+
+ private static final String PREFERENCE_PAGE_ID= "org.eclipse.jdt.ui.preferences.JavaTemplatePreferencePage"; //$NON-NLS-1$
+ private static final TemplateStore TEMPLATE_STORE= JavaPlugin.getDefault().getTemplateStore();
+ private static final IPreferenceStore PREFERENCE_STORE= JavaPlugin.getDefault().getPreferenceStore();
+ private static final ContextTypeRegistry TEMPLATE_CONTEXT_REGISTRY= JavaPlugin.getDefault().getTemplateContextRegistry();
+
+ private TemplateVariableProcessor fTemplateProcessor;
+ private JavaSourceViewer fPatternViewer;
+
+ /**
+ * Create a new TemplatesPage for the JavaEditor
+ *
+ * @param javaEditor
+ */
+ public JavaTemplatesPage(JavaEditor javaEditor) {
+ super(javaEditor, javaEditor.getViewer());
+ fTemplateProcessor= new TemplateVariableProcessor();
+ updateContextTypes(getContextTypes());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#insertTemplate(org.eclipse.jface.text.templates.Template, org.eclipse.swt.graphics.Point)
+ */
+ protected void insertTemplate(Template template, Point dropPosition) {
+ if (!getJavaEditor().validateEditorInputState())
+ return;
+ ISourceViewer contextViewer= getJavaEditor().getViewer();
+ ITextSelection textSelection= (ITextSelection) contextViewer.getSelectionProvider().getSelection();
+ IDocument document= getJavaEditor().getDocumentProvider().getDocument(getJavaEditor().getEditorInput());
+ if (!isValidTemplate(document, template, textSelection.getOffset(), textSelection.getLength()))
+ return;
+ beginCompoundChange(contextViewer);
+ /*
+ * The Editor checks whether a completion for a word exists before it allows for the template to be
+ * applied. We pickup the current text at the selection position and replace it with the first char
+ * of the template name for this to succeed.
+ * Another advantage by this method is that the template replaces the selected text provided the
+ * selection by itself is not used in the template pattern.
+ */
+ String savedText;
+ try {
+ savedText= document.get(textSelection.getOffset(), textSelection.getLength());
+ if (savedText.length() == 0) {
+ String prefix= getIdentifierPart(document, template, textSelection.getOffset(), textSelection.getLength());
+ if (prefix.length() > 0 && !template.getName().startsWith(prefix.toString())) {
+ return;
+ }
+ if (prefix.length() > 0) {
+ contextViewer.setSelectedRange(textSelection.getOffset() - prefix.length(), prefix.length());
+ textSelection= (ITextSelection) contextViewer.getSelectionProvider().getSelection();
+ }
+ }
+ document.replace(textSelection.getOffset(), textSelection.getLength(), template.getName().substring(0, 1));
+ } catch (BadLocationException e) {
+ endCompoundChange(contextViewer);
+ return;
+ }
+ Position position= new Position(textSelection.getOffset() + 1, 0);
+ Region region= new Region(textSelection.getOffset() + 1, 0);
+ contextViewer.getSelectionProvider().setSelection(new TextSelection(textSelection.getOffset(), 1));
+ ICompilationUnit compilationUnit= (ICompilationUnit) EditorUtility.getEditorInputJavaElement(getJavaEditor(), true);
+
+ TemplateContextType type= getContextTypeRegistry().getContextType(template.getContextTypeId());
+ DocumentTemplateContext context= ((CompilationUnitContextType) type).createContext(document, position, compilationUnit);
+ context.setVariable("selection", savedText); //$NON-NLS-1$
+ if (context.getKey().length() == 0) {
+ try {
+ document.replace(textSelection.getOffset(), 1, savedText);
+ } catch (BadLocationException e) {
+ endCompoundChange(contextViewer);
+ return;
+ }
+ }
+ TemplateProposal proposal= new TemplateProposal(template, context, region, null);
+ getJavaEditor().getSite().getPage().activate(getJavaEditor());
+ proposal.apply(getJavaEditor().getViewer(), ' ', 0, region.getOffset());
+ endCompoundChange(contextViewer);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getContextTypeRegistry()
+ */
+ protected ContextTypeRegistry getContextTypeRegistry() {
+ return TEMPLATE_CONTEXT_REGISTRY;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getTemplatePreferenceStore()
+ */
+ protected IPreferenceStore getTemplatePreferenceStore() {
+ return PREFERENCE_STORE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getTemplateStore()
+ */
+ protected TemplateStore getTemplateStore() {
+ return TEMPLATE_STORE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TextEditorTemplatesPage#isValidTemplate(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.templates.Template, int, int)
+ */
+ protected boolean isValidTemplate(IDocument document, Template template, int offset, int length) {
+ try {
+ String[] contextIds= getContextIds(document, offset);
+ for (int i= 0; i < contextIds.length; i++) {
+ if (contextIds[i].equals(template.getContextTypeId())) {
+ DocumentTemplateContext context= getContext(document, template, offset, length);
+ return context.canEvaluate(template) || isTemplateAllowed(context, template);
+ }
+ }
+ } catch (BadLocationException e) {
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TextEditorTemplatesPage#createPatternViewer(org.eclipse.swt.widgets.Composite)
+ */
+ protected Viewer createPatternViewer(Composite parent) {
+ if (parent == null)
+ return fPatternViewer ;
+ IDocument document= new Document();
+ JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
+ tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
+ IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
+ fPatternViewer= new JavaSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
+ SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false);
+ fPatternViewer.configure(configuration);
+ fPatternViewer.setEditable(false);
+ fPatternViewer.setDocument(document);
+
+ Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
+ fPatternViewer.getTextWidget().setFont(font);
+ new JavaSourcePreviewerUpdater(fPatternViewer, configuration, store);
+
+ Control control= fPatternViewer.getControl();
+ GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
+ control.setLayoutData(data);
+
+ fPatternViewer.setEditable(false);
+ return fPatternViewer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getImageForTemplate(org.eclipse.jface.text.templates.Template)
+ */
+ protected Image getImageForTemplate(Template template) {
+ if (template.getContextTypeId().equals(SWTContextType.ID))
+ return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SWT_TEMPLATE);
+ return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TextEditorTemplatesPage#editTemplate(org.eclipse.jface.text.templates.Template, boolean, boolean)
+ */
+ protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) {
+ EditTemplateDialog dialog= new EditTemplateDialog(getShell(), template, edit, isNameModifiable, getContextTypeRegistry());
+ if (dialog.open() == Window.OK) {
+ return dialog.getTemplate();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TextEditorTemplatesPage#getContextTypes()
+ */
+ protected String[] getContextTypes() {
+ Point selectedRange= getJavaEditor().getViewer().getSelectedRange();
+ int offset= selectedRange.x + selectedRange.y;
+ try {
+ IDocument document= getJavaEditor().getDocumentProvider().getDocument(getJavaEditor().getEditorInput());
+ return getContextIds(document, offset);
+ } catch (BadLocationException e) {
+ return new String[0];
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TextEditorTemplatesPage#updatePatternViewer(org.eclipse.jface.text.templates.Template)
+ */
+ protected void updatePatternViewer(Template template) {
+ if (template == null) {
+ fPatternViewer.getDocument().set(""); //$NON-NLS-1$
+ return ;
+ }
+ String contextId= template.getContextTypeId();
+ TemplateContextType type= getContextTypeRegistry().getContextType(contextId);
+ fTemplateProcessor.setContextType(type);
+
+ IDocument doc= fPatternViewer.getDocument();
+
+ String start= null;
+ if ("javadoc".equals(contextId)) { //$NON-NLS-1$
+ start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
+ } else
+ start= ""; //$NON-NLS-1$
+
+ doc.set(start + template.getPattern());
+ int startLen= start.length();
+ fPatternViewer.setDocument(doc, startLen, doc.getLength() - startLen);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.texteditor.templates.TemplatesPage#getPreferencePageId()
+ */
+ protected String getPreferencePageId() {
+ return PREFERENCE_PAGE_ID;
+ }
+
+ /**
+ * Helper function to return the JavaEditor
+ *
+ * @return the editor
+ */
+ private JavaEditor getJavaEditor() {
+ return (JavaEditor)getEditor() ;
+ }
+
+ /**
+ * Undomanager - end compound change
+ * @param viewer
+ */
+ private void endCompoundChange(ISourceViewer viewer) {
+ if (viewer instanceof ITextViewerExtension)
+ ((ITextViewerExtension) viewer).getRewriteTarget().endCompoundChange();
+ }
+
+ /**
+ * Undomanager - begin a compound change
+ * @param viewer
+ */
+ private void beginCompoundChange(ISourceViewer viewer) {
+ if (viewer instanceof ITextViewerExtension)
+ ((ITextViewerExtension) viewer).getRewriteTarget().beginCompoundChange();
+ }
+
+ /**
+ * Check whether the template is allowed eventhough the context can't evaluate it. This is needed because
+ * the Dropping of a template is more lenient than ctl-space invoked code assist.
+ *
+ * @param context
+ * @param template
+ * @return true if the template is allowed
+ */
+ private boolean isTemplateAllowed(DocumentTemplateContext context, Template template) {
+ int offset;
+ try {
+ if (template.getContextTypeId().equals(JavaDocContextType.ID)) {
+ return (offset= context.getCompletionOffset()) > 0 && Character.isWhitespace(context.getDocument().getChar(offset - 1));
+ } else {
+ return ((offset= context.getCompletionOffset()) > 0 && !isTemplateNamePart(context.getDocument().getChar(offset - 1)));
+ }
+ } catch (BadLocationException e) {
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the character is a valid character in Java template names
+ *
+ * @param ch
+ * @return true or false
+ */
+ private boolean isTemplateNamePart(char ch) {
+ return !Character.isWhitespace(ch) && ch != '(' && ch != ')' && ch != '{' && ch != '}' && ch != ';';
+ }
+
+ /**
+ * Get context
+ *
+ * @param document
+ * @param template
+ * @param offset
+ * @param length
+ * @return the context
+ */
+ private DocumentTemplateContext getContext(IDocument document, Template template, final int offset, int length) {
+ DocumentTemplateContext context;
+ if (template.getContextTypeId().equals(JavaDocContextType.ID)) {
+ context= new JavaDocContext(getContextTypeRegistry().getContextType(template.getContextTypeId()), document, new Position(offset, length), (ICompilationUnit) EditorUtility
+ .getEditorInputJavaElement(getJavaEditor(), true));
+ } else {
+ context= new JavaContext(getContextTypeRegistry().getContextType(template.getContextTypeId()), document, new Position(offset, length), (ICompilationUnit) EditorUtility.getEditorInputJavaElement(
+ getJavaEditor(), true));
+ }
+ return context;
+ }
+
+ /**
+ * Get the active contexts for the given position in the document
+ *
+ * @param document
+ * @param offset
+ * @return an array of valid context id
+ * @throws BadLocationException
+ */
+ private String[] getContextIds(IDocument document, int offset) throws BadLocationException {
+ String partition= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true);
+ String[] ids= new String[] { JavaContextType.ID, SWTContextType.ID };
+ if (partition.equals(IJavaPartitions.JAVA_DOC))
+ ids= new String[] { JavaDocContextType.ID };
+ return ids;
+ }
+
+ /**
+ * Get the java identifier terminated at the given offset
+ *
+ * @param document
+ * @param template
+ * @param offset
+ * @param length
+ * @return the identifier part
+ * @throws BadLocationException
+ */
+ private String getIdentifierPart(IDocument document, Template template, int offset, int length) throws BadLocationException {
+ return getContext(document, template, offset, length).getKey();
+ }
+}
#P org.eclipse.ui.views
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.views/META-INF/MANIFEST.MF,v
retrieving revision 1.9
diff -u -r1.9 MANIFEST.MF
--- META-INF/MANIFEST.MF 7 Sep 2006 19:17:20 -0000 1.9
+++ META-INF/MANIFEST.MF 17 Sep 2007 10:26:11 -0000
@@ -11,7 +11,8 @@
org.eclipse.ui.internal.views.contentoutline;x-internal:=true,
org.eclipse.ui.internal.views.properties;x-internal:=true,
org.eclipse.ui.views.contentoutline,
- org.eclipse.ui.views.properties
+ org.eclipse.ui.views.properties,
+ org.eclipse.ui.views.templates
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.help;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)"
Index: plugin.properties
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.views/plugin.properties,v
retrieving revision 1.13
diff -u -r1.13 plugin.properties
--- plugin.properties 8 May 2006 20:53:18 -0000 1.13
+++ plugin.properties 17 Sep 2007 10:26:11 -0000
@@ -7,10 +7,11 @@
#
# Contributors:
# IBM Corporation - initial API and implementation
+# Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
###############################################################################
pluginName= Views
providerName= Eclipse.org
Views.PropertySheet = Properties
Views.ContentOutline = Outline
-
+Views.Templates = Templates
Index: plugin.xml
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.views/plugin.xml,v
retrieving revision 1.26
diff -u -r1.26 plugin.xml
--- plugin.xml 23 Feb 2006 19:35:46 -0000 1.26
+++ plugin.xml 17 Sep 2007 10:26:11 -0000
@@ -18,6 +18,13 @@
class="org.eclipse.ui.views.contentoutline.ContentOutline"
id="org.eclipse.ui.views.ContentOutline">
+ "org.eclipse.ui.views.TemplatesView"
.
+ * getAdapter
:
+ *
+ * IEditorPart editor = ...;
+ * ITemplatePage templatePage = (ITemplatePage) editor.getAdapter(ITemplatePage.class);
+ * if (templatePage != null) {
+ * // editor wishes to contribute templatePage to templates view
+ * }
+ *
+ * If the editor supports a templates page, the editor instantiates
+ * and configures the page, and returns it. This page is then added to the
+ * templates view (a pagebook which presents one page at a time) and
+ * immediately made the current page (the templates view need not be
+ * visible). If the editor does not support a template page, the templates
+ * view shows a special default page which makes it clear to the user
+ * that the templates view is disengaged. When the templates view notices a
+ * different editor being activated, it flips to the editor's corresponding
+ * template page. When the templates view notices an editor being
+ * closed, it may destroy the editor's corresponding content outline page.
+ *
+ * The workbench will automatically instantiate this class when a templates + * view is needed for a workbench window. This class was not intended + * to be instantiated or subclassed by clients. + *
+ * + * @since 3.4 + */ +public class TemplatesView extends PageBookView { + /** + * The plugin prefix. + */ + public static final String PREFIX = PlatformUI.PLUGIN_ID + "."; //$NON-NLS-1$ + + /** + * Help context id used for the templates view + */ + public static final String TEMPLATES_VIEW_HELP_CONTEXT_ID = PREFIX + + "templates_view_context";//$NON-NLS-1$ + + /** + * Message to show on the default page. + */ + private static final String DEFAULT_TEXT = TemplatesMessages.Templates_defaultMessage; + + /** + * Creates a templates view + */ + public TemplatesView() { + super(); + } + + /* (non-Javadoc) + * Method declared on PageBookView. + */ + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage(DEFAULT_TEXT); + return page; + } + + /** + * ThePageBookView
implementation of this IWorkbenchPart
+ * method creates a PageBook
control with its default page showing.
+ */
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getPageBook(),
+ TEMPLATES_VIEW_HELP_CONTEXT_ID);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on PageBookView.
+ */
+ protected PageRec doCreatePage(IWorkbenchPart part) {
+ // Try to get template page.
+ Object obj = ViewsPlugin.getAdapter(part, ITemplatesPage.class, false);
+ if (obj instanceof ITemplatesPage) {
+ ITemplatesPage page = (ITemplatesPage) obj;
+ initPage(page);
+ page.createControl(getPageBook());
+ return new PageRec(part, page);
+ }
+ // There is no template page
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on PageBookView.
+ */
+ protected void doDestroyPage(IWorkbenchPart part, PageRec rec) {
+ ITemplatesPage page = (ITemplatesPage) rec.page;
+ page.dispose();
+ rec.dispose();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IAdaptable.
+ */
+ public Object getAdapter(Class key) {
+ if (key == IContributedContentsView.class) {
+ return new IContributedContentsView() {
+ public IWorkbenchPart getContributingPart() {
+ return getContributingEditor();
+ }
+ };
+ }
+ return super.getAdapter(key);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on PageBookView.
+ */
+ protected IWorkbenchPart getBootstrapPart() {
+ IWorkbenchPage page = getSite().getPage();
+ if (page != null) {
+ return page.getActiveEditor();
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the editor which contributed the current
+ * page to this view.
+ *
+ * @return the editor which contributed the current page
+ * or null
if no editor contributed the current page
+ */
+ private IWorkbenchPart getContributingEditor() {
+ return getCurrentContributingPart();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on PageBookView.
+ * We only want to track editors.
+ */
+ protected boolean isImportant(IWorkbenchPart part) {
+ //We only care about editors
+ return (part instanceof IEditorPart);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IViewPart.
+ * Treat this the same as part activation.
+ */
+ public void partBroughtToTop(IWorkbenchPart part) {
+ partActivated(part);
+ }
+}
Index: src/org/eclipse/ui/internal/views/templates/TemplatesMessages.java
===================================================================
RCS file: src/org/eclipse/ui/internal/views/templates/TemplatesMessages.java
diff -N src/org/eclipse/ui/internal/views/templates/TemplatesMessages.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/internal/views/templates/TemplatesMessages.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.internal.views.templates;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * TemplatesMessages is the message class for the messages used in the templates view.
+ */
+public class TemplatesMessages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.ui.internal.views.templates.TemplatesMessages"; //$NON-NLS-1$
+
+ /**
+ * Default message for an empty templates view
+ */
+ public static String Templates_defaultMessage;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, TemplatesMessages.class);
+ }
+
+ private TemplatesMessages() {
+ }
+}
Index: src/org/eclipse/ui/internal/views/templates/TemplatesMessages.properties
===================================================================
RCS file: src/org/eclipse/ui/internal/views/templates/TemplatesMessages.properties
diff -N src/org/eclipse/ui/internal/views/templates/TemplatesMessages.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/internal/views/templates/TemplatesMessages.properties 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2000, 2007 Dakshinamurthy Karra and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Dakshinamurthy Karra - initial API and implementation
+###############################################################################
+Templates_defaultMessage=Templates are not available.
Index: src/org/eclipse/ui/views/templates/ITemplatesPage.java
===================================================================
RCS file: src/org/eclipse/ui/views/templates/ITemplatesPage.java
diff -N src/org/eclipse/ui/views/templates/ITemplatesPage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/views/templates/ITemplatesPage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Dakshinamurthy Karra and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
+ *******************************************************************************/
+
+package org.eclipse.ui.views.templates;
+
+import org.eclipse.ui.part.IPageBookViewPage;
+
+/**
+ * Interface for a template page. This interface defines
+ * the minimum requirement for pages within the templates view, namely
+ * they must be pages (implement IPageBookViewPage
).
+ *
+ * @see TemplatesView
+ * @since 3.4
+ */
+public interface ITemplatesPage extends IPageBookViewPage {
+}
#P org.eclipse.ui.workbench
Index: Eclipse UI/org/eclipse/ui/IPageLayout.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IPageLayout.java,v
retrieving revision 1.33
diff -u -r1.33 IPageLayout.java
--- Eclipse UI/org/eclipse/ui/IPageLayout.java 26 Jun 2007 17:35:10 -0000 1.33
+++ Eclipse UI/org/eclipse/ui/IPageLayout.java 17 Sep 2007 10:26:14 -0000
@@ -10,6 +10,7 @@
* Chris Gross