From 53234e85cbb0efec0bb6ceab4015437f27bf2009 Mon Sep 17 00:00:00 2001 From: jsurfer Date: Thu, 2 Sep 2004 18:23:57 +0000 Subject: [PATCH] intial source from ttp://www.sf.net/projects/wdte --- .../net.sourceforge.phpeclipse.js.ui/.classpath | 7 + .../net.sourceforge.phpeclipse.js.ui/.cvsignore | 1 + archive/net.sourceforge.phpeclipse.js.ui/.project | 30 +++ .../build.properties | 16 ++ .../icons/class_method.gif | Bin 0 -> 879 bytes .../icons/class_obj.gif | Bin 0 -> 160 bytes .../icons/class_variable.gif | Bin 0 -> 131 bytes .../icons/dyn_class_obj.gif | Bin 0 -> 930 bytes .../icons/func.gif | Bin 0 -> 863 bytes .../icons/global_variable.gif | Bin 0 -> 119 bytes .../icons/instance_method.gif | Bin 0 -> 878 bytes .../icons/instance_variable.gif | Bin 0 -> 138 bytes .../net.sourceforge.phpeclipse.js.ui/icons/js.gif | Bin 0 -> 898 bytes .../icons/sample.gif | Bin 0 -> 983 bytes .../plugin.properties | 20 ++ .../net.sourceforge.phpeclipse.js.ui/plugin.xml | 72 ++++++ .../sourceforge/phpeclipse/js/ui/JSUIPlugin.java | 148 ++++++++++++ .../phpeclipse/js/ui/editors/JSColorManager.java | 75 ++++++ .../phpeclipse/js/ui/editors/JSConfiguration.java | 242 ++++++++++++++++++++ .../js/ui/editors/JSDocumentProvider.java | 81 +++++++ .../js/ui/editors/JSDoubleClickStrategy.java | 217 ++++++++++++++++++ .../phpeclipse/js/ui/editors/JSEditor.java | 187 +++++++++++++++ .../phpeclipse/js/ui/editors/JSEditorMessages.java | 45 ++++ .../js/ui/editors/JSEditorMessages.properties | 10 + .../phpeclipse/js/ui/editors/JSImages.java | 105 +++++++++ .../js/ui/internal/outline/JSOutlinePage.java | 102 ++++++++ .../js/ui/internal/text/JSCompletionProcessor.java | 59 +++++ .../js/ui/model/JSElementCategories.java | 39 +++ .../js/ui/model/JSModelAdapterFactory.java | 63 +++++ .../phpeclipse/js/ui/model/JSNameSorter.java | 55 +++++ .../phpeclipse/js/ui/model/JSWorkbenchAdapter.java | 91 ++++++++ .../ui/preferences/JavaScriptPreferencePage.java | 74 ++++++ .../js/ui/preferences/PreferenceNames.java | 36 +++ .../phpeclipse/js/ui/views/JSClassesView.java | 177 ++++++++++++++ .../js/ui/views/JSClassesViewContentProvider.java | 116 ++++++++++ 35 files changed, 2068 insertions(+), 0 deletions(-) create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/.cvsignore create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/.project create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/class_method.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/class_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/class_variable.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/dyn_class_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/func.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/global_variable.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/instance_method.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/instance_variable.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/js.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/icons/sample.gif create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/plugin.properties create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/JSUIPlugin.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSColorManager.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSConfiguration.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDocumentProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDoubleClickStrategy.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditor.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.properties create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSImages.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/outline/JSOutlinePage.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/text/JSCompletionProcessor.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSElementCategories.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSModelAdapterFactory.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSNameSorter.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSWorkbenchAdapter.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/JavaScriptPreferencePage.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/PreferenceNames.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesView.java create mode 100644 archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesViewContentProvider.java diff --git a/archive/net.sourceforge.phpeclipse.js.ui/.classpath b/archive/net.sourceforge.phpeclipse.js.ui/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.js.ui/.cvsignore b/archive/net.sourceforge.phpeclipse.js.ui/.cvsignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/archive/net.sourceforge.phpeclipse.js.ui/.project b/archive/net.sourceforge.phpeclipse.js.ui/.project new file mode 100644 index 0000000..20a5107 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/.project @@ -0,0 +1,30 @@ + + + net.sourceforge.phpeclipse.js.ui + + + net.sf.wdte.js.core + net.sf.wdte.ui + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/archive/net.sourceforge.phpeclipse.js.ui/build.properties b/archive/net.sourceforge.phpeclipse.js.ui/build.properties new file mode 100644 index 0000000..c2bb87a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/build.properties @@ -0,0 +1,16 @@ +bin.includes = plugin.xml,\ + *.jar,\ + icons/,\ + plugin.properties,\ + net.sf.wdte.js.ui.jar +src.includes = src/,\ + plugin.xml,\ + .template,\ + .project,\ + .classpath,\ + icons/,\ + plugin.properties,\ + build.properties +jars.compile.order = net.sf.wdte.js.ui.jar +source.net.sf.wdte.js.ui.jar = src/ +output.net.sf.wdte.js.ui.jar = bin/ diff --git a/archive/net.sourceforge.phpeclipse.js.ui/icons/class_method.gif b/archive/net.sourceforge.phpeclipse.js.ui/icons/class_method.gif new file mode 100644 index 0000000000000000000000000000000000000000..601ea4a5f808c4eba276e0a2a604b21f9bf0276c GIT binary patch literal 879 zcmZ?wbhEHb6krfw_|Cv!A8&78Z(lz@e*XUW0|yTL|Noz16pV(zhzSA3pDc_F46F<~ zARmMBgad~U12>0^$A*T+W>#(%i31ZBGB9u|OUYy?C^9fg$b0of6fQo*pkS+)W8tv) o_+%k#zb`9E wTk{`vdk|APSoUZD7sg^_`Ql|cuj3SEylQ}_34AubF CMuJy>s>g(Y?L*?(O~0!0_LY;eWE> z|2fJ3N5N+|z`)C(!vF-JJi)+G&mheq<594nsfmMC&Su5}g(e08MWuuT z3672(Oh#!T0fCOrjf^H;A{!hIIySO7aVZ!~XkcRG;;FfE;!{Hd6R(jPhe5#8MmA0^$A$$5n>mEFVoq#$c!)uO*+#~pkfEW4Q7cHK;A4VYuZ&>b8i`BF YCnm8oazu0rDK<=(l|5x6A;4e_01bj7Z2$lO literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.js.ui/icons/global_variable.gif b/archive/net.sourceforge.phpeclipse.js.ui/icons/global_variable.gif new file mode 100644 index 0000000000000000000000000000000000000000..db022b1c677f4ab45c18cd97b2481445442b4bbe GIT binary patch literal 119 zcmZ?wbhEHb6krfw*v!CSUvF<8Z@>Tk{`vdk|APSoUZD7sg^_`Ql|cuj3S0^N5F!{W>#T7lLZ?T54Um3JE>?CCN(yTva{WgIFQu9sKCz9@Wb#4 n1EaF&G@i~)54|SnhRzZZ2v%g6WfJVfav*s5(fRhwObpfl`=ch( literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.js.ui/icons/instance_variable.gif b/archive/net.sourceforge.phpeclipse.js.ui/icons/instance_variable.gif new file mode 100644 index 0000000000000000000000000000000000000000..dd3eb15513a403856d32e7928b06e3d96a5ab3a5 GIT binary patch literal 138 zcmZ?wbhEHb6krfw*v!CSUvF<8Z@>Tk{`vdk|APSoUZD7sg^_`Ql|cuj3S9*?jxd%4aX0yzy`dymabz zw#(eg=y~&N&n)dZv2xzduG}5lraiApo3(c4*{Ylg5#|$JO_EEZ<^|a2`Z*=9ns7DV zy=TR&gYw*7f%auV?ip3tvjRPmcdoho{K?x$_vR?C#t5&<;~V}S*>OMCr>h}%%bLZ9 zmo3`hYEwTICo-TTCZwgTsC&VjZRgJ1eE#fBa^%9R zmmfWS@;bnyJ27HWY}kxYzv(Hl>yu;FCPlAEh+34Muq-8Rb6C)<8qA3{r2e5 z`$vyngh#H=FWlqqvnapfc5%(!sQ4v?r7J61-&eJNEN^;KTK}T7{#i-gJh%G*9vcYdwv_*~xdw!Gz4Va?T!sXyyF@8?w<>X`X=#j%uHV4GRvj@+tE@ zQ%F!a)GKcn^~8abN>4la1UNXVL;{ZWi)lEwyeatDu%Lr6;aASiLrXXW zQm# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/JSUIPlugin.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/JSUIPlugin.java new file mode 100644 index 0000000..d01a57c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/JSUIPlugin.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2002-2004 Adrian Dinu and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Adrian Dinu - initial implementation + * + * $Id: JSUIPlugin.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui; + +import java.util.LinkedList; +import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import net.sourceforge.phpeclipse.js.ui.editors.JSImages; +import net.sourceforge.phpeclipse.js.ui.model.JSModelAdapterFactory; +import net.sourceforge.phpeclipse.js.ui.preferences.PreferenceNames; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class JSUIPlugin extends AbstractUIPlugin { + + /** The shared instance. */ + private static JSUIPlugin plugin; + + /** Resource bundle. */ + private ResourceBundle resourceBundle; + + /** The current func list. */ + private List currentFunctions = new LinkedList(); + + /** + * The constructor. + * + * @param descriptor the plugin descriptors + */ + public JSUIPlugin() { + plugin = this; + + try { + resourceBundle = ResourceBundle.getBundle( + "net.sourceforge.phpeclipse.js.ui.jseditorPluginResources"); //$NON-NLS-1$ + } catch (MissingResourceException e) { + resourceBundle = null; + } + } + + /** + * Returns the shared instance. + * @return + */ + public static JSUIPlugin getDefault() { + return plugin; + } + + /** + * Returns the workspace instance. + * @return + */ + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + /** + * Returns the string from the plugin's resource bundle, or 'key' if not + * found. + * + * @param key + * + * @return + */ + public static String getResourceString(String key) { + ResourceBundle bundle = JSUIPlugin.getDefault().getResourceBundle(); + try { + return bundle.getString(key); + } catch(MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + * @return + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * Returns the list of current functions. + * + * @return the current functions + */ + public List getCurrentFunctions() { + return currentFunctions; + } + + /** + * Sets the current list of functions. + * + * @param currentFunctions The functions to set + */ + public void setCurrentFunctions(List currentFunctions) { + this.currentFunctions = currentFunctions; + } + + /* + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + JSModelAdapterFactory.register(Platform.getAdapterManager()); + } + + /* + * @see AbstractUIPlugin#initializeDefaultPreferences(IPreferenceStore) + */ + protected void initializeDefaultPreferences(IPreferenceStore store) { + store.setDefault(PreferenceNames.P_AUTO_OUTLINE, true); + // TODO Use PreferenceConverter for color/string conversion + store.setDefault(PreferenceNames.P_COMMENT_COLOR, "63,127,95"); + store.setDefault(PreferenceNames.P_STRING_COLOR, "42,0,255"); + store.setDefault(PreferenceNames.P_KEYWORD_COLOR, "127,0,85"); + store.setDefault(PreferenceNames.P_DEFAULT_COLOR, "0,0,0"); + } + + /* + * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry) + */ + protected void initializeImageRegistry(ImageRegistry reg) { + JSImages.initializeRegistry(reg); + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSColorManager.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSColorManager.java new file mode 100644 index 0000000..53d14c4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSColorManager.java @@ -0,0 +1,75 @@ +/* + * $RCSfile: JSColorManager.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/05 03:13:28 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.ui 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.ui.editors; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $ + * + * @version $Revision: 1.1 $ + */ +public class JSColorManager +{ + protected Map fColorTable = new HashMap(10); + + /** + * + */ + public void dispose() + { + Iterator e = fColorTable.values().iterator(); + + while(e.hasNext()) + { + ((Color)e.next()).dispose(); + } + } + + /** + * + * + * @param rgb + * + * @return + */ + public Color getColor(RGB rgb) + { + Color color = (Color)fColorTable.get(rgb); + + if(color == null) + { + color = new Color(Display.getCurrent(), rgb); + fColorTable.put(rgb, color); + } + + return color; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSConfiguration.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSConfiguration.java new file mode 100644 index 0000000..a6a58a3 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSConfiguration.java @@ -0,0 +1,242 @@ +/* + * $RCSfile: JSConfiguration.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.2 2004/02/26 02:25:57 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:13:28 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.3.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.3 2003/12/10 20:19:16 agfitzp + * 3.0 port + * + * Revision 1.2 2003/06/21 03:48:51 agfitzp + * fixed global variables as functions bug + * fixed length calculation of instance variables + * Automatic outlining is now a preference + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.ui 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.ui.editors; + +import net.sourceforge.phpeclipse.js.core.parser.JSPartitionScanner; +import net.sourceforge.phpeclipse.js.core.parser.JSScanner; +import net.sourceforge.phpeclipse.js.core.parser.JSStringScanner; +import net.sourceforge.phpeclipse.js.core.parser.NonRuleBasedDamagerRepairer; +import net.sourceforge.phpeclipse.js.ui.JSUIPlugin; +import net.sourceforge.phpeclipse.js.ui.internal.text.JSCompletionProcessor; +import net.sourceforge.phpeclipse.js.ui.preferences.PreferenceNames; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextDoubleClickStrategy; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $ + * + * @version $Revision: 1.1 $ + */ +public class JSConfiguration extends SourceViewerConfiguration +{ + private JSDoubleClickStrategy doubleClickStrategy; + private JSStringScanner stringScanner; + private JSScanner scanner; + private JSColorManager colorManager; + private IPreferenceStore preferences; + + /** + * Creates a new JSConfiguration object. + * + * @param colorManager + */ + public JSConfiguration(JSColorManager colorManager) + { + this.colorManager = colorManager; + this.preferences = JSUIPlugin.getDefault().getPreferenceStore(); + } + + public boolean getAutomaticOutliningPreference() + { + return preferences.getBoolean(PreferenceNames.P_AUTO_OUTLINE); + } + + protected RGB getColorPreference(String categoryColor) + { + String rgbString = preferences.getString(categoryColor); + + if (rgbString.length() <= 0) + { + rgbString = preferences.getDefaultString(categoryColor); + if(rgbString.length() <= 0) + { + rgbString = "0,0,0"; + } + } + return StringConverter.asRGB(rgbString); + } + + public Color getContentColor(String categoryColor) + { + return colorManager.getColor(getColorPreference(categoryColor)); + } + + /** + * + * + * @param sourceViewer + * + * @return + */ + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) + { + return new String[] { + IDocument.DEFAULT_CONTENT_TYPE, + JSPartitionScanner.JS_COMMENT, + JSPartitionScanner.JS_KEYWORD, + JSPartitionScanner.JS_STRING }; + } + + /** + * + * + * @param sourceViewer + * @param contentType + * + * @return + */ + public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) + { + if (doubleClickStrategy == null) + { + doubleClickStrategy = new JSDoubleClickStrategy(); + } + + return doubleClickStrategy; + } + + /** + * + * + * @return + */ + protected JSScanner getJSScanner() + { + if (scanner == null) + { + Color defaultColor = getContentColor(PreferenceNames.P_DEFAULT_COLOR); + scanner = new JSScanner(defaultColor); + scanner.setDefaultReturnToken(new Token(new TextAttribute(defaultColor))); + } + + return scanner; + } + + /** + * + * + * @return + */ + protected JSStringScanner getJSStringScanner() + { + if (stringScanner == null) + { + Color stringColor = getContentColor(PreferenceNames.P_STRING_COLOR); + stringScanner = new JSStringScanner(stringColor); + stringScanner.setDefaultReturnToken(new Token(new TextAttribute(stringColor))); + } + + return stringScanner; + } + + /** + * + * + * @param sourceViewer + * + * @return + */ + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) + { + PresentationReconciler reconciler = new PresentationReconciler(); + + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getJSScanner()); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + NonRuleBasedDamagerRepairer commentRepairer = + new NonRuleBasedDamagerRepairer(new TextAttribute(getContentColor(PreferenceNames.P_COMMENT_COLOR))); + reconciler.setDamager(commentRepairer, JSPartitionScanner.JS_COMMENT); + reconciler.setRepairer(commentRepairer, JSPartitionScanner.JS_COMMENT); + + NonRuleBasedDamagerRepairer stringRepairer = + new NonRuleBasedDamagerRepairer(new TextAttribute(getContentColor(PreferenceNames.P_STRING_COLOR))); + reconciler.setDamager(stringRepairer, JSPartitionScanner.JS_STRING); + reconciler.setRepairer(stringRepairer, JSPartitionScanner.JS_STRING); + + NonRuleBasedDamagerRepairer keywordRepairer = + new NonRuleBasedDamagerRepairer(new TextAttribute(getContentColor(PreferenceNames.P_KEYWORD_COLOR), null, SWT.BOLD)); + reconciler.setDamager(keywordRepairer, JSPartitionScanner.JS_KEYWORD); + reconciler.setRepairer(keywordRepairer, JSPartitionScanner.JS_KEYWORD); + + return reconciler; + } + /** + * @return + */ + public IPreferenceStore getPreferences() { + return preferences; + } + + /** + * @param store + */ + public void setPreferences(IPreferenceStore store) { + preferences = store; + } + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + + IContentAssistProcessor processor = new JSCompletionProcessor(); + assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(processor, JSPartitionScanner.JS_COMMENT); + assistant.setContentAssistProcessor(processor, JSPartitionScanner.JS_STRING); + assistant.setContentAssistProcessor(processor, JSPartitionScanner.JS_KEYWORD); + assistant.setContentAssistProcessor(processor, JSPartitionScanner.JS_DEFAULT); + assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE); + assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); + + return assistant; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDocumentProvider.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDocumentProvider.java new file mode 100644 index 0000000..1994fae --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDocumentProvider.java @@ -0,0 +1,81 @@ +/* + * $RCSfile: JSDocumentProvider.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.2 2004/02/26 02:25:57 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:13:28 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.1 2003/05/28 15:17:11 agfitzp + * net.sourceforge.phpeclipse.js.ui 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.ui.editors; + +import net.sourceforge.phpeclipse.js.core.parser.JSPartitionScanner; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.rules.DefaultPartitioner; +import org.eclipse.ui.editors.text.FileDocumentProvider; + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $ + * + * @version $Revision: 1.1 $ + */ +public class JSDocumentProvider extends FileDocumentProvider { + + /** + * Array of constant token types that will be color hilighted. + */ + private static String[] colorTokens= { + JSPartitionScanner.JS_COMMENT, + JSPartitionScanner.JS_STRING, + JSPartitionScanner.JS_KEYWORD + }; + + /** + * Constructor for JSDocumentProvider. + */ + public JSDocumentProvider() { + super(); + } + + /** + * @param element + * + * @return + * + * @throws CoreException + */ + protected IDocument createDocument(Object element) throws CoreException { + IDocument document = super.createDocument(element); + + if (document != null) { + IDocumentPartitioner partitioner = + new DefaultPartitioner(new JSPartitionScanner(), colorTokens); + partitioner.connect(document); + document.setDocumentPartitioner(partitioner); + } + + return document; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDoubleClickStrategy.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDoubleClickStrategy.java new file mode 100644 index 0000000..8317759 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSDoubleClickStrategy.java @@ -0,0 +1,217 @@ +/* + * $RCSfile: JSDoubleClickStrategy.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/05 03:13:28 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.ui 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.ui.editors; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextDoubleClickStrategy; +import org.eclipse.jface.text.ITextViewer; + + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $ + * + * @version $Revision: 1.1 $ + */ +public class JSDoubleClickStrategy implements ITextDoubleClickStrategy +{ + protected ITextViewer fText; + + /** + * Creates a new JSDoubleClickStrategy object. + */ + public JSDoubleClickStrategy() + { + super(); + } + + /** + * + * + * @param part + */ + public void doubleClicked(ITextViewer part) + { + int pos = part.getSelectedRange().x; + + if(pos < 0) + { + return; + } + + fText = part; + + if(!selectComment(pos)) + { + selectWord(pos); + } + } + + /** + * + * + * @param caretPos + * + * @return + */ + protected boolean selectComment(int caretPos) + { + IDocument doc = fText.getDocument(); + int startPos; + int endPos; + + try + { + int pos = caretPos; + char c = ' '; + + while(pos >= 0) + { + c = doc.getChar(pos); + + if(c == '\\') + { + pos -= 2; + + continue; + } + + if(c == Character.LINE_SEPARATOR || c == '\"') + { + break; + } + + --pos; + } + + if(c != '\"') + { + return false; + } + + startPos = pos; + + pos = caretPos; + + int length = doc.getLength(); + c = ' '; + + while(pos < length) + { + c = doc.getChar(pos); + + if(c == Character.LINE_SEPARATOR || c == '\"') + { + break; + } + + ++pos; + } + + if(c != '\"') + { + return false; + } + + endPos = pos; + + int offset = startPos + 1; + int len = endPos - offset; + fText.setSelectedRange(offset, len); + + return true; + } + catch(BadLocationException x) + { + } + + return false; + } + + /** + * + * + * @param caretPos + * + * @return + */ + protected boolean selectWord(int caretPos) + { + IDocument doc = fText.getDocument(); + int startPos; + int endPos; + + try + { + int pos = caretPos; + char c; + + while(pos >= 0) + { + c = doc.getChar(pos); + + if(!Character.isJavaIdentifierPart(c)) + { + break; + } + + --pos; + } + + startPos = pos; + + pos = caretPos; + + int length = doc.getLength(); + + while(pos < length) + { + c = doc.getChar(pos); + + if(!Character.isJavaIdentifierPart(c)) + { + break; + } + + ++pos; + } + + endPos = pos; + selectRange(startPos, endPos); + + return true; + } + catch(BadLocationException x) + { + } + + return false; + } + + private void selectRange(int startPos, int stopPos) + { + int offset = startPos + 1; + int length = stopPos - offset; + fText.setSelectedRange(offset, length); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditor.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditor.java new file mode 100644 index 0000000..3a627d0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditor.java @@ -0,0 +1,187 @@ +/* + * $RCSfile: JSEditor.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.4 2004/02/27 17:12:48 cell + * Use the new outline page + * + * Revision 1.3 2004/02/26 02:25:57 agfitzp + * renamed packages to match xml & css + * + * Revision 1.2 2004/02/14 18:36:30 ayashi + * More UI-Core refactoring... still doesn't work though... + * + * Revision 1.1 2004/02/05 03:13:28 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.5.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.5 2003/08/14 15:14:15 agfitzp + * Removed thread hack from automatic update + * + * Revision 1.4 2003/07/04 17:26:56 agfitzp + * New hack, update in a new thread only if we're not already in the middle of updating + * + * Revision 1.3 2003/06/21 03:48:51 agfitzp + * fixed global variables as functions bug + * fixed length calculation of instance variables + * Automatic outlining is now a preference + * + * Revision 1.2 2003/05/28 20:47:58 agfitzp + * Outline the document, not the file. + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.ui 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.ui.editors; + +import net.sourceforge.phpeclipse.js.core.model.JSElement; +import net.sourceforge.phpeclipse.js.ui.internal.outline.JSOutlinePage; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; + +/** + * DOCUMENT ME! + * + * @version $Revision: 1.1 $ + * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $ + */ +public class JSEditor extends TextEditor implements ISelectionChangedListener +{ + protected JSColorManager colorManager = new JSColorManager(); + protected JSOutlinePage outlinePage; + protected JSConfiguration configuration; + + protected boolean updating = false; + + /** + * Constructor for SampleEditor. + */ + public JSEditor() + { + super(); + configuration = new JSConfiguration(colorManager); + + setSourceViewerConfiguration(configuration); + setDocumentProvider(new JSDocumentProvider()); + } + protected void createActions() { + super.createActions(); + + IAction action = new ContentAssistAction(JSEditorMessages.getResourceBundle(), + "ContentAssistProposal.", this); //$NON-NLS-1$ + action + .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ + +// IAction action= new TextOperationAction( +// TemplateMessages.getResourceBundle(), +// "Editor." + TEMPLATE_PROPOSALS + ".", //$NON-NLS-1$ //$NON-NLS-2$ +// this, +// ISourceViewer.CONTENTASSIST_PROPOSALS); +// action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); +// setAction(TEMPLATE_PROPOSALS, action); +// markAsStateDependentAction(TEMPLATE_PROPOSALS, true); + } + /** + * Method declared on IEditorPart + * @param monitor + */ + public void doSave(IProgressMonitor monitor) + { + super.doSave(monitor); + + if (outlinePage != null) + { + outlinePage.update(); + } + } + + /** + * + */ + public void dispose() + { + colorManager.dispose(); + super.dispose(); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#getAdapter(Class) + */ + public Object getAdapter(Class key) { + if (key.equals(IContentOutlinePage.class)) { + outlinePage = new JSOutlinePage(this); + outlinePage.addSelectionChangedListener(this); + return outlinePage; + } + return super.getAdapter(key); + } + + /** + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) + { + if (null != event) + { + if (event.getSelection() instanceof IStructuredSelection) + { + IStructuredSelection sel = (IStructuredSelection) event.getSelection(); + if (null != sel) + { + JSElement fe = (JSElement) sel.getFirstElement(); + if (null != fe) + { + selectAndReveal(fe.getStart(), fe.getLength()); + } + } + } + } + } + + /** + * Updates all content dependent actions. + * + * This might be a hack: We're trapping this update to ensure that the + * outline is always up to date. + */ + protected void updateContentDependentActions() + { + super.updateContentDependentActions(); + + if(!updating) + { + if (configuration.getAutomaticOutliningPreference()) + { + if (outlinePage != null) + { + updating = true; + + outlinePage.update(); + updating = false; + } + } + } + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.java new file mode 100644 index 0000000..5af638b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.java @@ -0,0 +1,45 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +package net.sourceforge.phpeclipse.js.ui.editors; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class JSEditorMessages { + + private static final String RESOURCE_BUNDLE= "net.sourceforge.phpeclipse.js.ui.editors.JSEditorMessages";//$NON-NLS-1$ + + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private JSEditorMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } + + public static ResourceBundle getResourceBundle() { + return fgResourceBundle; + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.properties b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.properties new file mode 100644 index 0000000..bea66ef --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSEditorMessages.properties @@ -0,0 +1,10 @@ +############################################################# +# +# (c) Copyright IBM Corp. 2000, 2001. +# All Rights Reserved. +# +############################################################# +ContentAssistProposal.label=Content Assist@Ctrl+SPACE +ContentAssistProposal.tooltip=Content Assist +ContentAssistProposal.image= +ContentAssistProposal.description=Content Assist diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSImages.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSImages.java new file mode 100644 index 0000000..085c2a9 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/editors/JSImages.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2002-2004 Adrian Dinu and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Adrian Dinu - initial implementation + * Alex Fitzpatrick - additional images + * Christopher Lenz - migration to use the plugin's image registry + * + * $Id: JSImages.java,v 1.1 2004-09-02 18:23:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.editors; + +import java.net.URL; + +import net.sourceforge.phpeclipse.js.ui.JSUIPlugin; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; + +/** + * Convenience class for storing references to image descriptors used by the JS + * editor. + */ +public class JSImages { + + public static final String ICON_VAR = + "global_variable.gif"; //$NON-NLS-1$ + public static final String ICON_FUNCTION = + "func.gif"; //$NON-NLS-1$ + public static final String ICON_CLASS = + "class_obj.gif"; //$NON-NLS-1$ + public static final String ICON_DYNAMIC_CLASS = + "dyn_class_obj.gif"; //$NON-NLS-1$ + public static final String ICON_CLASS_METHOD = + "class_method.gif"; //$NON-NLS-1$ + public static final String ICON_INSTANCE_METHOD = + "instance_method.gif"; //$NON-NLS-1$ + public static final String ICON_CLASS_VAR = + "class_variable.gif"; //$NON-NLS-1$ + public static final String ICON_INSTANCE_VAR = + "instance_variable.gif"; //$NON-NLS-1$ + + /** + * Returns the image for the specified key, or null if no image for + * that key is found. + * + * @param key the key under which the image was registered + * @return the image, or null if none + */ + public static Image get(String key) { + return JSUIPlugin.getDefault().getImageRegistry().get(key); + } + + /** + * Returns the image descriptor for the specified key, or null if + * no image for that key is found. + * + * @param key the key under which the image was registered + * @return the image descriptor, or null if none + */ + public static ImageDescriptor getDescriptor(String key) { + return JSUIPlugin.getDefault().getImageRegistry().getDescriptor(key); + } + + /** + * Initializes the given image registry with all images provided through + * this class. + * + * @param reg the registry to initialize + */ + public static void initializeRegistry(ImageRegistry reg) { + reg.put(ICON_VAR, createImageDescriptor(ICON_VAR)); + reg.put(ICON_FUNCTION, createImageDescriptor(ICON_FUNCTION)); + reg.put(ICON_CLASS, createImageDescriptor(ICON_CLASS)); + reg.put(ICON_DYNAMIC_CLASS, createImageDescriptor(ICON_DYNAMIC_CLASS)); + reg.put(ICON_CLASS_METHOD, createImageDescriptor(ICON_CLASS_METHOD)); + reg.put(ICON_INSTANCE_METHOD, + createImageDescriptor(ICON_INSTANCE_METHOD)); + reg.put(ICON_CLASS_VAR, createImageDescriptor(ICON_CLASS_VAR)); + reg.put(ICON_INSTANCE_VAR, createImageDescriptor(ICON_INSTANCE_VAR)); + } + + /** + * Utility method to create an ImageDescriptor from a path to a + * file. + * + * @param path the full path to the image file + * @return the image descriptor + */ + private static ImageDescriptor createImageDescriptor(String path) { + try { + URL url = JSUIPlugin.getDefault().getBundle() + .getEntry("/icons/" + path); //$NON-NLS-1$ + return ImageDescriptor.createFromURL(url); + } catch (IllegalStateException e) { + return ImageDescriptor.getMissingImageDescriptor(); + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/outline/JSOutlinePage.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/outline/JSOutlinePage.java new file mode 100644 index 0000000..fe2506f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/outline/JSOutlinePage.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2002-2004 Adrian Dinu and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Adrian Dinu - initial implementation + * Alex Fitzpatrick - update outline while editing + * Christopher Lenz - use custom content and label providers + * + * $Id: JSOutlinePage.java,v 1.1 2004-09-02 18:23:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.internal.outline; + +import net.sourceforge.phpeclipse.js.core.model.JSElementList; +import net.sourceforge.phpeclipse.js.core.parser.JSSyntaxModelFactory; +import net.sourceforge.phpeclipse.js.ui.model.JSNameSorter; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +/** + * Implements an outline page for JavaScript files. + */ +public class JSOutlinePage extends ContentOutlinePage { + + // Instance Variables ------------------------------------------------------ + + /** The associated text editor. **/ + protected ITextEditor editor; + + // Constructors ------------------------------------------------------------ + + /** + * Creates a new JSOutlinePage. + * + * @param editor the associated text editor + */ + public JSOutlinePage(ITextEditor editor) { + this.editor = editor; + } + + // ContentOutlinePage Implementation --------------------------------------- + + /* + * @see org.eclipse.ui.part.IPage#createControl(Composite) + */ + public void createControl(Composite parent) { + super.createControl(parent); + TreeViewer viewer = getTreeViewer(); + viewer.setContentProvider(new WorkbenchContentProvider()); + viewer.setLabelProvider(new WorkbenchLabelProvider()); + // TODO Make sorting optional + viewer.setSorter(new JSNameSorter()); + } + + // Public Methods ---------------------------------------------------------- + + /** + * Forces the outline page to update its contents. + */ + public void update() { + IDocument document = getDocument(); + JSSyntaxModelFactory factory = JSSyntaxModelFactory.getInstance(); + JSElementList model = factory.getContentOutline(document); + if (model != null) { + TreeViewer viewer = getTreeViewer(); + if (viewer != null) { + Control control = viewer.getControl(); + if ((control != null) && !control.isDisposed()) { + control.setRedraw(false); + viewer.setInput(model); + viewer.expandAll(); + control.setRedraw(true); + } + } + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns the document that is open in the associated text editor. + * + * @return the document being edited + */ + private IDocument getDocument() { + IDocumentProvider provider = editor.getDocumentProvider(); + return provider.getDocument(editor.getEditorInput()); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/text/JSCompletionProcessor.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/text/JSCompletionProcessor.java new file mode 100644 index 0000000..63aa64b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/text/JSCompletionProcessor.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpeclipse.js.ui.internal.text; + +import net.sourceforge.phpeclipse.ui.WebUI; +import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor; +import net.sourceforge.phpeclipse.ui.templates.template.JSContextType; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.templates.TemplateContextType; + + +/** + * A completion processor for XML templates. + */ +public class JSCompletionProcessor extends BasicCompletionProcessor { + /** + * We watch for angular brackets since those are often part of XML + * templates. + */ + protected String extractPrefix(ITextViewer viewer, int offset) { + IDocument document= viewer.getDocument(); + int i= offset; + if (i > document.getLength()) + return ""; //$NON-NLS-1$ + + try { + while (i > 0) { + char ch= document.getChar(i - 1); + if (!Character.isJavaIdentifierPart(ch)) + break; + i--; + } + + return document.get(i, offset - i); + } catch (BadLocationException e) { + return ""; //$NON-NLS-1$ + } + } + /** + * Return the XML context type that is supported by this plugin. + */ + protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { + return WebUI.getDefault().getContextTypeRegistry().getContextType(JSContextType.JS_CONTEXT_TYPE); + } + + +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSElementCategories.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSElementCategories.java new file mode 100644 index 0000000..b42aea1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSElementCategories.java @@ -0,0 +1,39 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:58 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/14 18:36:30 ayashi + * More UI-Core refactoring... still doesn't work though... + * + * Revision 1.1 2004/02/05 03:13:29 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.ui.model; + +/** + * @author fitzpata + * + */ +public interface JSElementCategories +{ + static final int CLASS = 1; + static final int FUNCTION = 2; + static final int VARIABLE = 3; + static final int CLASS_VARIABLE = 4; + static final int INSTANCE_VARIABLE = 5; + static final int CLASS_METHOD = 6; + static final int INSTANCE_METHOD = 7; +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSModelAdapterFactory.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSModelAdapterFactory.java new file mode 100644 index 0000000..bf4e0db --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSModelAdapterFactory.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: JSModelAdapterFactory.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.model; + +import net.sourceforge.phpeclipse.js.core.model.JSElement; +import net.sourceforge.phpeclipse.js.core.model.JSElementList; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ui.model.IWorkbenchAdapter; + +/** + * Factory that creates adapters for JavaScript model objects. + */ +public class JSModelAdapterFactory implements IAdapterFactory { + + // Static Methods ---------------------------------------------------------- + + /** + * Creates and registers this adapter factory with the given manager. + * + * @param manager the adapter manager to register with + */ + public static void register(IAdapterManager manager) { + JSModelAdapterFactory factory = new JSModelAdapterFactory(); + manager.registerAdapters(factory, JSElement.class); + manager.registerAdapters(factory, JSElementList.class); + } + + // IAdapterFactory Implementation ------------------------------------------ + + /* + * @see IAdapterFactory#getAdapter(Object, Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adapterType == IWorkbenchAdapter.class) { + if ((adaptableObject instanceof JSElement) + || (adaptableObject instanceof JSElementList)) { + return new JSWorkbenchAdapter(); + } + } + return null; + } + + /* + * @see IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[] { IWorkbenchAdapter.class }; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSNameSorter.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSNameSorter.java new file mode 100644 index 0000000..bc16e53 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSNameSorter.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2003-2004 Alex Fitzpatrick and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Alex Fitzpatrick - initial implementation + * + * $Id: JSNameSorter.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.model; + +import net.sourceforge.phpeclipse.js.core.model.JSClassElement; +import net.sourceforge.phpeclipse.js.core.model.JSClassMethodElement; +import net.sourceforge.phpeclipse.js.core.model.JSClassVariableElement; +import net.sourceforge.phpeclipse.js.core.model.JSFunctionElement; +import net.sourceforge.phpeclipse.js.core.model.JSGlobalVariableElement; +import net.sourceforge.phpeclipse.js.core.model.JSInstanceMethodElement; +import net.sourceforge.phpeclipse.js.core.model.JSInstanceVariableElement; + +import org.eclipse.jface.viewers.ViewerSorter; + +/** + * Name sorter. + */ +public class JSNameSorter extends ViewerSorter { + + // ViewerSorter Implementation --------------------------------------------- + + /* + * @see ViewerSorter#category(Object) + */ + public int category(Object element) { + if (element instanceof JSClassElement) { + return JSElementCategories.CLASS; + } else if (element instanceof JSFunctionElement) { + return JSElementCategories.FUNCTION; + } else if (element instanceof JSGlobalVariableElement) { + return JSElementCategories.VARIABLE; + } else if (element instanceof JSClassVariableElement) { + return JSElementCategories.CLASS_VARIABLE; + } else if (element instanceof JSInstanceVariableElement) { + return JSElementCategories.INSTANCE_VARIABLE; + } else if (element instanceof JSClassMethodElement) { + return JSElementCategories.CLASS_METHOD; + } else if (element instanceof JSInstanceMethodElement) { + return JSElementCategories.INSTANCE_VARIABLE; + } + return super.category(element); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSWorkbenchAdapter.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSWorkbenchAdapter.java new file mode 100644 index 0000000..81d98bc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSWorkbenchAdapter.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: JSWorkbenchAdapter.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.model; + +import net.sourceforge.phpeclipse.js.core.model.JSClassElement; +import net.sourceforge.phpeclipse.js.core.model.JSClassMethodElement; +import net.sourceforge.phpeclipse.js.core.model.JSClassVariableElement; +import net.sourceforge.phpeclipse.js.core.model.JSElement; +import net.sourceforge.phpeclipse.js.core.model.JSElementList; +import net.sourceforge.phpeclipse.js.core.model.JSFunctionElement; +import net.sourceforge.phpeclipse.js.core.model.JSGlobalVariableElement; +import net.sourceforge.phpeclipse.js.core.model.JSInstanceMethodElement; +import net.sourceforge.phpeclipse.js.core.model.JSInstanceVariableElement; +import net.sourceforge.phpeclipse.js.ui.editors.JSImages; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.WorkbenchAdapter; + +/** + * Adapter that provides a visual representation of JavaScript model elements. + */ +public class JSWorkbenchAdapter extends WorkbenchAdapter { + + // IWorkbenchAdapter Implementation ---------------------------------------- + + /* + * @see IWorkbenchAdapter#getChildren(Object) + */ + public Object[] getChildren(Object o) { + if (o instanceof JSElementList) { + return ((JSElementList) o).getChildren(null); + } else if (o instanceof JSElement) { + return ((JSElement) o).getChildren(null); + } + return super.getChildren(o); + } + + /* + * @see IWorkbenchAdapter#getImageDescriptor(Object) + */ + public ImageDescriptor getImageDescriptor(Object o) { + if (o instanceof JSClassElement) { + return JSImages.getDescriptor(JSImages.ICON_CLASS); + } else if (o instanceof JSGlobalVariableElement) { + return JSImages.getDescriptor(JSImages.ICON_VAR); + } else if (o instanceof JSFunctionElement) { + return JSImages.getDescriptor(JSImages.ICON_FUNCTION); + } else if (o instanceof JSClassMethodElement) { + return JSImages.getDescriptor(JSImages.ICON_CLASS_METHOD); + } else if (o instanceof JSClassVariableElement) { + return JSImages.getDescriptor(JSImages.ICON_CLASS_VAR); + } else if (o instanceof JSInstanceMethodElement) { + return JSImages.getDescriptor(JSImages.ICON_INSTANCE_METHOD); + } else if (o instanceof JSInstanceVariableElement) { + return JSImages.getDescriptor(JSImages.ICON_INSTANCE_VAR); + } + return super.getImageDescriptor(o); + } + + /* + * @see IWorkbenchAdapter#getLabel(Object) + */ + public String getLabel(Object o) { + if (o instanceof JSElement) { + return ((JSElement) o).getName(); + } + return super.getLabel(o); + } + + /* + * @see IWorkbenchAdapter#getParent(Object) + */ + public Object getParent(Object o) { + if (o instanceof JSElement) { + return ((JSElement) o).getParent(null); + } + return super.getParent(o); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/JavaScriptPreferencePage.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/JavaScriptPreferencePage.java new file mode 100644 index 0000000..b170b80 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/JavaScriptPreferencePage.java @@ -0,0 +1,74 @@ +/* + * Created on May 20th, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/05 03:13:29 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.4 2003/12/10 20:19:16 agfitzp + * 3.0 port + * + * Revision 1.3 2003/06/21 03:48:51 agfitzp + * fixed global variables as functions bug + * fixed length calculation of instance variables + * Automatic outlining is now a preference + * + * Revision 1.2 2003/05/30 20:53:08 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.ui.preferences; + +import net.sourceforge.phpeclipse.js.ui.JSUIPlugin; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ColorFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * This class represents a preference page that + * is contributed to the Preferences dialog. By + * subclassing FieldEditorPreferencePage, we + * can use the field support built into JFace that allows + * us to create a page that is small and knows how to + * save, restore and apply itself. + *

+ * This page is used to modify preferences only. They + * are stored in the preference store that belongs to + * the main plug-in class. That way, preferences can + * be accessed directly via the preference store. + */ + +public class JavaScriptPreferencePage + extends FieldEditorPreferencePage + implements IWorkbenchPreferencePage , PreferenceNames { + + public JavaScriptPreferencePage() { + super(GRID); + setPreferenceStore(JSUIPlugin.getDefault().getPreferenceStore()); + setDescription("Preferences for JavaScript editor."); + } + +/** + * Creates the field editors. Field editors are abstractions of + * the common GUI blocks needed to manipulate various types + * of preferences. Each field editor knows how to save and + * restore itself. + */ + + public void createFieldEditors() { + addField(new BooleanFieldEditor(P_AUTO_OUTLINE, "&Automatic Outlining", getFieldEditorParent())); + addField(new ColorFieldEditor(P_COMMENT_COLOR, "&Comment Color:", getFieldEditorParent())); + addField(new ColorFieldEditor(P_STRING_COLOR, "&String Color:", getFieldEditorParent())); + addField(new ColorFieldEditor(P_KEYWORD_COLOR, "&Keyword Color:", getFieldEditorParent())); + addField(new ColorFieldEditor(P_DEFAULT_COLOR, "D&efault Color:", getFieldEditorParent())); + } + + public void init(IWorkbench workbench) { + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/PreferenceNames.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/PreferenceNames.java new file mode 100644 index 0000000..dc35f5b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/preferences/PreferenceNames.java @@ -0,0 +1,36 @@ +/* + * Created on May 15, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/05 03:13:29 agfitzp + * Initial submission, outline view is broken due to refactoring + * + * Revision 1.4 2003/12/10 20:19:16 agfitzp + * 3.0 port + * + * Revision 1.3 2003/06/21 03:48:51 agfitzp + * fixed global variables as functions bug + * fixed length calculation of instance variables + * Automatic outlining is now a preference + * + * Revision 1.2 2003/05/30 20:53:08 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.ui.preferences; + +/** + * Publicly available list of preference names as constants. + * @author fitzpata + */ +public interface PreferenceNames +{ + String P_COMMENT_COLOR = "commentColor"; + String P_STRING_COLOR = "stringColor"; + String P_KEYWORD_COLOR = "keywordColor"; + String P_DEFAULT_COLOR = "defaultColor"; + String P_AUTO_OUTLINE = "autoOutline"; +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesView.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesView.java new file mode 100644 index 0000000..314b809 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesView.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2003-2004 Alex Fitzpatrick and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Alex Fitzpatrick - initial implementation + * + * $Id: JSClassesView.java,v 1.1 2004-09-02 18:23:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.views; + +import net.sourceforge.phpeclipse.js.ui.model.JSNameSorter; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.part.DrillDownAdapter; +import org.eclipse.ui.part.ViewPart; + +/** + * A view of all JavaScript syntactic elements in all projects. + */ +public class JSClassesView extends ViewPart { + + private TreeViewer viewer; + private DrillDownAdapter drillDownAdapter; + private Action action1; + private Action action2; + private Action doubleClickAction; + + /** + * The constructor. + */ + public JSClassesView() { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + public void createPartControl(Composite parent) { + viewer = + new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + drillDownAdapter = new DrillDownAdapter(viewer); + viewer.setContentProvider(new JSClassesViewContentProvider()); + viewer.setLabelProvider(new WorkbenchLabelProvider()); + viewer.setSorter(new JSNameSorter()); + viewer.setInput(ResourcesPlugin.getWorkspace()); + makeActions(); + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + } + + /** + * + */ + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + JSClassesView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + /** + * + */ + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { + manager.add(action1); + manager.add(new Separator()); + manager.add(action2); + } + + private void fillContextMenu(IMenuManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void fillLocalToolBar(IToolBarManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + } + + private void makeActions() { + action1 = new Action() { + public void run() { + showMessage("Action 1 executed"); + } + }; + action1.setText("Action 1"); + action1.setToolTipText("Action 1 tooltip"); + action1.setImageDescriptor( + PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_OBJS_INFO_TSK)); + + action2 = new Action() { + public void run() { + showMessage("Action 2 executed"); + } + }; + action2.setText("Action 2"); + action2.setToolTipText("Action 2 tooltip"); + action2.setImageDescriptor( + PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + IDE.SharedImages.IMG_OBJS_TASK_TSK)); + doubleClickAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + Object obj = + ((IStructuredSelection) selection).getFirstElement(); + showMessage("Double-click detected on " + obj.toString()); + } + }; + } + + private void hookDoubleClickAction() { + viewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + doubleClickAction.run(); + } + }); + } + private void showMessage(String message) { + MessageDialog.openInformation( + viewer.getControl().getShell(), + "Classes", + message); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#setFocus() + */ + public void setFocus() { + viewer.getControl().setFocus(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesViewContentProvider.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesViewContentProvider.java new file mode 100644 index 0000000..2fb678a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/views/JSClassesViewContentProvider.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2003-2004 Alex Fitzpatrick and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Alex Fitzpatrick - initial implementation + * + * $Id: JSClassesViewContentProvider.java,v 1.1 2004-09-02 18:23:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.js.ui.views; + +import net.sourceforge.phpeclipse.js.core.model.JSElement; +import net.sourceforge.phpeclipse.js.core.parser.JSSyntaxModelFactory; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * Content provider for the JavaScript classes view. + */ +class JSClassesViewContentProvider + implements IStructuredContentProvider, ITreeContentProvider { + private IWorkspace invisibleRoot; + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, + * java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object parent) { + if (parent.equals(ResourcesPlugin.getWorkspace())) { + if (invisibleRoot == null) + invisibleRoot = ((IWorkspace) parent); + return getChildren(invisibleRoot); + } + return getChildren(parent); + } + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object child) { + if (child instanceof IProject) { + return ((IProject) child).getWorkspace(); + } + + if (child instanceof JSElement) { + return ((JSElement) child).getParent(child); + } + return null; + } + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object parent) { + + if (parent instanceof IWorkspace) { + return invisibleRoot.getRoot().getProjects(); + } + + if (parent instanceof IProject) { + return getClasses((IProject) parent); + } + + if (parent instanceof JSElement) { + return ((JSElement) parent).getChildren(parent); + } + + return new Object[0]; + } + /** + * @param project + * @return + */ + private Object[] getClasses(IProject project) { + return JSSyntaxModelFactory + .getInstance() + .getContentOutline(project) + .getChildren(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object parent) { + return getChildren(parent).length > 0; + } +} -- 1.7.1