[Desc.] Widget -> html support is added.
[Issue] RM7801, RM7601, RM7642, RM7970
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Tizen Advanced Declaration View for JavaScript
+Bundle-Name: Tizen Advanced Declaration View
Bundle-SymbolicName: org.tizen.web.advanceddeclarationview;singleton:=true
Bundle-Version: 1.0.0.qualifier
-Fragment-Host: org.eclipse.wst.jsdt.ui;bundle-version="1.1.101"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.ui,
- org.eclipse.osgi.util;bundle-version="3.2.200"
+Bundle-Activator: org.tizen.web.advanceddeclarationview.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.wst.jsdt.core;bundle-version="1.1.102",
+ org.tizen.webuibuilder;bundle-version="1.0.0",
+ org.eclipse.core.resources;bundle-version="3.7.101"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Import-Package:
+ org.eclipse.gef,
+ org.eclipse.jface.text,
+ org.eclipse.jface.text.source,
+ org.eclipse.ui.editors.text,
+ org.eclipse.ui.texteditor,
+ org.eclipse.wst.html.core.internal.provisional.contenttype,
+ org.eclipse.wst.html.ui,
+ org.eclipse.wst.jsdt.internal.corext.util,
+ org.eclipse.wst.jsdt.internal.ui,
+ org.eclipse.wst.jsdt.internal.ui.javaeditor,
+ org.eclipse.wst.jsdt.internal.ui.text,
+ org.eclipse.wst.jsdt.internal.ui.util,
+ org.eclipse.wst.jsdt.ui,
+ org.eclipse.wst.jsdt.ui.actions,
+ org.eclipse.wst.jsdt.ui.text,
+ org.eclipse.wst.sse.core,
+ org.eclipse.wst.sse.core.internal.provisional,
+ org.eclipse.wst.sse.ui.internal,
+ org.tizen.webuibuilder.editparts,
+ org.tizen.webuibuilder.ui.editor
Bundle-Vendor: The Linux Foundation
source.. = src/
output.. = bin/
-bin.includes = META-INF/,\
+bin.includes = plugin.xml,\
+ META-INF/,\
.,\
- fragment.xml,\
icons/
+++ /dev/null
-<contexts>
- <context id="viewer" title="Sample View">
- <description>This is the context help for the sample view with a table viewer. It was generated by a PDE template.</description>
- <topic href="/PLUGINS_ROOT/org.eclipse.platform.doc.isv/guide/ua_help_context.htm" label="Context-sensitive help">
- <enablement>
- <with variable="platform">
- <test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.platform.doc.isv"/>
- </with>
- </enablement>
- </topic>
- </context>
-</contexts>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<fragment>
- <extension
- point="org.eclipse.ui.views">
- <view
- category="org.eclipse.wst.jsdt.ui.java"
- class="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView"
- icon="icons/declaration_view_icon.png"
- id="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView"
- name="Declaration">
- </view>
- </extension>
- <extension
- point="org.eclipse.help.contexts">
- <contexts
- file="contexts.xml">
- </contexts>
- </extension>
-
-<extension
- point="org.eclipse.ui.viewActions">
- <viewContribution
- id="org.tizen.web.advanceddeclarationview.viewContribution"
- targetID="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView">
- <action
- class="org.tizen.web.advanceddeclarationview.ui.ToggleLockActionDelegate"
- definitionId="org.tizen.web.advanceddeclarationview.ui.LockView"
- icon="icons/declaration_view_lock.png"
- id="org.tizen.web.advanceddeclarationview.lockAction"
- label="&Lock View"
- state="false"
- style="toggle"
- toolbarPath="additions"
- tooltip="Lock">
- </action>
- </viewContribution>
- </extension>
- <extension
- point="org.eclipse.ui.bindings">
- <key
- commandId="org.tizen.web.advanceddeclarationview.ui.LockView"
- contextId="org.eclipse.ui.contexts.window"
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
- sequence="Alt+L">
- </key>
- <key
- commandId="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView"
- contextId="org.eclipse.ui.contexts.window"
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
- sequence="Alt+Ctrl+O">
- </key>
- </extension>
-
- <extension
- point="org.eclipse.ui.commands">
- <category
- id="org.tizen.web.advanceddeclarationview.commands"
- name="Advanced Declaration View"
- description="Advanced Declaration View Commands"/>
- <command
- categoryId="org.tizen.web.advanceddeclarationview.commands"
- id="org.tizen.web.advanceddeclarationview.ui.LockView"
- name="Lock Advanced Declaration View"
- defaultHandler="org.tizen.web.advanceddeclarationview.ui.ViewHandler">
- </command>
- </extension>
- <extension
- point="org.eclipse.ui.viewActions">
- <viewContribution
- id="org.tizen.web.advanceddeclarationview.viewContribution1"
- targetID="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView">
- <action
- class="org.tizen.web.advanceddeclarationview.ui.ToggleLineNumberActionDelegate"
- id="org.tizen.web.advanceddeclarationview.togglelinenumberaction"
- label="Show Line Number"
- state="true"
- style="toggle"
- tooltip="Show Line Number">
- </action>
- </viewContribution>
- </extension>
- <extension
- point="org.eclipse.ui.viewActions">
- <viewContribution
- id="org.tizen.web.advanceddeclarationview.viewContribution2"
- targetID="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView">
- <action
- class="org.tizen.web.advanceddeclarationview.ui.OpenInputActionDelegate"
- icon="icons/declaration_view_open.png"
- id="org.tizen.web.advanceddeclarationview.action1"
- label="Open Input"
- style="push"
- toolbarPath="additions"
- tooltip="Open Input">
- </action>
- </viewContribution>
- </extension>
- <extension
- point="org.eclipse.ui.themes">
- <colorDefinition
- label="Declaration view background"
- categoryId="org.eclipse.wst.jsdt.ui.presentation"
- value="242,254,255"
- id="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView.backgroundColor">
- <description>
- The color used as background for the JavaScript Declaration view.
- </description>
- </colorDefinition>
- </extension>
-
- <!-- Set Advanced Declaration View location beside Pages in TizenWeb perspective -->
- <extension
- point="org.eclipse.ui.perspectiveExtensions">
- <perspectiveExtension
- targetID="org.tizen.web.ui.perspective.WebWidget">
- <view
- id="org.tizen.webuibuilder.ui.views.PagesView"
- relationship="stack"
- relative="org.eclipse.ui.views.ProblemView">
- </view>
- <view
- id="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView"
- relationship="stack"
- relative="org.eclipse.ui.views.ProblemView">
- </view>
- </perspectiveExtension>
- </extension>
-</fragment>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ name="Tizen"
+ id="org.tizen.web.AdvancedDeclarationView">
+ </category>
+ <view
+ name="Declaration"
+ icon="icons/declaration_view_icon.png"
+ category="org.tizen.web.AdvancedDeclarationView"
+ class="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView"
+ id="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView">
+ </view>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.themes">
+ <colorDefinition
+ label="Declaration view background"
+ categoryId="org.eclipse.wst.jsdt.ui.presentation"
+ value="242,254,255"
+ id="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView.backgroundColor">
+ <description>
+ The color used as background for the JavaScript Declaration view.
+ </description>
+ </colorDefinition>
+ </extension>
+
+ <!-- Set Advanced Declaration View location beside Pages in TizenWeb perspective -->
+ <extension
+ point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension
+ targetID="org.tizen.web.ui.perspective.WebWidget">
+ <view
+ id="org.tizen.webuibuilder.ui.views.PagesView"
+ relationship="stack"
+ relative="org.eclipse.ui.views.ProblemView">
+ </view>
+ <view
+ id="org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView"
+ relationship="stack"
+ relative="org.eclipse.ui.views.ProblemView">
+ </view>
+ </perspectiveExtension>
+ </extension>
+</plugin>
--- /dev/null
+/*******************************************************************************
+ * Program Understanding / Advanced Declaration View for JavaScript
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyukmin Kwon <hyukmin0530@samsung.com>
+ * Jaeheung Kim <jaeheung.kim@samsung.com>
+ * Sujin Kim <sujin921.kim@samsung.com>
+ * Woongsik Choi <woongsik76.choi@samsung.com>
+ *
+ * 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:
+ * - S-Core Co., Ltd
+ *
+ *******************************************************************************/
+package org.tizen.web.advanceddeclarationview;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.tizen.web.advanceddeclarationview"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
* Sujin Kim <sujin921.kim@samsung.com>
* Woongsik Choi <woongsik76.choi@samsung.com>
*
- * The Original Code is JSDT's org.eclipse.wst.jsdt.internal.ui.infoviews package.
- * The Initial developer or author of the Original Code is IBM Corporation and others.
- * Samsung Electronics Co., Ltd. modifies it under the terms of Eclipse Public License v1.0
- *
* 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
*******************************************************************************/
package org.tizen.web.advanceddeclarationview.ui;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.resource.ColorRegistry;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextPresentationListener;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.source.CompositeRuler;
-import org.eclipse.jface.text.source.ISharedTextColors;
-import org.eclipse.jface.text.source.LineNumberRulerColumn;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ComboViewer;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.part.*;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.part.ViewPart;
-import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
-import org.eclipse.wst.jsdt.core.ICodeAssist;
-import org.eclipse.wst.jsdt.core.IJavaScriptElement;
-import org.eclipse.wst.jsdt.core.ILocalVariable;
-import org.eclipse.wst.jsdt.core.IMember;
-import org.eclipse.wst.jsdt.core.ISourceRange;
-import org.eclipse.wst.jsdt.core.ISourceReference;
-import org.eclipse.wst.jsdt.core.JavaScriptModelException;
-import org.eclipse.wst.jsdt.internal.core.SourceType;
-import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds;
-import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor;
-import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaSourceViewer;
-import org.eclipse.wst.jsdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
-import org.eclipse.wst.jsdt.internal.ui.util.SelectionUtil;
-import org.eclipse.wst.jsdt.ui.IContextMenuConstants;
-import org.eclipse.wst.jsdt.ui.JavaScriptElementLabels;
-import org.eclipse.wst.jsdt.ui.actions.IJavaEditorActionDefinitionIds;
-import org.eclipse.wst.jsdt.ui.actions.JdtActionConstants;
-import org.eclipse.wst.jsdt.ui.actions.OpenAction;
-import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions;
-import org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration;
+import org.tizen.webuibuilder.ui.editor.PageDesigner;
+@SuppressWarnings("restriction")
+public class AdvancedDeclarationView extends PageBookView implements ISelectionListener {
-/**
- * Abstract class for views which show information for a given element.
- *
- *
- */
-public class AdvancedDeclarationView extends ViewPart implements ISelectionListener, IMenuListener, IPropertyChangeListener {
- /** Symbolic Java editor font name. */
- private static final String SYMBOLIC_FONT_NAME= "org.eclipse.wst.jsdt.ui.editors.textfont"; //$NON-NLS-1$
-
- /** JavaScriptElementLabels flags used for the title */
- private final long TITLE_FLAGS= JavaScriptElementLabels.ALL_FULLY_QUALIFIED
- | JavaScriptElementLabels.M_PRE_RETURNTYPE | JavaScriptElementLabels.M_PARAMETER_TYPES | JavaScriptElementLabels.M_PARAMETER_NAMES | JavaScriptElementLabels.M_EXCEPTIONS
- | JavaScriptElementLabels.F_PRE_TYPE_SIGNATURE | JavaScriptElementLabels.M_PRE_TYPE_PARAMETERS | JavaScriptElementLabels.T_TYPE_PARAMETERS
- | JavaScriptElementLabels.USE_RESOLVED
- | JavaScriptElementLabels.APPEND_ROOT_PATH;
- private final long LOCAL_VARIABLE_TITLE_FLAGS= TITLE_FLAGS & ~JavaScriptElementLabels.F_FULLY_QUALIFIED | JavaScriptElementLabels.F_POST_QUALIFIED;
+ /**
+ * The ID of the view as specified by the extension.
+ */
+ public static final String ID = "org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView";
- /** JavaScriptElementLabels flags used for the tool tip text */
- private static final long TOOLTIP_LABEL_FLAGS= JavaScriptElementLabels.DEFAULT_QUALIFIED | JavaScriptElementLabels.ROOT_POST_QUALIFIED | JavaScriptElementLabels.APPEND_ROOT_PATH |
- JavaScriptElementLabels.M_PARAMETER_TYPES | JavaScriptElementLabels.M_PARAMETER_NAMES | JavaScriptElementLabels.M_APP_RETURNTYPE | JavaScriptElementLabels.M_EXCEPTIONS |
- JavaScriptElementLabels.F_APP_TYPE_SIGNATURE | JavaScriptElementLabels.T_TYPE_PARAMETERS;
- private static final int LAYOUT_NORMAL = 0;
- private static final int LAYOUT_MULTIPLE_ELEMENTS = 1;
- private static final int LAYOUT_NOTHING_TO_VIEW = 2;
-
/*
* @see IPartListener2
*/
}
public void partInputChanged(IWorkbenchPartReference ref) {
if (!ref.getId().equals(getSite().getId())) {
- computeAndSetInput(ref.getPart(false));
+ if (getCurrentPage() instanceof DeclarationPage) {
+ ((DeclarationPage) getCurrentPage()).computeAndSetInput(ref.getPart(false));
+ }
}
}
public void partActivated(IWorkbenchPartReference ref) {
}
};
- /** Parent control */
- private Composite parentControl;
- /** This view's source viewer */
- private SourceViewer fSrcViewer;
- /** This view's combo viewer */
- private ComboViewer fComboViewer;
- /** The viewers configuration */
- private JavaScriptSourceViewerConfiguration fViewerConfiguration;
- /** This view's javascript element info label */
- private Label fElementInfoLabel;
- /** This view's result info label */
- private Label fComboBoxLabel;
- /** The viewer's vertical ruler */
- private CompositeRuler fVerticalRuler;
- /** The viewer's showing line number flag */
- private boolean fShowLineNumber = true;
- /** The viewer's line number column */
- private LineNumberRulerColumn fLineNumberColumn;
- /** The toggle line number ruler action */
- private IAction fToggleLineNumberAction;
- /** The open input action action */
- private IAction fOpenInputAction;
-
- /** The viewer's font properties change listener. */
- private IPropertyChangeListener fFontPropertyChangeListener= new FontPropertyChangeListener();
- /** The current input. */
- protected IJavaScriptElement fSelectedElement;
-
- /**
- * The editor's property change listener.
- *
- */
- private IPropertyChangeListener fPropertyChangeListener= new PropertyChangeListener();
- /** The open action */
- private OpenAction fOpen;
- /** The toggle lock action */
- private IAction fToggleLockAction;
-
- /** Counts the number of background computation requests. */
- private volatile int fComputeCount;
-
- /** Flag for locking */
- private boolean locked = false;
-
- /** Background color. */
- private Color fBackgroundColor;
- private RGB fBackgroundColorRGB;
-
- /**
- * Internal property change listener for handling changes in the editor's preferences.
- */
- class PropertyChangeListener implements IPropertyChangeListener {
- /*
- * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- if (fSrcViewer == null) {
- return;
- }
-
- if (fViewerConfiguration.affectsTextPresentation(event)) {
- fViewerConfiguration.handlePropertyChangeEvent(event);
- fSrcViewer.invalidateTextPresentation();
- }
- if (event.getProperty().equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR)) {
- updateLineNumberColumnPresentation(true);
- }
- }
- }
-
/**
- * Internal property change listener for handling workbench font changes.
+ * Start to listen for selection changes.
*/
- class FontPropertyChangeListener implements IPropertyChangeListener {
- /*
- * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- if (fSrcViewer == null) {
- return;
- }
-
- String property= event.getProperty();
-
- if (SYMBOLIC_FONT_NAME.equals(property)) {
- setViewerFont();
- }
- }
+ void startListeningForSelectionChanges() {
+ getSite().getPage().addPostSelectionListener(this);
}
- private ISourceRange getSourceRange(IJavaScriptElement element) {
- ISourceRange range = null;
- if (element instanceof ISourceReference) {
- try {
- if (element instanceof ILocalVariable) {
- range = ((ILocalVariable) element).getNameRange();
- } else if (element instanceof IMember) {
- range = ((IMember) element).getNameRange();
- } else {
- range = ((ISourceReference) element).getSourceRange();
- }
- } catch (JavaScriptModelException e) {
- return null;
- }
- }
- return range;
- }
-
/**
- * Remove elements with no JavaScript file which contains the element
- * @param elements array to search
- * @return elements array
+ * Stop to listen for selection changes.
*/
- private IJavaScriptElement[] removeElementsWithNoContainingJSFile(IJavaScriptElement[] elements) {
- if (elements == null) {
- return elements;
- }
-
- int count = elements.length;
- for (int i = 0; i < elements.length; i++) {
- if (elements[i] == null) {
- count--;
- continue;
- }
- if (getJsFileElement(elements[i]) == null) {
- elements[i] = null;
- count--;
- }
- }
-
- IJavaScriptElement[] jsElements = new IJavaScriptElement[count];
- for (int i = 0, j = 0; i < elements.length; i++) {
- if (elements[i] != null) {
- jsElements[j++] = elements[i];
- }
- }
- return jsElements;
+ void stopListeningForSelectionChanges() {
+ getSite().getPage().removePostSelectionListener(this);
}
- /**
- * Brute force search to remove elements by comparing with SourceRanges.
- * @param elements to search
- * @return removed unnecessary elements
- */
- private IJavaScriptElement[] removeDuplicateElements(IJavaScriptElement[] elements) {
- if (elements == null || elements.length <= 1) {
- return elements;
- }
-
- int count = elements.length;
- outerloop: for (int i = 0; i < elements.length; i++) {
- if (elements[i] == null) {
- continue;
- }
-
- IJavaScriptElement ifile = getJsFileElement(elements[i]);
- ISourceRange irange = getSourceRange(elements[i]);
- if (irange == null) {
- continue;
- }
- int ioffset = irange.getOffset();
- int ilength = irange.getLength();
-
- for (int j = i + 1; j < elements.length; j++) {
- if (elements[j] == null) {
- continue;
- }
-
- IJavaScriptElement jfile = getJsFileElement(elements[j]);
- ISourceRange jrange = getSourceRange(elements[j]);
- if (jrange == null) {
- continue;
- }
-
- int joffset = jrange.getOffset();
- int jlength = jrange.getLength();
-
- if (ifile == null || jfile == null || !ifile.equals(jfile) || ilength == jlength) {
- continue;
- }
-
- // start comparing ranges to remove element
- if (ioffset >= joffset && (ioffset + ilength <= joffset + jlength)) {
- elements[j] = null;
- count--;
- } else if (ioffset <= joffset && (ioffset + ilength >= joffset + jlength)) {
- elements[i] = null;
- count--;
- continue outerloop;
- }
- }
- }
-
- IJavaScriptElement[] jsElements = new IJavaScriptElement[count];
- // copy all non null elements to jsElements
- for (int i = 0, j = 0; i < elements.length; i++) {
- if (elements[i] != null) {
- jsElements[j++] = elements[i];
- }
- }
-
- return jsElements;
- }
-
- /**
- * Find default element and set it to elements[0]
- * @param elements elements to search and set
- */
- private void findDefaultElementAndSet(IJavaScriptElement[] elements) {
- if(elements == null)
- return;
- for (int index = 0; index < elements.length; index++) {
- if(!(elements[index] instanceof SourceType)) {
- // set default element to elements[0]
- IJavaScriptElement element = elements[0];
- elements[0] = elements[index];
- elements[index] = element;
- }
- }
- }
-
- /**
- * Text presentation listeners for handling background color.
- * @author sujin
- */
- private class DeclarationVieweTextPresenter implements ITextPresentationListener {
- @Override
- public void applyTextPresentation(TextPresentation textPresentation) {
- highlightDeclaration(textPresentation);
- }
- private void highlightDeclaration(TextPresentation textPresentation) {
-
- //Highlight and scroll to the declaration.
- ISourceRange range = getSourceRange(fSelectedElement);
- if(range != null) {
- Display disp = fSrcViewer.getControl().getDisplay();
- StyleRange styleRange = new StyleRange();
- styleRange.start = range.getOffset();
- styleRange.length = range.getLength();
- styleRange.background = new Color(disp, new RGB(185,211,238));
-
- fSrcViewer.setRangeIndication(range.getOffset(), range.getLength(), true);
- textPresentation.mergeStyleRange(styleRange);
- }
- }
- }
-
- /**
- * Set the input of this view.
- *
- * @param input the input object
- */
- protected void setInput(Object input) {
- if (input instanceof IDocument) {
- fSrcViewer.setInput(input);
- } else if (input == null) {
- fSrcViewer.setInput(new Document("")); //$NON-NLS-1$
- } else {
- IDocument document= new Document(input.toString());
- JavaScriptPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING);
- fSrcViewer.setInput(document);
- }
-
- if (input != null) {
- fSrcViewer.invalidateTextPresentation();
- }
- }
-
- /**
- * Computes the input for this view based on the given element.
- *
- * @param element the element from which to compute the input
- * @return the input or <code>null</code> if the input was not computed successfully
- */
- protected Object getJsFileSource(Object input) {
- if (!(input instanceof IJavaScriptElement)) {
- return null;
- }
-
- IJavaScriptElement inputFile = getJsFileElement(((IJavaScriptElement)input));
-
- if (inputFile == null) {
- return null;
- }
-
- if (fSrcViewer == null || !(inputFile instanceof ISourceReference)) {
- return null;
- }
-
- ISourceReference sourceRef= (ISourceReference)inputFile;
-
- String source;
- try {
- source= sourceRef.getSource();
- } catch (JavaScriptModelException ex) {
- return ""; //$NON-NLS-1$
- }
-
- if (source == null) {
- return ""; //$NON-NLS-1$
- }
-
- return source;
- }
-
- /**
- * Find the name of the JavaScript file containing the given JavaScript element.
- *
- * @param element JavaScript element
- * @return the file name String or "" if the containing JavaScript file can not be found.
- */
- protected String getJsFileName(IJavaScriptElement element) {
- IJavaScriptElement file = getJsFileElement(element);
- if (file == null) {
- return "";
- } else {
- return file.getElementName();
- }
- }
-
- /**
- * Find the JavaScript element for file containing the given JavaScript element.
- *
- * @param element JavaScript element
- * @return the file JavaScript element or <code>null</code> if the containing JavaScript file can not be found.
- */
- protected IJavaScriptElement getJsFileElement(IJavaScriptElement element) {
- IJavaScriptElement file = element.getAncestor(IJavaScriptElement.JAVASCRIPT_UNIT);
- if (file == null) {
- file = element.getAncestor(IJavaScriptElement.CLASS_FILE);
- }
-
- return file;
- }
-
- /**
- * Set the view's foreground color.
- *
- * @param color the SWT color
- */
- protected void setForeground(Color color) {
- fSrcViewer.getTextWidget().setForeground(color);
- }
-
- /**
- * Set the view's background color.
- *
- * @param color the SWT color
- */
- protected void setBackground(Color color) {
- fSrcViewer.getTextWidget().setBackground(color);
- }
+ /** The toggle lock action */
+ private ToggleLockAction fToggleLockAction;
- public void setFocus() {
- fSrcViewer.getTextWidget().setFocus();
- }
+ /** The toggle line number ruler action */
+ private ToggleLineNumberAction fToggleLineNumberAction;
- /**
- * Returns the view's primary control.
- *
- * @return the primary control
- */
- protected Control getControl() {
- return fSrcViewer.getControl();
- }
-
- /**
- * Returns the context ID for the Help system
- *
- * @return the string used as ID for the Help context
- *
- */
- protected String getHelpContextId() {
- return IJavaHelpContextIds.SOURCE_VIEW;
- }
- /**
- * set locked flag.
- * @param flag
- */
- public void setLocked(boolean flag) {
- locked = flag;
- }
-
- /**
- * Returns locked flag.
- *
- * @return the locked flag
- *
- */
- protected boolean isLocked() {
- return locked;
- }
-
- /**
- * set lock action.
- * @param ac
- */
- public void setLockAction(IAction ac) {
- fToggleLockAction = ac;
- }
-
- /**
- * get lock action.
- * @return
- */
- public IAction getLockAction() {
+ public ToggleLockAction getToggleLockAction() {
return fToggleLockAction;
}
- /**
- * set Show Line Number flag.
- * @param flag
- */
- public void setLineNumberStatus(boolean flag) {
- fShowLineNumber = flag;
- updateLineNumberRuler();
- }
-
- /**
- * set toggle line number action.
- * @param ac
- */
- public void setToggleLineNumberAction(IAction ac) {
- fToggleLineNumberAction = ac;
- }
-
- /**
- * get toggle line number action.
- * @return
- */
- public IAction getToggleLineNumberAction() {
+ public ToggleLineNumberAction getToggleLineNumberAction() {
return fToggleLineNumberAction;
}
-
- /**
- * set open in action.
- * @param ac
- */
- public void setOpenInputAction(IAction ac) {
- fOpenInputAction = ac;
- }
-
-
- /**
- * get open in action.
- * @return
- */
- public IAction getOpenInputAction() {
- return fOpenInputAction;
- }
- /**
- * Returns Show Line Number flag.
- *
- * @return the fShowLineNumber flag
- *
- */
- public boolean getLineNumberStatus() {
- return fShowLineNumber;
- }
-
- /*
- * @see IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
- */
- public final void createPartControl(Composite parent) {
- internalCreatePartControl(parent);
- inititalizeColors();
- getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener);
- createContextMenu();
- createActions();
- fillActionBars(getViewSite().getActionBars());
- PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpContextId());
- }
-
- /**
- * Create the part control.
- *
- * @param parent the parent control
- * @see IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
- */
- protected void internalCreatePartControl(Composite parent) {
- parentControl = parent;
- parent.setLayout(new FormLayout());
-
- IPreferenceStore store= JavaScriptPlugin.getDefault().getCombinedPreferenceStore();
- fComboViewer = new ComboViewer(parent, SWT.READ_ONLY);
- fComboViewer.setLabelProvider(new LabelProvider() {
- @Override
- public String getText(Object element) {
- if (element instanceof IJavaScriptElement) {
- IJavaScriptElement jsElement = (IJavaScriptElement)element;
- return getElementLabelString(jsElement);
- } else {
- return super.getText(element);
- }
- }
- });
- fComboViewer.setContentProvider(new ArrayContentProvider());
- fComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection selection = event.getSelection();
- if (!(selection instanceof StructuredSelection)) {
- return;
- }
-
- Object selectedObject = ((StructuredSelection)selection).getFirstElement();
- if (!(selectedObject instanceof IJavaScriptElement)) {
- return;
- }
-
- IJavaScriptElement selectedElement = (IJavaScriptElement)selectedObject;
- processComboViewerSelection(selectedElement);
- }
- });
-
- fElementInfoLabel = new Label(parent, SWT.LEFT);
- fElementInfoLabel.setText("");
-
- fComboBoxLabel = new Label(parent, SWT.LEFT);
- fComboBoxLabel.setText("");
-
- fVerticalRuler = new CompositeRuler();
- fSrcViewer = new JavaSourceViewer(parent, fVerticalRuler, null, false, SWT.V_SCROLL | SWT.H_SCROLL, store);
- fViewerConfiguration= new SimpleJavaSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, IJavaScriptPartitions.JAVA_PARTITIONING, false);
- fSrcViewer.configure(fViewerConfiguration);
- fSrcViewer.setEditable(false);
- ITextPresentationListener textPresenter = new DeclarationVieweTextPresenter();
- fSrcViewer.addTextPresentationListener(textPresenter);
- setViewerFont();
- JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
- store.addPropertyChangeListener(fPropertyChangeListener);
- getViewSite().setSelectionProvider(fSrcViewer);
-
- updateLayout(LAYOUT_NOTHING_TO_VIEW);
-
- updateLineNumberRuler();
- }
-
- private void inititalizeColors() {
- if (getSite().getShell().isDisposed()) {
- return;
- }
-
- Display display= getSite().getShell().getDisplay();
- if (display == null || display.isDisposed()) {
- return;
- }
- setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
-
- ColorRegistry registry= JFaceResources.getColorRegistry();
- registry.addListener(this);
-
- fBackgroundColorRGB= registry.getRGB(getBackgroundColorKey());
- Color bgColor;
- if (fBackgroundColorRGB == null) {
- bgColor= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fBackgroundColorRGB= bgColor.getRGB();
+ protected void createActions() {
+ fToggleLockAction = new ToggleLockAction();
+ fToggleLineNumberAction = new ToggleLineNumberAction(this);
+ }
+
+ public void setActionBars(IActionBars actionBars){
+ IToolBarManager toolBarManager= actionBars.getToolBarManager();
+ toolBarManager.add(getToggleLockAction());
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener);
+ createActions();
+ setActionBars(getViewSite().getActionBars());
+ }
+
+ @Override
+ protected IPage createDefaultPage(PageBook book) {
+ MessagePage messagePage = new MessagePage();
+ initPage(messagePage);
+ messagePage.setMessage("Declaration View is not available");
+ messagePage.createControl(book);
+ return messagePage;
+ }
+
+ @Override
+ protected PageRec doCreatePage(IWorkbenchPart part) {
+
+ if (part instanceof JavaEditor) {
+ JSDeclarationPage jsDeclarationPage = new JSDeclarationPage(getViewSite());
+ initPage(jsDeclarationPage);
+ jsDeclarationPage.createControl(getPageBook());
+ return new PageRec(part, jsDeclarationPage);
+ } else if (part instanceof PageDesigner) {
+ GUIBuilderDeclarationPage guiBuilderDeclarationPage = new GUIBuilderDeclarationPage(getViewSite());
+ initPage(guiBuilderDeclarationPage);
+ guiBuilderDeclarationPage.createControl(getPageBook());
+ return new PageRec(part, guiBuilderDeclarationPage);
} else {
- bgColor= new Color(display, fBackgroundColorRGB);
- fBackgroundColor= bgColor;
+ MessagePage messagePage = new MessagePage();
+ initPage(messagePage);
+ String msg = "Page for "+part.getSite().getPluginId();
+ if (part instanceof PageDesigner) {
+ msg = msg + " : Pagedesigner";
+ } else if (part instanceof JavaEditor) {
+ msg = msg + " : JavaScriptEditor";
+ } else {
+ msg = msg + " : Not interested";
+ }
+ messagePage.setMessage(msg);
+ messagePage.createControl(getPageBook());
+ return new PageRec(part, messagePage);
}
- setBackground(bgColor);
- }
-
- /**
- * Creates the context menu for this view.
- */
- protected void createContextMenu() {
- MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$
- menuManager.setRemoveAllWhenShown(true);
- menuManager.addMenuListener(this);
- Menu contextMenu= menuManager.createContextMenu(fSrcViewer.getTextWidget());
- fSrcViewer.getTextWidget().setMenu(contextMenu);
- getSite().registerContextMenu(menuManager, getSelectionProvider());
}
- /**
- * Creates the actions and action groups for this view.
- */
- protected void createActions() {
-
- // Setup OpenAction
- fOpen= new OpenAction(getViewSite()) {
- /*
- * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#getSelection()
- */
- public ISelection getSelection() {
- return convertToJavaElementSelection(fSrcViewer.getSelection());
- }
-
- /*
- * @see org.eclipse.wst.jsdt.ui.actions.OpenAction#run(IStructuredSelection)
- */
- public void run(IStructuredSelection selection) {
- if (selection.isEmpty()) {
- getShell().getDisplay().beep();
- return;
- }
- super.run(selection);
- }
+ @Override
+ protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
+ pageRecord.page.dispose();
+ }
- /*
- * @see org.eclipse.wst.jsdt.ui.actions.OpenAction#run(Object[])
- */
- public void run(Object[] elements) {
- stopListeningForSelectionChanges();
- super.run(elements);
- startListeningForSelectionChanges();
- }
- };
+ @Override
+ protected IWorkbenchPart getBootstrapPart() {
+ return null;
}
- /**
- * Converts the given selection to a structured selection
- * containing Java elements.
- *
- * @param selection the selection
- * @return a structured selection with Java elements
- */
- private IStructuredSelection convertToJavaElementSelection(ISelection selection) {
- if (!(selection instanceof ITextSelection && fSelectedElement instanceof ISourceReference)) {
- return StructuredSelection.EMPTY;
+ @Override
+ protected boolean isImportant(IWorkbenchPart part) {
+ if (getToggleLockAction().isChecked()) {
+ return false;
}
-
- ITextSelection textSelection= (ITextSelection)selection;
- Object codeAssist= getJsFileElement(fSelectedElement);
-
- if (codeAssist instanceof ICodeAssist) {
- IJavaScriptElement[] elements= null;
- try {
- elements= ((ICodeAssist)codeAssist).codeSelect(textSelection.getOffset(), textSelection.getLength());
- elements = removeElementsWithNoContainingJSFile(elements);
- elements = removeDuplicateElements(elements);
- findDefaultElementAndSet(elements);
- } catch (JavaScriptModelException e) {
- return StructuredSelection.EMPTY;
- }
- if (elements != null && elements.length > 0) {
- return new StructuredSelection(elements[0]);
- } else {
- return StructuredSelection.EMPTY;
- }
+ if (part instanceof JavaEditor) {
+ return true;
+ } else if (part instanceof PageDesigner) {
+ return true;
+ } else {
+ return false;
}
-
- return StructuredSelection.EMPTY;
}
-
- /*
- * @see IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
- */
- public void menuAboutToShow(IMenuManager menu) {
- menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
- menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
-
- if (fOpenInputAction != null) {
- menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenInputAction);
- }
-
- //menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoInputAction);
- menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpen);
-
- if (fToggleLockAction != null) {
- menu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleLockAction);
+
+ @Override
+ protected void showPageRec(PageRec pageRec) {
+ if ((getToggleLockAction() != null) && (getToggleLockAction().isChecked())) {
+ return;
}
- if (fToggleLineNumberAction != null) {
- menu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleLineNumberAction);
- }
- }
-
- /**
- * Returns the input of this view.
- *
- * @return input the input object or <code>null</code> if not input is set
- */
- protected IJavaScriptElement getInput() {
- return fSelectedElement;
- }
-
- // Helper method
- ISelectionProvider getSelectionProvider() {
- return getViewSite().getSelectionProvider();
- }
-
- /**
- * Fills the actions bars.
- * <p>
- * Subclasses may extend.
- *
- * @param actionBars the action bars
- */
- protected void fillActionBars(IActionBars actionBars) {
+ super.showPageRec(pageRec);
- actionBars.setGlobalActionHandler(JdtActionConstants.OPEN, fOpen);
- fOpen.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR);
- }
-
-
- /**
- * The preference key for the background color.
- *
- * @return the background color key
- *
- */
- protected String getBackgroundColorKey() {
- return "org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView.backgroundColor"; //$NON-NLS-1$
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if (getBackgroundColorKey().equals(event.getProperty())) {
- inititalizeColors();
- }
- }
-
- /**
- * Start to listen for selection changes.
- */
- protected void startListeningForSelectionChanges() {
- getSite().getPage().addPostSelectionListener(this);
- }
-
- /**
- * Stop to listen for selection changes.
- */
- protected void stopListeningForSelectionChanges() {
- getSite().getPage().removePostSelectionListener(this);
+ if (pageRec.page instanceof DeclarationPage) {
+ ((DeclarationPage)(pageRec.page)).updateLineNumberRuler(getToggleLineNumberAction().isChecked());
+ }
}
- /*
- * @see ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
- */
+ @Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part.equals(this)) {
return;
}
-
- computeAndSetInput(part);
+ if (getCurrentPage() instanceof DeclarationPage) {
+ ((DeclarationPage) getCurrentPage()).computeAndSetInput(part);
+ }
}
-
- /**
- * Tries to get a JavaScript element out of the given element.
- *
- * @param element an object
- * @return the JavaScript element represented by the given element or <code>null</code>
- */
- private IJavaScriptElement findJavaScriptElement(Object element) {
- if (element == null) {
- return null;
- }
-
- IJavaScriptElement je= null;
- if (element instanceof IAdaptable) {
- je= (IJavaScriptElement)((IAdaptable)element).getAdapter(IJavaScriptElement.class);
- }
-
- return je;
- }
-
+
/*
* @see IWorkbenchPart#dispose()
*/
final public void dispose() {
- // cancel possible running computation
- fComputeCount++;
getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
-
- JFaceResources.getColorRegistry().removeListener(this);
- fBackgroundColorRGB= null;
- if (fBackgroundColor != null) {
- fBackgroundColor.dispose();
- fBackgroundColor= null;
- }
-
- internalDispose();
- }
-
- /*
- * @see IWorkbenchPart#dispose()
- */
- protected void internalDispose() {
- fSrcViewer= null;
- fComboViewer= null;
- fViewerConfiguration= null;
- JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
- JavaScriptPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
- }
-
- /**
- * Finds and returns the JavaScript element selected in the given part.
- * Returns null for non JavaScript context.
- * Returns empty array for no-declaration found case.
- * @param part the workbench part for which to find the selected Java element
- * @param selection the selection
- * @return the selected JavaScript element
- */
- protected IJavaScriptElement[] findSelectedJavaScriptElements(IWorkbenchPart part, ISelection selection) {
- Object element = null;
- try {
- if (part instanceof JavaEditor && selection instanceof ITextSelection) {
- return TextSelectionConverter.codeResolve((JavaEditor)part, (ITextSelection)selection);
- } else if (selection instanceof IStructuredSelection) {
- element = SelectionUtil.getSingleElement(selection);
- IJavaScriptElement e = findJavaScriptElement(element);
- if (e==null) {
- return null;
- } else {
- return new IJavaScriptElement[] {e};
- }
- } else {
- return null;
- }
- } catch (JavaScriptModelException e) {
- return null;
- }
+ super.dispose();
}
-
- /**
- * Determines all necessary details and delegates the computation into
- * a background thread.
- *
- * @param part the workbench part
- */
- private void computeAndSetInput(final IWorkbenchPart part) {
- if (isLocked()) {
- return;
- }
-
- final int currentCount= ++fComputeCount;
-
- ISelectionProvider provider= part.getSite().getSelectionProvider();
- if (provider == null) {
- return;
- }
-
- final ISelection selection= provider.getSelection();
- if (selection == null || selection.isEmpty()) {
- return;
- }
-
- Thread thread= new Thread("Advanced Declaration view input computer") { //$NON-NLS-1$
- public void run() {
- if (currentCount != fComputeCount) {
- return;
- }
-
- IJavaScriptElement[] elements= findSelectedJavaScriptElements(part, selection);
- elements = removeElementsWithNoContainingJSFile(elements);
- final IJavaScriptElement[] jsElements = removeDuplicateElements(elements);
- findDefaultElementAndSet(jsElements);
-
- Shell shell= getSite().getShell();
- if (shell.isDisposed()) {
- return;
- }
-
- Display display= shell.getDisplay();
- if (display.isDisposed()) {
- return;
- }
-
- setComboViewerInput(display, jsElements, currentCount);
-
- if (jsElements == null || jsElements.length <= 0) {
- setSrcViewerInput(display, null, currentCount);
- } else {
- setSrcViewerInput(display, jsElements[0], currentCount);
- }
- }
- };
-
- thread.setDaemon(true);
- thread.setPriority(Thread.MIN_PRIORITY);
- thread.start();
- }
-
- /**
- * Determines all necessary details and delegates the computation into
- * a background thread.
- *
- * @param part the workbench part
- */
- private void processComboViewerSelection(final IJavaScriptElement jsElement) {
- if (isLocked()) {
- return;
- }
-
- final int currentCount= ++fComputeCount;
-
- Thread thread= new Thread("Advanced Declaration view ComboViewer selection processing thread") { //$NON-NLS-1$
- public void run() {
- if (currentCount != fComputeCount) {
- return;
- }
-
- Shell shell= getSite().getShell();
- if (shell.isDisposed()) {
- return;
- }
-
- Display display= shell.getDisplay();
- if (display.isDisposed()) {
- return;
- }
-
- setSrcViewerInput (display, jsElement, currentCount);
- }
- };
-
- thread.setDaemon(true);
- thread.setPriority(Thread.MIN_PRIORITY);
- thread.start();
- }
-
- private void setSrcViewerInput (Display display, final IJavaScriptElement jsElement, final int currentCount) {
- display.asyncExec(new Runnable() {
- /*
- * @see java.lang.Runnable#run()
- */
- public void run() {
- if (fComputeCount != currentCount || getViewSite().getShell().isDisposed()) {
- return;
- }
- updateSrcViewer(jsElement);
- }
- });
- }
-
- private void setComboViewerInput (Display display, final IJavaScriptElement[] jsElements, final int currentCount) {
- display.asyncExec(new Runnable() {
- /*
- * @see java.lang.Runnable#run()
- */
- public void run() {
- if (fComputeCount != currentCount || getViewSite().getShell().isDisposed()) {
- return;
- }
-
- if (jsElements == null) {
- fElementInfoLabel.setText("Declaration View is not available.");
- updateComboViewer(new IJavaScriptElement[] {});
- } else if (jsElements.length > 0) {
- updateComboViewer(jsElements);
- } else {
- fElementInfoLabel.setText("No declaration found.");
- updateComboViewer(new IJavaScriptElement[] {});
- }
- }
- });
- }
-
- private void updateComboViewer(Object[] elements) {
- if (elements.length > 1) {
- fSrcViewer.getControl().setVisible(true);
- fComboViewer.getCombo().removeAll();
- fComboViewer.add(elements);
- fComboViewer.getCombo().select(0);
- fComboBoxLabel.setText(elements.length + " cases");
- fComboViewer.getCombo().setVisible(true);
- fComboBoxLabel.setVisible(true);
- updateLayout(LAYOUT_MULTIPLE_ELEMENTS);
- } else if (elements.length >= 1) {
- fSrcViewer.getControl().setVisible(true);
- fComboViewer.getCombo().setVisible(false);
- fComboBoxLabel.setVisible(false);
- updateLayout(LAYOUT_NORMAL);
- } else {
- fSrcViewer.getControl().setVisible(false);
- fComboViewer.getCombo().setVisible(false);
- fComboBoxLabel.setVisible(false);
- updateLayout(LAYOUT_NOTHING_TO_VIEW);
- }
- }
-
- private void updateSrcViewer(IJavaScriptElement selection) {
- fSelectedElement = selection;
- if (selection == null) {
- setInput(null);
- } else {
- Object src = getJsFileSource(selection);
- if (src == null) {
- setInput(null);
- } else {
- doSetInput(src);
- }
- }
- }
-
- private void doSetInput(Object input) {
- setInput(input);
- IJavaScriptElement inputElement= fSelectedElement;
- fElementInfoLabel.setText(getElementLabelString(inputElement));
-
- setTitleToolTip(JavaScriptElementLabels.getElementLabelExtend(inputElement, TOOLTIP_LABEL_FLAGS));
- }
-
- private String getElementLabelString(IJavaScriptElement element) {
- long flags;
- if (element instanceof ILocalVariable) {
- flags= LOCAL_VARIABLE_TITLE_FLAGS;
- } else {
- flags= TITLE_FLAGS;
- }
-
- String positionInfo = "";
- ISourceRange range = getSourceRange(element);
- if (range != null) {
- try {
- int lineOfOffset = fSrcViewer.getDocument().getLineOfOffset(range.getOffset()) + 1;
- positionInfo = " [line:" + lineOfOffset + "]";
- } catch (BadLocationException ex) {
- positionInfo = "";
- }
- }
- return JavaScriptElementLabels.getElementLabelExtend(element, flags) + "/" + getJsFileName(element) + positionInfo;
- }
-
- /**
- * Sets the font for this viewer sustaining selection and scroll position.
- */
- private void setViewerFont() {
- Font font= JFaceResources.getFont(SYMBOLIC_FONT_NAME);
-
- if (fSrcViewer.getDocument() != null) {
- Point selection= fSrcViewer.getSelectedRange();
- int topIndex= fSrcViewer.getTopIndex();
-
- StyledText styledText= fSrcViewer.getTextWidget();
- Control parent= fSrcViewer.getControl();
- parent.setRedraw(false);
- styledText.setFont(font);
- fSrcViewer.setSelectedRange(selection.x , selection.y);
- fSrcViewer.setTopIndex(topIndex);
-
- if (parent instanceof Composite) {
- Composite composite= (Composite) parent;
- composite.layout(true);
- }
- parent.setRedraw(true);
- } else {
- StyledText styledText= fSrcViewer.getTextWidget();
- styledText.setFont(font);
- }
- }
-
- private void updateLayout(int mode) {
- FormData formData;
- int margin = 3;
- if (mode == LAYOUT_MULTIPLE_ELEMENTS) {
- formData = new FormData();
- formData.left = new FormAttachment(0, margin);
- formData.right = new FormAttachment(70, -2 * margin);
- formData.top = new FormAttachment(0, margin);
- fComboViewer.getControl().setLayoutData(formData);
-
- formData = new FormData();
- formData.left = new FormAttachment(fComboViewer.getControl(), 2 * margin);
- formData.right = new FormAttachment(100, -margin);
- formData.top = new FormAttachment(0, margin);
- fComboBoxLabel.setLayoutData(formData);
-
- formData = new FormData();
- formData.left = new FormAttachment(0, margin);
- formData.right = new FormAttachment(100, -margin);
- formData.bottom = new FormAttachment(100, -margin);
- fElementInfoLabel.setLayoutData(formData);
-
- formData = new FormData();
- formData.left = new FormAttachment(0, margin);
- formData.right = new FormAttachment(100, -margin);
- formData.top = new FormAttachment(fComboViewer.getControl(), margin);
- formData.bottom = new FormAttachment(fElementInfoLabel, -margin);
- fSrcViewer.getControl().setLayoutData(formData);
- } else if (mode == LAYOUT_NORMAL) {
- formData = new FormData();
- formData.left = new FormAttachment(0, margin);
- formData.right = new FormAttachment(100, -margin);
- formData.bottom = new FormAttachment(100, -margin);
- fElementInfoLabel.setLayoutData(formData);
-
- formData = new FormData();
- formData.left = new FormAttachment(0, margin);
- formData.right = new FormAttachment(100, -margin);
- formData.top = new FormAttachment(0, margin);
- formData.bottom = new FormAttachment(fElementInfoLabel, -margin);
- fSrcViewer.getControl().setLayoutData(formData);
- } else if (mode == LAYOUT_NOTHING_TO_VIEW) {
- formData = new FormData();
- formData.top = new FormAttachment(0, margin);
- formData.left = new FormAttachment(0, margin);
- formData.right = new FormAttachment(100, -margin);
- fElementInfoLabel.setLayoutData(formData);
- }
- parentControl.layout();
- }
-
- /**
- * Updates the line number ruler.
- */
- private void updateLineNumberRuler()
- {
- if (fVerticalRuler !=null) {
- if(!fShowLineNumber){
- if(fLineNumberColumn!=null){
- fVerticalRuler.removeDecorator(fLineNumberColumn);
- }
- } else {
- if(fLineNumberColumn==null){
- fLineNumberColumn = new LineNumberRulerColumn();
- updateLineNumberColumnPresentation(false);
- }
- fVerticalRuler.addDecorator(0, fLineNumberColumn);
- }
- }
- }
-
- private void updateLineNumberColumnPresentation(boolean refresh) {
- if (fLineNumberColumn == null) {
- return;
- }
- RGB rgb= getColorFromStore(EditorsUI.getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR);
- if (rgb == null) {
- rgb= new RGB(0, 0, 0);
- }
- ISharedTextColors sharedColors= getSharedColors();
- fLineNumberColumn.setForeground(sharedColors.getColor(rgb));
- if (refresh) {
- fLineNumberColumn.redraw();
- }
- }
-
- private ISharedTextColors getSharedColors() {
- return EditorsUI.getSharedTextColors();
- }
-
- private RGB getColorFromStore(IPreferenceStore store, String key) {
- RGB rgb= null;
- if (store.contains(key)) {
- if (store.isDefault(key)) {
- rgb= PreferenceConverter.getDefaultColor(store, key);
- } else {
- rgb= PreferenceConverter.getColor(store, key);
- }
- }
- return rgb;
- }
-}
-
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Program Understanding / Advanced Declaration View for JavaScript
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyukmin Kwon <hyukmin0530@samsung.com>
+ * Jaeheung Kim <jaeheung.kim@samsung.com>
+ * Sujin Kim <sujin921.kim@samsung.com>
+ * Woongsik Choi <woongsik76.choi@samsung.com>
+ *
+ * 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:
+ * - S-Core Co., Ltd
+ *
+ *******************************************************************************/
+package org.tizen.web.advanceddeclarationview.ui;
+
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.Page;
+
+abstract public class DeclarationPage extends Page {
+
+ abstract public void updateLineNumberRuler(boolean showLineNumber);
+ abstract void computeAndSetInput(final IWorkbenchPart part);
+}
--- /dev/null
+/*******************************************************************************
+ * Program Understanding / Advanced Declaration View for JavaScript
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyukmin Kwon <hyukmin0530@samsung.com>
+ * Jaeheung Kim <jaeheung.kim@samsung.com>
+ * Sujin Kim <sujin921.kim@samsung.com>
+ * Woongsik Choi <woongsik76.choi@samsung.com>
+ *
+ * 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:
+ * - S-Core Co., Ltd
+ *
+ *******************************************************************************/
+package org.tizen.web.advanceddeclarationview.ui;
+
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.CompositeRuler;
+import org.eclipse.jface.text.source.ISharedTextColors;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.LineNumberRulerColumn;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
+import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
+import org.eclipse.wst.jsdt.internal.ui.util.SelectionUtil;
+import org.eclipse.wst.jsdt.ui.IContextMenuConstants;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.tizen.webuibuilder.editparts.DesignerEditPart;
+
+@SuppressWarnings("restriction")
+public class GUIBuilderDeclarationPage extends DeclarationPage implements ISelectionListener,
+IMenuListener, IPropertyChangeListener {
+ /** Symbolic Java editor font name. */
+ private static final String SYMBOLIC_FONT_NAME= "org.eclipse.wst.sse.ui.textfont"; //$NON-NLS-1$
+ private static final int LAYOUT_NORMAL = 0;
+ private static final int LAYOUT_NOTHING_TO_VIEW = 1;
+
+ /**
+ * The "parent" view site
+ */
+ private IViewSite parentSite;
+
+ /** Main composite control */
+ private Composite mainComposite;
+ /** This view's source viewer */
+ private SourceViewer fSrcViewer;
+ /** This view's combo viewer */
+
+ private TextSourceViewerConfiguration fViewerConfiguration;
+ /** This view's javascript element info label */
+ private Label fElementInfoLabel;
+ /** The viewer's vertical ruler */
+ private CompositeRuler fVerticalRuler;
+ /** The viewer's line number column */
+ private LineNumberRulerColumn fLineNumberColumn;
+ private boolean lineNumberColumnOn = false;
+
+ /** The viewer's font properties change listener. */
+ private IPropertyChangeListener fFontPropertyChangeListener= new FontPropertyChangeListener();
+
+ /**
+ * The editor's property change listener.
+ *
+ */
+ private IPropertyChangeListener fPropertyChangeListener= new PropertyChangeListener();
+
+ /** Counts the number of background computation requests. */
+ private volatile int fComputeCount;
+
+ /** Background color. */
+ private Color fBackgroundColor;
+ private RGB fBackgroundColorRGB;
+
+ /**
+ * Internal property change listener for handling changes in the editor's preferences.
+ */
+ class PropertyChangeListener implements IPropertyChangeListener {
+ /*
+ * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (fSrcViewer == null) {
+ return;
+ }
+
+ fSrcViewer.invalidateTextPresentation();
+
+ if (event.getProperty().equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR)) {
+ updateLineNumberColumnPresentation(true);
+ }
+ }
+ }
+
+ /**
+ * Internal property change listener for handling workbench font changes.
+ */
+ class FontPropertyChangeListener implements IPropertyChangeListener {
+ /*
+ * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (fSrcViewer == null) {
+ return;
+ }
+
+ String property= event.getProperty();
+
+ if (SYMBOLIC_FONT_NAME.equals(property)) {
+ setViewerFont();
+ }
+ }
+ }
+
+ private ToggleLockAction getToggleLockAction(){
+ return ((AdvancedDeclarationView)(parentSite.getPart())).getToggleLockAction();
+ }
+
+ private boolean isLocked () {
+ return getToggleLockAction().isChecked();
+ }
+
+ private ToggleLineNumberAction getToggleLineNumberAction(){
+ return ((AdvancedDeclarationView)(parentSite.getPart())).getToggleLineNumberAction();
+ }
+
+ /**
+ * Set the input of this view.
+ *
+ * @param input the input object
+ */
+ protected void setInput(String input) {
+ if (input == null) {
+ fSrcViewer.setInput(""); //$NON-NLS-1$
+ } else {
+ fSrcViewer.getDocument().set(input);
+ fSrcViewer.invalidateTextPresentation();
+ }
+ }
+
+ /**
+ * Set the view's foreground color.
+ *
+ * @param color the SWT color
+ */
+ protected void setForeground(Color color) {
+ fSrcViewer.getTextWidget().setForeground(color);
+ }
+
+ /**
+ * Set the view's background color.
+ *
+ * @param color the SWT color
+ */
+ protected void setBackground(Color color) {
+ fSrcViewer.getTextWidget().setBackground(color);
+ }
+
+ /**
+ * Create the part control.
+ *
+ * @param parent the parent control
+ * @see IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ protected void internalCreatePartControl(Composite parent) {
+ mainComposite = new Composite(parent, SWT.NULL);
+ mainComposite.setLayout(new FormLayout());
+
+ fElementInfoLabel = new Label(mainComposite, SWT.LEFT);
+ fElementInfoLabel.setText("");
+
+
+ fVerticalRuler = new CompositeRuler();
+ fViewerConfiguration = new StructuredTextViewerConfigurationHTML();
+ fSrcViewer = doCreateViewer(mainComposite, fVerticalRuler,fViewerConfiguration);
+ fSrcViewer.setEditable(false);
+
+ setViewerFont();
+ JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
+ EditorsUI.getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
+ getSite().setSelectionProvider(fSrcViewer);
+
+ updateLayout(LAYOUT_NOTHING_TO_VIEW);
+
+ updateLineNumberRuler(!lineNumberColumnOn);
+ }
+
+ SourceViewer doCreateViewer(Composite parent, IVerticalRuler verticalRuler, SourceViewerConfiguration viewerConfiguration) {
+ SourceViewer viewer = null;
+ String contentTypeID = ContentTypeIdForHTML.ContentTypeID_HTML;
+ viewer = new StructuredTextViewer(parent, verticalRuler, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ viewer.getTextWidget().setFont(JFaceResources.getFont(SYMBOLIC_FONT_NAME)); //$NON-NLS-1$
+ IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID);
+ IDocument document = scratchModel.getStructuredDocument();
+ viewer.configure(viewerConfiguration);
+ viewer.setDocument(document);
+ return viewer;
+ }
+
+ private void inititalizeColors() {
+ if (getSite().getShell().isDisposed()) {
+ return;
+ }
+
+ Display display= getSite().getShell().getDisplay();
+ if (display == null || display.isDisposed()) {
+ return;
+ }
+
+ setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
+
+ ColorRegistry registry= JFaceResources.getColorRegistry();
+ registry.addListener(this);
+
+ fBackgroundColorRGB= registry.getRGB(getBackgroundColorKey());
+ Color bgColor;
+ if (fBackgroundColorRGB == null) {
+ bgColor= display.getSystemColor(SWT.COLOR_WHITE);
+ fBackgroundColorRGB= bgColor.getRGB();
+ } else {
+ bgColor= new Color(display, fBackgroundColorRGB);
+ fBackgroundColor= bgColor;
+ }
+ setBackground(bgColor);
+ }
+
+ /**
+ * Creates the context menu for this view.
+ */
+ protected void createContextMenu() {
+ MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuManager.setRemoveAllWhenShown(true);
+ menuManager.addMenuListener(this);
+ Menu contextMenu= menuManager.createContextMenu(fSrcViewer.getTextWidget());
+ fSrcViewer.getTextWidget().setMenu(contextMenu);
+ getSite().registerContextMenu(parentSite.getPluginId() + ".guibuilder.contextmenu",
+ menuManager, getSite().getSelectionProvider());
+ }
+
+ /**
+ * Creates the actions and action groups for this view.
+ */
+ protected void createActions() {
+
+ }
+
+ /**
+ * The preference key for the background color.
+ *
+ * @return the background color key
+ *
+ */
+ protected String getBackgroundColorKey() {
+ return "org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView.backgroundColor"; //$NON-NLS-1$
+ }
+
+ /*
+ * @see IWorkbenchPart#dispose()
+ */
+ protected void internalDispose() {
+ fSrcViewer= null;
+ fViewerConfiguration= null;
+ JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
+ EditorsUI.getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
+ }
+
+ /**
+ * Determines all necessary details and delegates the computation into
+ * a background thread.
+ *
+ * @param part the workbench part
+ */
+ @Override
+ void computeAndSetInput(final IWorkbenchPart part) {
+ if (isLocked()) {
+ return;
+ }
+
+ final int currentCount= ++fComputeCount;
+
+ ISelectionProvider provider= part.getSite().getSelectionProvider();
+ if (provider == null) {
+ return;
+ }
+
+ final ISelection selection= provider.getSelection();
+ if (selection == null || selection.isEmpty()) {
+ return;
+ }
+
+ if (!(SelectionUtil.getSingleElement(selection) instanceof DesignerEditPart)) {
+ return;
+ }
+
+ Thread thread= new Thread("Advanced Declaration view input computer") { //$NON-NLS-1$
+ public void run() {
+ if (currentCount != fComputeCount) {
+ return;
+ }
+
+ processGUIBuilderInput((DesignerEditPart) SelectionUtil.getSingleElement(selection), currentCount);
+ }
+ };
+
+ thread.setDaemon(true);
+ thread.setPriority(Thread.MIN_PRIORITY);
+ thread.start();
+ }
+
+ private void processGUIBuilderInput(DesignerEditPart designerEditPart, int currentCount) {
+ Shell shell= getSite().getShell();
+ if (shell.isDisposed()) {
+ return;
+ }
+
+ Display display= shell.getDisplay();
+ if (display.isDisposed()) {
+ return;
+ }
+
+ setGUIBulderSrcViewerInput(display, designerEditPart.getCode(true),currentCount);
+ }
+
+ private void setGUIBulderSrcViewerInput (Display display, final String htmlSource, final int currentCount) {
+ display.asyncExec(new Runnable() {
+ /*
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ if (fComputeCount != currentCount || getSite().getShell().isDisposed()) {
+ return;
+ }
+ setInput(htmlSource);
+ updateLayout(LAYOUT_NORMAL);
+ }
+ });
+ }
+
+ /**
+ * Sets the font for this viewer sustaining selection and scroll position.
+ */
+ private void setViewerFont() {
+ Font font= JFaceResources.getFont(SYMBOLIC_FONT_NAME);
+
+ if (fSrcViewer.getDocument() != null) {
+ Point selection= fSrcViewer.getSelectedRange();
+ int topIndex= fSrcViewer.getTopIndex();
+
+ StyledText styledText= fSrcViewer.getTextWidget();
+ Control parent= fSrcViewer.getControl();
+ parent.setRedraw(false);
+ styledText.setFont(font);
+ fSrcViewer.setSelectedRange(selection.x , selection.y);
+ fSrcViewer.setTopIndex(topIndex);
+
+ if (parent instanceof Composite) {
+ Composite composite= (Composite) parent;
+ composite.layout(true);
+ }
+ parent.setRedraw(true);
+ } else {
+ StyledText styledText= fSrcViewer.getTextWidget();
+ styledText.setFont(font);
+ }
+ }
+
+ private void updateLayout(int mode) {
+ FormData formData;
+ int margin = 3;
+ if (mode == LAYOUT_NORMAL) {
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.bottom = new FormAttachment(100, -margin);
+ fElementInfoLabel.setLayoutData(formData);
+
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.top = new FormAttachment(0, margin);
+ formData.bottom = new FormAttachment(fElementInfoLabel, -margin);
+ fSrcViewer.getControl().setLayoutData(formData);
+ } else if (mode == LAYOUT_NOTHING_TO_VIEW) {
+ formData = new FormData();
+ formData.top = new FormAttachment(0, margin);
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ fElementInfoLabel.setLayoutData(formData);
+ }
+ mainComposite.layout();
+ }
+
+ /**
+ * Updates the line number ruler.
+ */
+ @Override
+ public void updateLineNumberRuler(boolean showLineNumber)
+ {
+ if (fVerticalRuler !=null) {
+ if (lineNumberColumnOn != showLineNumber) {
+ if(!showLineNumber){
+ if(fLineNumberColumn!=null){
+ fVerticalRuler.removeDecorator(fLineNumberColumn);
+ }
+ } else {
+ if(fLineNumberColumn==null){
+ fLineNumberColumn = new LineNumberRulerColumn();
+ updateLineNumberColumnPresentation(false);
+ }
+ fVerticalRuler.addDecorator(0, fLineNumberColumn);
+ }
+ lineNumberColumnOn = showLineNumber;
+ }
+ }
+ }
+
+ private void updateLineNumberColumnPresentation(boolean refresh) {
+ if (fLineNumberColumn == null) {
+ return;
+ }
+ RGB rgb= getColorFromStore(EditorsUI.getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR);
+ if (rgb == null) {
+ rgb= new RGB(0, 0, 0);
+ }
+ ISharedTextColors sharedColors= getSharedColors();
+ fLineNumberColumn.setForeground(sharedColors.getColor(rgb));
+ if (refresh) {
+ fLineNumberColumn.redraw();
+ }
+ }
+
+ private ISharedTextColors getSharedColors() {
+ return EditorsUI.getSharedTextColors();
+ }
+
+ private RGB getColorFromStore(IPreferenceStore store, String key) {
+ RGB rgb= null;
+ if (store.contains(key)) {
+ if (store.isDefault(key)) {
+ rgb= PreferenceConverter.getDefaultColor(store, key);
+ } else {
+ rgb= PreferenceConverter.getColor(store, key);
+ }
+ }
+ return rgb;
+ }
+
+ public GUIBuilderDeclarationPage(final IViewSite parentViewSite) {
+ parentSite = parentViewSite;
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (getBackgroundColorKey().equals(event.getProperty())) {
+ inititalizeColors();
+ }
+ }
+
+ /*
+ * @see IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
+ */
+ @Override
+ public void menuAboutToShow(IMenuManager manager) {
+ manager.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
+
+ manager.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, getToggleLockAction());
+ manager.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, getToggleLineNumberAction());
+ }
+
+ /*
+ * @see ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (part.equals(parentSite.getPart())) {
+ return;
+ }
+
+ computeAndSetInput(part);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ internalCreatePartControl(parent);
+ inititalizeColors();
+ createContextMenu();
+ createActions();
+ }
+
+ /**
+ * Returns the view's primary control.
+ *
+ * @return the primary control
+ */
+ @Override
+ public Control getControl() {
+ return mainComposite;
+ }
+
+ @Override
+ public void setFocus() {
+ mainComposite.setFocus();
+ }
+
+ /*
+ * @see IWorkbenchPart#dispose()
+ */
+ final public void dispose() {
+ // cancel possible running computation
+ fComputeCount++;
+
+ JFaceResources.getColorRegistry().removeListener(this);
+ fBackgroundColorRGB= null;
+ if (fBackgroundColor != null) {
+ fBackgroundColor.dispose();
+ fBackgroundColor= null;
+ }
+
+ internalDispose();
+ super.dispose();
+ }
+
+ @Override
+ public void setActionBars(IActionBars actionBars){
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Program Understanding / Advanced Declaration View for JavaScript
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyukmin Kwon <hyukmin0530@samsung.com>
+ * Jaeheung Kim <jaeheung.kim@samsung.com>
+ * Sujin Kim <sujin921.kim@samsung.com>
+ * Woongsik Choi <woongsik76.choi@samsung.com>
+ *
+ * The Original Code is JSDT's org.eclipse.wst.jsdt.internal.ui.infoviews package.
+ * The Initial developer or author of the Original Code is IBM Corporation and others.
+ * Samsung Electronics Co., Ltd. modifies it under the terms of Eclipse Public License v1.0
+ *
+ * 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:
+ * - S-Core Co., Ltd
+ *
+ *******************************************************************************/
+package org.tizen.web.advanceddeclarationview.ui;
+
+import org.eclipse.core.runtime.IAdaptable;
+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.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextPresentationListener;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.source.CompositeRuler;
+import org.eclipse.jface.text.source.ISharedTextColors;
+import org.eclipse.jface.text.source.LineNumberRulerColumn;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.wst.jsdt.core.ICodeAssist;
+import org.eclipse.wst.jsdt.core.IJavaScriptElement;
+import org.eclipse.wst.jsdt.core.ILocalVariable;
+import org.eclipse.wst.jsdt.core.IMember;
+import org.eclipse.wst.jsdt.core.ISourceRange;
+import org.eclipse.wst.jsdt.core.ISourceReference;
+import org.eclipse.wst.jsdt.core.JavaScriptModelException;
+import org.eclipse.wst.jsdt.internal.core.SourceType;
+import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds;
+import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
+import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaSourceViewer;
+import org.eclipse.wst.jsdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
+import org.eclipse.wst.jsdt.internal.ui.util.SelectionUtil;
+import org.eclipse.wst.jsdt.ui.IContextMenuConstants;
+import org.eclipse.wst.jsdt.ui.JavaScriptElementLabels;
+import org.eclipse.wst.jsdt.ui.actions.IJavaEditorActionDefinitionIds;
+import org.eclipse.wst.jsdt.ui.actions.JdtActionConstants;
+import org.eclipse.wst.jsdt.ui.actions.OpenAction;
+import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions;
+import org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration;
+
+@SuppressWarnings("restriction")
+public class JSDeclarationPage extends DeclarationPage implements ISelectionListener,
+ IMenuListener, IPropertyChangeListener {
+
+ /** Symbolic Java editor font name. */
+ private static final String SYMBOLIC_FONT_NAME= "org.eclipse.wst.jsdt.ui.editors.textfont"; //$NON-NLS-1$
+
+ /** JavaScriptElementLabels flags used for the title */
+ private final long TITLE_FLAGS= JavaScriptElementLabels.ALL_FULLY_QUALIFIED
+ | JavaScriptElementLabels.M_PRE_RETURNTYPE | JavaScriptElementLabels.M_PARAMETER_TYPES | JavaScriptElementLabels.M_PARAMETER_NAMES | JavaScriptElementLabels.M_EXCEPTIONS
+ | JavaScriptElementLabels.F_PRE_TYPE_SIGNATURE | JavaScriptElementLabels.M_PRE_TYPE_PARAMETERS | JavaScriptElementLabels.T_TYPE_PARAMETERS
+ | JavaScriptElementLabels.USE_RESOLVED
+ | JavaScriptElementLabels.APPEND_ROOT_PATH;
+ private final long LOCAL_VARIABLE_TITLE_FLAGS= TITLE_FLAGS & ~JavaScriptElementLabels.F_FULLY_QUALIFIED | JavaScriptElementLabels.F_POST_QUALIFIED;
+
+ private static final int LAYOUT_NORMAL = 0;
+ private static final int LAYOUT_MULTIPLE_ELEMENTS = 1;
+ private static final int LAYOUT_NOTHING_TO_VIEW = 2;
+
+ /**
+ * The "parent" view site
+ */
+ private IViewSite parentSite;
+
+ /** Main composite control */
+ private Composite mainComposite;
+ /** This view's source viewer */
+ private SourceViewer fSrcViewer;
+ /** This view's combo viewer */
+ private ComboViewer fComboViewer;
+ /** The viewers configuration */
+ private JavaScriptSourceViewerConfiguration fViewerConfiguration;
+ /** This view's javascript element info label */
+ private Label fElementInfoLabel;
+ /** This view's result info label */
+ private Label fComboBoxLabel;
+ /** The viewer's vertical ruler */
+ private CompositeRuler fVerticalRuler;
+ /** The viewer's line number column */
+ private LineNumberRulerColumn fLineNumberColumn;
+ private boolean lineNumberColumnOn = false;
+ /** The open input action action */
+ private OpenInputAction fOpenInputAction;
+
+ /** The viewer's font properties change listener. */
+ private IPropertyChangeListener fFontPropertyChangeListener= new FontPropertyChangeListener();
+ /** The current input. */
+ protected IJavaScriptElement fSelectedElement;
+
+ /**
+ * The editor's property change listener.
+ *
+ */
+ private IPropertyChangeListener fPropertyChangeListener= new PropertyChangeListener();
+ /** The open action */
+ private OpenAction fOpen;
+
+ /** Counts the number of background computation requests. */
+ private volatile int fComputeCount;
+
+ /** Background color. */
+ private Color fBackgroundColor;
+ private RGB fBackgroundColorRGB;
+ /**
+ * Internal property change listener for handling changes in the editor's preferences.
+ */
+ class PropertyChangeListener implements IPropertyChangeListener {
+ /*
+ * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (fSrcViewer == null) {
+ return;
+ }
+
+ if (fViewerConfiguration.affectsTextPresentation(event)) {
+ fViewerConfiguration.handlePropertyChangeEvent(event);
+ fSrcViewer.invalidateTextPresentation();
+ }
+ if (event.getProperty().equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR)) {
+ updateLineNumberColumnPresentation(true);
+ }
+ }
+ }
+
+ /**
+ * Internal property change listener for handling workbench font changes.
+ */
+ class FontPropertyChangeListener implements IPropertyChangeListener {
+ /*
+ * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (fSrcViewer == null) {
+ return;
+ }
+
+ String property= event.getProperty();
+
+ if (SYMBOLIC_FONT_NAME.equals(property)) {
+ setViewerFont();
+ }
+ }
+ }
+
+ private ToggleLineNumberAction getToggleLineNumberAction(){
+ return ((AdvancedDeclarationView)(parentSite.getPart())).getToggleLineNumberAction();
+ }
+
+ private ToggleLockAction getToggleLockAction(){
+ return ((AdvancedDeclarationView)(parentSite.getPart())).getToggleLockAction();
+ }
+
+ private boolean isLocked () {
+ return getToggleLockAction().isChecked();
+ }
+
+ private ISourceRange getSourceRange(IJavaScriptElement element) {
+ ISourceRange range = null;
+ if (element instanceof ISourceReference) {
+ try {
+ if (element instanceof ILocalVariable) {
+ range = ((ILocalVariable) element).getNameRange();
+ } else if (element instanceof IMember) {
+ range = ((IMember) element).getNameRange();
+ } else {
+ range = ((ISourceReference) element).getSourceRange();
+ }
+ } catch (JavaScriptModelException e) {
+ return null;
+ }
+ }
+ return range;
+ }
+
+ /**
+ * Remove elements with no JavaScript file which contains the element
+ * @param elements array to search
+ * @return elements array
+ */
+ private IJavaScriptElement[] removeElementsWithNoContainingJSFile(IJavaScriptElement[] elements) {
+ if (elements == null) {
+ return elements;
+ }
+
+ int count = elements.length;
+ for (int i = 0; i < elements.length; i++) {
+ if (elements[i] == null) {
+ count--;
+ continue;
+ }
+ if (getJsFileElement(elements[i]) == null) {
+ elements[i] = null;
+ count--;
+ }
+ }
+
+ IJavaScriptElement[] jsElements = new IJavaScriptElement[count];
+ for (int i = 0, j = 0; i < elements.length; i++) {
+ if (elements[i] != null) {
+ jsElements[j++] = elements[i];
+ }
+ }
+ return jsElements;
+ }
+
+ /**
+ * Brute force search to remove elements by comparing with SourceRanges.
+ * @param elements to search
+ * @return removed unnecessary elements
+ */
+ private IJavaScriptElement[] removeDuplicateElements(IJavaScriptElement[] elements) {
+ if (elements == null || elements.length <= 1) {
+ return elements;
+ }
+
+ int count = elements.length;
+ outerloop: for (int i = 0; i < elements.length; i++) {
+ if (elements[i] == null) {
+ continue;
+ }
+
+ IJavaScriptElement ifile = getJsFileElement(elements[i]);
+ ISourceRange irange = getSourceRange(elements[i]);
+ if (irange == null) {
+ continue;
+ }
+ int ioffset = irange.getOffset();
+ int ilength = irange.getLength();
+
+ for (int j = i + 1; j < elements.length; j++) {
+ if (elements[j] == null) {
+ continue;
+ }
+
+ IJavaScriptElement jfile = getJsFileElement(elements[j]);
+ ISourceRange jrange = getSourceRange(elements[j]);
+ if (jrange == null) {
+ continue;
+ }
+
+ int joffset = jrange.getOffset();
+ int jlength = jrange.getLength();
+
+ if (ifile == null || jfile == null || !ifile.equals(jfile) || ilength == jlength) {
+ continue;
+ }
+
+ // start comparing ranges to remove element
+ if (ioffset >= joffset && (ioffset + ilength <= joffset + jlength)) {
+ elements[j] = null;
+ count--;
+ } else if (ioffset <= joffset && (ioffset + ilength >= joffset + jlength)) {
+ elements[i] = null;
+ count--;
+ continue outerloop;
+ }
+ }
+ }
+
+ IJavaScriptElement[] jsElements = new IJavaScriptElement[count];
+ // copy all non null elements to jsElements
+ for (int i = 0, j = 0; i < elements.length; i++) {
+ if (elements[i] != null) {
+ jsElements[j++] = elements[i];
+ }
+ }
+
+ return jsElements;
+ }
+
+ /**
+ * Find default element and set it to elements[0]
+ * @param elements elements to search and set
+ */
+ private void findDefaultElementAndSet(IJavaScriptElement[] elements) {
+ if(elements == null)
+ return;
+ for (int index = 0; index < elements.length; index++) {
+ if(!(elements[index] instanceof SourceType)) {
+ // set default element to elements[0]
+ IJavaScriptElement element = elements[0];
+ elements[0] = elements[index];
+ elements[index] = element;
+ }
+ }
+ }
+
+ /**
+ * Text presentation listeners for handling background color.
+ * @author sujin
+ */
+ private class DeclarationVieweTextPresenter implements ITextPresentationListener {
+ @Override
+ public void applyTextPresentation(TextPresentation textPresentation) {
+ highlightDeclaration(textPresentation);
+ }
+ private void highlightDeclaration(TextPresentation textPresentation) {
+
+ //Highlight and scroll to the declaration.
+ ISourceRange range = getSourceRange(fSelectedElement);
+ if(range != null) {
+ Display disp = fSrcViewer.getControl().getDisplay();
+ StyleRange styleRange = new StyleRange();
+ styleRange.start = range.getOffset();
+ styleRange.length = range.getLength();
+ styleRange.background = new Color(disp, new RGB(185,211,238));
+
+ fSrcViewer.setRangeIndication(range.getOffset(), range.getLength(), true);
+ textPresentation.mergeStyleRange(styleRange);
+ }
+ }
+ }
+
+ /**
+ * Set the input of this view.
+ *
+ * @param input the input object
+ */
+ protected void setInput(Object input) {
+ if (input instanceof IDocument) {
+ fSrcViewer.setInput(input);
+ } else if (input == null) {
+ fSrcViewer.setInput(new Document("")); //$NON-NLS-1$
+ } else {
+ IDocument document= new Document(input.toString());
+ JavaScriptPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING);
+ fSrcViewer.setInput(document);
+ }
+
+ if (input != null) {
+ fSrcViewer.invalidateTextPresentation();
+ }
+ }
+
+ /**
+ * Computes the input for this view based on the given element.
+ *
+ * @param element the element from which to compute the input
+ * @return the input or <code>null</code> if the input was not computed successfully
+ */
+ protected Object getJsFileSource(Object input) {
+ if (!(input instanceof IJavaScriptElement)) {
+ return null;
+ }
+
+ IJavaScriptElement inputFile = getJsFileElement(((IJavaScriptElement)input));
+
+ if (inputFile == null) {
+ return null;
+ }
+
+ if (fSrcViewer == null || !(inputFile instanceof ISourceReference)) {
+ return null;
+ }
+
+ ISourceReference sourceRef= (ISourceReference)inputFile;
+
+ String source;
+ try {
+ source= sourceRef.getSource();
+ } catch (JavaScriptModelException ex) {
+ return ""; //$NON-NLS-1$
+ }
+
+ if (source == null) {
+ return ""; //$NON-NLS-1$
+ }
+
+ return source;
+ }
+
+ /**
+ * Find the name of the JavaScript file containing the given JavaScript element.
+ *
+ * @param element JavaScript element
+ * @return the file name String or "" if the containing JavaScript file can not be found.
+ */
+ protected String getJsFileName(IJavaScriptElement element) {
+ IJavaScriptElement file = getJsFileElement(element);
+ if (file == null) {
+ return "";
+ } else {
+ return file.getElementName();
+ }
+ }
+
+ /**
+ * Find the JavaScript element for file containing the given JavaScript element.
+ *
+ * @param element JavaScript element
+ * @return the file JavaScript element or <code>null</code> if the containing JavaScript file can not be found.
+ */
+ protected IJavaScriptElement getJsFileElement(IJavaScriptElement element) {
+ IJavaScriptElement file = element.getAncestor(IJavaScriptElement.JAVASCRIPT_UNIT);
+ if (file == null) {
+ file = element.getAncestor(IJavaScriptElement.CLASS_FILE);
+ }
+
+ return file;
+ }
+
+ /**
+ * Set the view's foreground color.
+ *
+ * @param color the SWT color
+ */
+ protected void setForeground(Color color) {
+ fSrcViewer.getTextWidget().setForeground(color);
+ }
+
+ /**
+ * Set the view's background color.
+ *
+ * @param color the SWT color
+ */
+ protected void setBackground(Color color) {
+ fSrcViewer.getTextWidget().setBackground(color);
+ }
+
+
+ /**
+ * Returns the context ID for the Help system
+ *
+ * @return the string used as ID for the Help context
+ *
+ */
+ protected String getHelpContextId() {
+ return IJavaHelpContextIds.SOURCE_VIEW;
+ }
+
+ /**
+ * Create the part control.
+ *
+ * @param parent the parent control
+ * @see IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ protected void internalCreatePartControl(Composite parent) {
+ mainComposite = new Composite(parent, SWT.NULL);
+ mainComposite.setLayout(new FormLayout());
+
+ IPreferenceStore store= JavaScriptPlugin.getDefault().getCombinedPreferenceStore();
+ fComboViewer = new ComboViewer(mainComposite, SWT.READ_ONLY);
+ fComboViewer.setLabelProvider(new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IJavaScriptElement) {
+ IJavaScriptElement jsElement = (IJavaScriptElement)element;
+ return getElementLabelString(jsElement);
+ } else {
+ return super.getText(element);
+ }
+ }
+ });
+ fComboViewer.setContentProvider(new ArrayContentProvider());
+ fComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection = event.getSelection();
+ if (!(selection instanceof StructuredSelection)) {
+ return;
+ }
+
+ Object selectedObject = ((StructuredSelection)selection).getFirstElement();
+ if (!(selectedObject instanceof IJavaScriptElement)) {
+ return;
+ }
+
+ IJavaScriptElement selectedElement = (IJavaScriptElement)selectedObject;
+ processComboViewerSelection(selectedElement);
+ }
+ });
+
+ fElementInfoLabel = new Label(mainComposite, SWT.LEFT);
+ fElementInfoLabel.setText("");
+
+ fComboBoxLabel = new Label(mainComposite, SWT.LEFT);
+ fComboBoxLabel.setText("");
+
+ fVerticalRuler = new CompositeRuler();
+ fSrcViewer = new JavaSourceViewer(mainComposite, fVerticalRuler, null, false, SWT.V_SCROLL | SWT.H_SCROLL, store);
+ fViewerConfiguration= new SimpleJavaSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, IJavaScriptPartitions.JAVA_PARTITIONING, false);
+ fSrcViewer.configure(fViewerConfiguration);
+ fSrcViewer.setEditable(false);
+ ITextPresentationListener textPresenter = new DeclarationVieweTextPresenter();
+ fSrcViewer.addTextPresentationListener(textPresenter);
+ setViewerFont();
+ JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
+ store.addPropertyChangeListener(fPropertyChangeListener);
+ getSite().setSelectionProvider(fSrcViewer);
+
+ updateLayout(LAYOUT_NOTHING_TO_VIEW);
+
+ updateLineNumberRuler(!lineNumberColumnOn);
+ }
+
+
+ private void inititalizeColors() {
+ if (getSite().getShell().isDisposed()) {
+ return;
+ }
+
+ Display display= getSite().getShell().getDisplay();
+ if (display == null || display.isDisposed()) {
+ return;
+ }
+
+ setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
+
+ ColorRegistry registry= JFaceResources.getColorRegistry();
+ registry.addListener(this);
+
+ fBackgroundColorRGB= registry.getRGB(getBackgroundColorKey());
+ Color bgColor;
+ if (fBackgroundColorRGB == null) {
+ bgColor= display.getSystemColor(SWT.COLOR_WHITE);
+ fBackgroundColorRGB= bgColor.getRGB();
+ } else {
+ bgColor= new Color(display, fBackgroundColorRGB);
+ fBackgroundColor= bgColor;
+ }
+ setBackground(bgColor);
+ }
+
+ /**
+ * Creates the context menu for this view.
+ */
+ protected void createContextMenu() {
+ MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuManager.setRemoveAllWhenShown(true);
+ menuManager.addMenuListener(this);
+ Menu contextMenu= menuManager.createContextMenu(fSrcViewer.getTextWidget());
+ fSrcViewer.getTextWidget().setMenu(contextMenu);
+ getSite().registerContextMenu(parentSite.getPluginId() + ".javascript.contextmenu", menuManager, getSelectionProvider());
+ }
+
+ /**
+ * Creates the actions and action groups for this view.
+ */
+ protected void createActions() {
+
+ // Setup OpenAction
+ fOpen= new OpenAction(getSite()) {
+ /*
+ * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#getSelection()
+ */
+ public ISelection getSelection() {
+ return convertToJavaElementSelection(fSrcViewer.getSelection());
+ }
+
+ /*
+ * @see org.eclipse.wst.jsdt.ui.actions.OpenAction#run(IStructuredSelection)
+ */
+ public void run(IStructuredSelection selection) {
+ if (selection.isEmpty()) {
+ getShell().getDisplay().beep();
+ return;
+ }
+ super.run(selection);
+ }
+
+ /*
+ * @see org.eclipse.wst.jsdt.ui.actions.OpenAction#run(Object[])
+ */
+ public void run(Object[] elements) {
+ ((AdvancedDeclarationView)(parentSite.getPart())).stopListeningForSelectionChanges();
+ super.run(elements);
+ ((AdvancedDeclarationView)(parentSite.getPart())).startListeningForSelectionChanges();
+ }
+ };
+
+ fOpenInputAction = new OpenInputAction(this);
+ }
+
+ /**
+ * Converts the given selection to a structured selection
+ * containing Java elements.
+ *
+ * @param selection the selection
+ * @return a structured selection with Java elements
+ */
+ private IStructuredSelection convertToJavaElementSelection(ISelection selection) {
+ if (!(selection instanceof ITextSelection && fSelectedElement instanceof ISourceReference)) {
+ return StructuredSelection.EMPTY;
+ }
+
+ ITextSelection textSelection= (ITextSelection)selection;
+ Object codeAssist= getJsFileElement(fSelectedElement);
+
+ if (codeAssist instanceof ICodeAssist) {
+ IJavaScriptElement[] elements= null;
+ try {
+ elements= ((ICodeAssist)codeAssist).codeSelect(textSelection.getOffset(), textSelection.getLength());
+ elements = removeElementsWithNoContainingJSFile(elements);
+ elements = removeDuplicateElements(elements);
+ findDefaultElementAndSet(elements);
+ } catch (JavaScriptModelException e) {
+ return StructuredSelection.EMPTY;
+ }
+ if (elements != null && elements.length > 0) {
+ return new StructuredSelection(elements[0]);
+ } else {
+ return StructuredSelection.EMPTY;
+ }
+ }
+
+ return StructuredSelection.EMPTY;
+ }
+
+ /**
+ * Returns the input of this view.
+ *
+ * @return input the input object or <code>null</code> if not input is set
+ */
+ protected IJavaScriptElement getInput() {
+ return fSelectedElement;
+ }
+
+ // Helper method
+ ISelectionProvider getSelectionProvider() {
+ return getSite().getSelectionProvider();
+ }
+
+
+
+ /**
+ * The preference key for the background color.
+ *
+ * @return the background color key
+ *
+ */
+ protected String getBackgroundColorKey() {
+ return "org.tizen.web.advanceddeclarationview.ui.AdvancedDeclarationView.backgroundColor"; //$NON-NLS-1$
+ }
+
+
+ /**
+ * Tries to get a JavaScript element out of the given element.
+ *
+ * @param element an object
+ * @return the JavaScript element represented by the given element or <code>null</code>
+ */
+ private IJavaScriptElement findJavaScriptElement(Object element) {
+ if (element == null) {
+ return null;
+ }
+
+ IJavaScriptElement je= null;
+ if (element instanceof IAdaptable) {
+ je= (IJavaScriptElement)((IAdaptable)element).getAdapter(IJavaScriptElement.class);
+ }
+
+ return je;
+ }
+
+ /*
+ * @see IWorkbenchPart#dispose()
+ */
+ protected void internalDispose() {
+ fSrcViewer= null;
+ fComboViewer= null;
+ fViewerConfiguration= null;
+ JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
+ JavaScriptPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
+ }
+
+
+ /**
+ * Finds and returns the JavaScript element selected in the given part.
+ * Returns null for non JavaScript context.
+ * Returns empty array for no-declaration found case.
+ * @param part the workbench part for which to find the selected Java element
+ * @param selection the selection
+ * @return the selected JavaScript element
+ */
+ protected IJavaScriptElement[] findSelectedJavaScriptElements(IWorkbenchPart part, ISelection selection) {
+ Object element = null;
+ try {
+ if (part instanceof JavaEditor && selection instanceof ITextSelection) {
+ return TextSelectionConverter.codeResolve((JavaEditor)part, (ITextSelection)selection);
+ } else if (selection instanceof IStructuredSelection) {
+ element = SelectionUtil.getSingleElement(selection);
+ IJavaScriptElement e = findJavaScriptElement(element);
+ if (e==null) {
+ return null;
+ } else {
+ return new IJavaScriptElement[] {e};
+ }
+ } else {
+ return null;
+ }
+ } catch (JavaScriptModelException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Determines all necessary details and delegates the computation into
+ * a background thread.
+ *
+ * @param part the workbench part
+ */
+ @Override
+ void computeAndSetInput(final IWorkbenchPart part) {
+ if (isLocked()) {
+ return;
+ }
+
+ final int currentCount= ++fComputeCount;
+
+ ISelectionProvider provider= part.getSite().getSelectionProvider();
+ if (provider == null) {
+ return;
+ }
+
+ final ISelection selection= provider.getSelection();
+ if (selection == null || selection.isEmpty()) {
+ return;
+ }
+
+ Thread thread= new Thread("Advanced Declaration view input computer") { //$NON-NLS-1$
+ public void run() {
+ if (currentCount != fComputeCount) {
+ return;
+ }
+
+ IJavaScriptElement[] elements= findSelectedJavaScriptElements(part, selection);
+ elements = removeElementsWithNoContainingJSFile(elements);
+ final IJavaScriptElement[] jsElements = removeDuplicateElements(elements);
+ findDefaultElementAndSet(jsElements);
+
+ Shell shell= getSite().getShell();
+ if (shell.isDisposed()) {
+ return;
+ }
+
+ Display display= shell.getDisplay();
+ if (display.isDisposed()) {
+ return;
+ }
+
+ setComboViewerInput(display, jsElements, currentCount);
+
+ if (jsElements == null || jsElements.length <= 0) {
+ setSrcViewerInput(display, null, currentCount);
+ } else {
+ setSrcViewerInput(display, jsElements[0], currentCount);
+ }
+ }
+ };
+
+ thread.setDaemon(true);
+ thread.setPriority(Thread.MIN_PRIORITY);
+ thread.start();
+ }
+
+ /**
+ * Determines all necessary details and delegates the computation into
+ * a background thread.
+ *
+ * @param part the workbench part
+ */
+ private void processComboViewerSelection(final IJavaScriptElement jsElement) {
+ if (isLocked()) {
+ return;
+ }
+
+ final int currentCount= ++fComputeCount;
+
+ Thread thread= new Thread("Advanced Declaration view ComboViewer selection processing thread") { //$NON-NLS-1$
+ public void run() {
+ if (currentCount != fComputeCount) {
+ return;
+ }
+
+ Shell shell= getSite().getShell();
+ if (shell.isDisposed()) {
+ return;
+ }
+
+ Display display= shell.getDisplay();
+ if (display.isDisposed()) {
+ return;
+ }
+
+ setSrcViewerInput (display, jsElement, currentCount);
+ }
+ };
+
+ thread.setDaemon(true);
+ thread.setPriority(Thread.MIN_PRIORITY);
+ thread.start();
+ }
+
+ private void setSrcViewerInput (Display display, final IJavaScriptElement jsElement, final int currentCount) {
+ display.asyncExec(new Runnable() {
+ /*
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ if (fComputeCount != currentCount || getSite().getShell().isDisposed()) {
+ return;
+ }
+ updateSrcViewer(jsElement);
+ }
+ });
+ }
+
+ private void setComboViewerInput (Display display, final IJavaScriptElement[] jsElements, final int currentCount) {
+ display.asyncExec(new Runnable() {
+ /*
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ if (fComputeCount != currentCount || getSite().getShell().isDisposed()) {
+ return;
+ }
+
+ if (jsElements == null) {
+ fElementInfoLabel.setText("Declaration View is not available.");
+ updateComboViewer(new IJavaScriptElement[] {});
+ } else if (jsElements.length > 0) {
+ updateComboViewer(jsElements);
+ } else {
+ fElementInfoLabel.setText("No declaration found.");
+ updateComboViewer(new IJavaScriptElement[] {});
+ }
+ }
+ });
+ }
+
+ private void updateComboViewer(Object[] elements) {
+ if (elements.length > 1) {
+ fSrcViewer.getControl().setVisible(true);
+ fComboViewer.getCombo().removeAll();
+ fComboViewer.add(elements);
+ fComboViewer.getCombo().select(0);
+ fComboBoxLabel.setText(elements.length + " cases");
+ fComboViewer.getCombo().setVisible(true);
+ fComboBoxLabel.setVisible(true);
+ updateLayout(LAYOUT_MULTIPLE_ELEMENTS);
+ } else if (elements.length >= 1) {
+ fSrcViewer.getControl().setVisible(true);
+ fComboViewer.getCombo().setVisible(false);
+ fComboBoxLabel.setVisible(false);
+ updateLayout(LAYOUT_NORMAL);
+ } else {
+ fSrcViewer.getControl().setVisible(false);
+ fComboViewer.getCombo().setVisible(false);
+ fComboBoxLabel.setVisible(false);
+ updateLayout(LAYOUT_NOTHING_TO_VIEW);
+ }
+ }
+
+ private void updateSrcViewer(IJavaScriptElement selection) {
+ fSelectedElement = selection;
+ if (selection == null) {
+ setInput(null);
+ } else {
+ Object src = getJsFileSource(selection);
+ if (src == null) {
+ setInput(null);
+ } else {
+ doSetInput(src);
+ }
+ }
+ }
+
+ private void doSetInput(Object input) {
+ setInput(input);
+ IJavaScriptElement inputElement= fSelectedElement;
+ fElementInfoLabel.setText(getElementLabelString(inputElement));
+
+ //setTitleToolTip(JavaScriptElementLabels.getElementLabelExtend(inputElement, TOOLTIP_LABEL_FLAGS));
+ }
+
+ private String getElementLabelString(IJavaScriptElement element) {
+ long flags;
+ if (element instanceof ILocalVariable) {
+ flags= LOCAL_VARIABLE_TITLE_FLAGS;
+ } else {
+ flags= TITLE_FLAGS;
+ }
+
+ String positionInfo = "";
+ ISourceRange range = getSourceRange(element);
+ if (range != null) {
+ try {
+ int lineOfOffset = fSrcViewer.getDocument().getLineOfOffset(range.getOffset()) + 1;
+ positionInfo = " [line:" + lineOfOffset + "]";
+ } catch (BadLocationException ex) {
+ positionInfo = "";
+ }
+ }
+ return JavaScriptElementLabels.getElementLabelExtend(element, flags) + "/" + getJsFileName(element) + positionInfo;
+ }
+
+ /**
+ * Sets the font for this viewer sustaining selection and scroll position.
+ */
+ private void setViewerFont() {
+ Font font= JFaceResources.getFont(SYMBOLIC_FONT_NAME);
+
+ if (fSrcViewer.getDocument() != null) {
+ Point selection= fSrcViewer.getSelectedRange();
+ int topIndex= fSrcViewer.getTopIndex();
+
+ StyledText styledText= fSrcViewer.getTextWidget();
+ Control parent= fSrcViewer.getControl();
+ parent.setRedraw(false);
+ styledText.setFont(font);
+ fSrcViewer.setSelectedRange(selection.x , selection.y);
+ fSrcViewer.setTopIndex(topIndex);
+
+ if (parent instanceof Composite) {
+ Composite composite= (Composite) parent;
+ composite.layout(true);
+ }
+ parent.setRedraw(true);
+ } else {
+ StyledText styledText= fSrcViewer.getTextWidget();
+ styledText.setFont(font);
+ }
+ }
+
+ private void updateLayout(int mode) {
+ FormData formData;
+ int margin = 3;
+ if (mode == LAYOUT_MULTIPLE_ELEMENTS) {
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(70, -2 * margin);
+ formData.top = new FormAttachment(0, margin);
+ fComboViewer.getControl().setLayoutData(formData);
+
+ formData = new FormData();
+ formData.left = new FormAttachment(fComboViewer.getControl(), 2 * margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.top = new FormAttachment(0, margin);
+ fComboBoxLabel.setLayoutData(formData);
+
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.bottom = new FormAttachment(100, -margin);
+ fElementInfoLabel.setLayoutData(formData);
+
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.top = new FormAttachment(fComboViewer.getControl(), margin);
+ formData.bottom = new FormAttachment(fElementInfoLabel, -margin);
+ fSrcViewer.getControl().setLayoutData(formData);
+ } else if (mode == LAYOUT_NORMAL) {
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.bottom = new FormAttachment(100, -margin);
+ fElementInfoLabel.setLayoutData(formData);
+
+ formData = new FormData();
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ formData.top = new FormAttachment(0, margin);
+ formData.bottom = new FormAttachment(fElementInfoLabel, -margin);
+ fSrcViewer.getControl().setLayoutData(formData);
+ } else if (mode == LAYOUT_NOTHING_TO_VIEW) {
+ formData = new FormData();
+ formData.top = new FormAttachment(0, margin);
+ formData.left = new FormAttachment(0, margin);
+ formData.right = new FormAttachment(100, -margin);
+ fElementInfoLabel.setLayoutData(formData);
+ }
+ mainComposite.layout();
+ }
+
+ /**
+ * Updates the line number ruler.
+ */
+ @Override
+ public void updateLineNumberRuler(boolean showLineNumber)
+ {
+ if (fVerticalRuler !=null) {
+ if (lineNumberColumnOn != showLineNumber) {
+ if(!showLineNumber){
+ if(fLineNumberColumn!=null){
+ fVerticalRuler.removeDecorator(fLineNumberColumn);
+ }
+ } else {
+ if(fLineNumberColumn==null){
+ fLineNumberColumn = new LineNumberRulerColumn();
+ updateLineNumberColumnPresentation(false);
+ }
+ fVerticalRuler.addDecorator(0, fLineNumberColumn);
+ }
+ lineNumberColumnOn = showLineNumber;
+ }
+ }
+ }
+
+ private void updateLineNumberColumnPresentation(boolean refresh) {
+ if (fLineNumberColumn == null) {
+ return;
+ }
+ RGB rgb= getColorFromStore(EditorsUI.getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR);
+ if (rgb == null) {
+ rgb= new RGB(0, 0, 0);
+ }
+ ISharedTextColors sharedColors= getSharedColors();
+ fLineNumberColumn.setForeground(sharedColors.getColor(rgb));
+ if (refresh) {
+ fLineNumberColumn.redraw();
+ }
+ }
+
+ private ISharedTextColors getSharedColors() {
+ return EditorsUI.getSharedTextColors();
+ }
+
+ private RGB getColorFromStore(IPreferenceStore store, String key) {
+ RGB rgb= null;
+ if (store.contains(key)) {
+ if (store.isDefault(key)) {
+ rgb= PreferenceConverter.getDefaultColor(store, key);
+ } else {
+ rgb= PreferenceConverter.getColor(store, key);
+ }
+ }
+ return rgb;
+ }
+
+ /** New stubs that must be implemented.*/
+ public JSDeclarationPage(final IViewSite parentViewSite) {
+ parentSite = parentViewSite;
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (getBackgroundColorKey().equals(event.getProperty())) {
+ inititalizeColors();
+ }
+ }
+
+ /*
+ * @see IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
+ */
+ @Override
+ public void menuAboutToShow(IMenuManager manager) {
+ manager.add(new Separator(IContextMenuConstants.GROUP_OPEN));
+ manager.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
+
+ manager.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenInputAction);
+ manager.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpen);
+ manager.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, getToggleLockAction());
+ manager.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, getToggleLineNumberAction());
+ }
+ /*
+ * @see ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (part.equals(parentSite.getPart())) {
+ return;
+ }
+
+ computeAndSetInput(part);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ internalCreatePartControl(parent);
+ inititalizeColors();
+ createContextMenu();
+ createActions();
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpContextId());
+ }
+
+ /**
+ * Returns the view's primary control.
+ *
+ * @return the primary control
+ */
+ @Override
+ public Control getControl() {
+ return mainComposite;
+ }
+
+ @Override
+ public void setFocus() {
+ mainComposite.setFocus();
+ }
+
+ /*
+ * @see IWorkbenchPart#dispose()
+ */
+ final public void dispose() {
+ // cancel possible running computation
+ fComputeCount++;
+
+ JFaceResources.getColorRegistry().removeListener(this);
+ fBackgroundColorRGB= null;
+ if (fBackgroundColor != null) {
+ fBackgroundColor.dispose();
+ fBackgroundColor= null;
+ }
+
+ internalDispose();
+ super.dispose();
+ }
+ @Override
+ public void setActionBars(IActionBars actionBars){
+ actionBars.setGlobalActionHandler(JdtActionConstants.OPEN, fOpen);
+ fOpen.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR);
+
+ IToolBarManager toolBarManager= actionBars.getToolBarManager();
+ toolBarManager.add(fOpenInputAction);
+ }
+}
*******************************************************************************/
package org.tizen.web.advanceddeclarationview.ui;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
+import org.eclipse.jface.action.Action;
import org.eclipse.wst.jsdt.core.IJavaScriptElement;
import org.eclipse.wst.jsdt.ui.actions.OpenAction;
+import org.tizen.web.advanceddeclarationview.Activator;
-public class OpenInputActionDelegate implements IViewActionDelegate {
- private AdvancedDeclarationView targetPart;
+public class OpenInputAction extends Action {
- @Override
- public void run(IAction action) {
- IJavaScriptElement inputElement= targetPart.getInput();
- if (inputElement != null) {
- new OpenAction(targetPart.getViewSite()).run(new Object[] { inputElement });
- }
- }
-
- @Override
- public void selectionChanged(IAction action, ISelection selection) {
- // TODO Auto-generated method stub
- targetPart.setOpenInputAction(action);
+ private JSDeclarationPage page;
+
+ public OpenInputAction(JSDeclarationPage pageSite) {
+ super();
+ this.page = pageSite;
+ setDescription("Open Input");
+ setToolTipText("Open Input");
+ setText("Open Input");
+ setImageDescriptor(Activator.getImageDescriptor("icons/declaration_view_open.png"));
}
@Override
- public void init(IViewPart view) {
- targetPart = (AdvancedDeclarationView)view;
-
+ public void run() {
+ IJavaScriptElement inputElement= page.getInput();
+ if (inputElement != null) {
+ new OpenAction(page.getSite()).run(new Object[] { inputElement });
+ }
}
-
}
*
*
*/
+@SuppressWarnings("restriction")
class TextSelectionConverter {
/** Empty result. */
* - S-Core Co., Ltd
*
*******************************************************************************/
-
package org.tizen.web.advanceddeclarationview.ui;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.part.PageBookView;
-public class ToggleLineNumberActionDelegate implements IViewActionDelegate {
- private AdvancedDeclarationView targetPart;
- @Override
- public void run(IAction action) {
- targetPart.setLineNumberStatus(!targetPart.getLineNumberStatus());
- }
+public class ToggleLineNumberAction extends Action {
+
+ private PageBookView pageBookView;
- @Override
- public void selectionChanged(IAction action, ISelection selection) {
- targetPart.setToggleLineNumberAction(action);
+ public ToggleLineNumberAction(PageBookView pageBookView) {
+ super();
+ this.pageBookView = pageBookView;
+ setChecked(true);
+ setDescription("Show Line Number");
+ setToolTipText("Show Line Number");
+ setText("Show Line Number");
}
-
@Override
- public void init(IViewPart view) {
- targetPart = (AdvancedDeclarationView)view;
+ public void run() {
+ if (pageBookView.getCurrentPage() instanceof DeclarationPage) {
+ ((DeclarationPage) pageBookView.getCurrentPage()).updateLineNumberRuler(isChecked());
+ }
}
-
}
* - S-Core Co., Ltd
*
*******************************************************************************/
-
package org.tizen.web.advanceddeclarationview.ui;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.action.IAction;
-
-/**
- * Lock Advanced Declaration View command handler.
- */
-public class ViewHandler extends AbstractHandler {
+import org.eclipse.jface.action.Action;
+import org.tizen.web.advanceddeclarationview.Activator;
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- String identifier = event.getCommand().getId();
- if (identifier.equals("org.tizen.web.advanceddeclarationview.ui.LockView")) {
- ToggleLockActionDelegate lockAction = ToggleLockActionDelegate.getDefault();
- IAction action = lockAction.getTarget().getLockAction();
+public class ToggleLockAction extends Action {
- action.setChecked(!lockAction.getTarget().isLocked());
- lockAction.run(action);
- }
- return null;
+ public ToggleLockAction() {
+ super();
+ setChecked(false);
+ setDescription("Lock (Alt+L)");
+ setToolTipText("Lock View (Alt+L)");
+ setText("Lock View");
+ setImageDescriptor (Activator.getImageDescriptor("icons/declaration_view_lock.png"));
}
-}
\ No newline at end of file
+}
+
+++ /dev/null
-/*******************************************************************************\r
- * Program Understanding / Advanced Declaration View for JavaScript\r
- *\r
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * Hyukmin Kwon <hyukmin0530@samsung.com>\r
- * Jaeheung Kim <jaeheung.kim@samsung.com>\r
- * Sujin Kim <sujin921.kim@samsung.com>\r
- * Woongsik Choi <woongsik76.choi@samsung.com>\r
- * \r
- * This program and the accompanying materials are made available \r
- * under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- * \r
- *******************************************************************************/\r
-\r
-package org.tizen.web.advanceddeclarationview.ui;\r
-\r
-import org.eclipse.jface.action.IAction;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.ui.IViewActionDelegate;\r
-import org.eclipse.ui.IViewPart;\r
-\r
-public class ToggleLockActionDelegate implements IViewActionDelegate {\r
- private AdvancedDeclarationView targetPart;\r
- private static ToggleLockActionDelegate lockAction;\r
-\r
- @Override\r
- public void run(IAction action) {\r
- targetPart.setLocked(!targetPart.isLocked());\r
- }\r
-\r
- @Override\r
- public void selectionChanged(IAction action, ISelection selection) {\r
- targetPart.setLockAction(action);\r
- }\r
-\r
- @Override\r
- public void init(IViewPart view) {\r
- targetPart = (AdvancedDeclarationView)view;\r
- targetPart.setLocked(false);\r
- \r
- lockAction = this;\r
- }\r
-\r
- public static ToggleLockActionDelegate getDefault() {\r
- return lockAction;\r
- }\r
- \r
- public AdvancedDeclarationView getTarget() {\r
- return targetPart;\r
- }\r
-}\r