diff options
Diffstat (limited to 'bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension')
8 files changed, 0 insertions, 2116 deletions
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ActionDescriptor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ActionDescriptor.java deleted file mode 100644 index 9a72e7a359..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ActionDescriptor.java +++ /dev/null @@ -1,378 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - - - -import java.util.StringTokenizer; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.ui.internal.IActionValidator; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.osgi.framework.Bundle; - - -/** - * When 'action' tag is found in the registry, an object of this class is - * created. It creates the appropriate action object and captures information - * that is later used to add this action object into menu/tool bar. This class - * is reused for global (workbench) menu/tool bar, popup menu actions, as well - * as view's pulldown and local tool bar. - */ -public class ActionDescriptor { - public static final String ATT_ACCELERATOR = "accelerator"; //$NON-NLS-1$ - public static final String ATT_CLASS = "class"; //$NON-NLS-1$ - public static final String ATT_DEFINITION_ID = "definitionId"; //$NON-NLS-1$ - public static final String ATT_DESCRIPTION = "description"; //$NON-NLS-1$ - public static final String ATT_DISABLEDICON = "disabledIcon"; //$NON-NLS-1$ - public static final String ATT_HELP_CONTEXT_ID = "helpContextId"; //$NON-NLS-1$ - public static final String ATT_HOVERICON = "hoverIcon"; //$NON-NLS-1$ - public static final String ATT_ICON = "icon"; //$NON-NLS-1$ - - public static final String ATT_ID = "id"; //$NON-NLS-1$ - public static final String ATT_LABEL = "label"; //$NON-NLS-1$ - public static final String ATT_MENUBAR_PATH = "menubarPath"; //$NON-NLS-1$ - public static final String ATT_POPUPMENU_PATH = "popupmenuPath"; //$NON-NLS-1$ - public static final String ATT_STATE = "state"; //$NON-NLS-1$ - public static final String ATT_TOOLBAR_PATH = "toolbarPath"; //$NON-NLS-1$ - public static final String ATT_TOOLTIP = "tooltip"; //$NON-NLS-1$ - - /** - * Creates an extension. If the extension plugin has not been loaded a - * busy cursor will be activated during the duration of the load. - * - * @param element - * the config element defining the extension - * @param classAttribute - * the name of the attribute carrying the class - * @returns the extension object if successful. If an error occurs when - * createing executable extension, the exception is logged, and - * null returned. - */ - public static Object createExtension(final IConfigurationElement element, final String classAttribute) { - final Object[] result = new Object[1]; - // If plugin has been loaded create extension. - // Otherwise, show busy cursor then create extension. - String pluginId = element.getDeclaringExtension().getNamespace(); - Bundle bundle = Platform.getBundle(pluginId); - if (bundle.getState() == Bundle.ACTIVE) { - try { - result[0] = element.createExecutableExtension(classAttribute); - } catch (Exception e) { - // catch and log ANY exception from extension point - handleCreateExecutableException(result, e); - } - } else { - BusyIndicator.showWhile(null, new Runnable() { - public void run() { - try { - result[0] = element.createExecutableExtension(classAttribute); - } catch (Exception e) { - // catch and log ANY exception from extension point - handleCreateExecutableException(result, e); - } - } - }); - } - return result[0]; - } - - private static void handleCreateExecutableException(final Object[] result, Throwable e) { - Logger.logException(e); - result[0] = null; - } - - private String id; - - private ActionContributionItem item; - private String menuGroup; - private String menuPath; - private String popupmenuGroup; - private String popupmenuPath; - private String toolbarGroup; - private String toolbarPath; - - /** - * Creates a new descriptor with the targetType - */ - public ActionDescriptor(IConfigurationElement actionElement) throws CoreException { - - // Calculate menu and toolbar paths. - String mpath = actionElement.getAttribute(ATT_MENUBAR_PATH); - String mgroup = null; - if (mpath != null) { - int loc = mpath.lastIndexOf('/'); - if (loc != -1) { - mgroup = mpath.substring(loc + 1); - mpath = mpath.substring(0, loc); - } else { - mgroup = mpath; - mpath = null; - } - } - menuPath = mpath; - menuGroup = mgroup; - - String ppath = actionElement.getAttribute(ATT_POPUPMENU_PATH); - String pgroup = null; - if (ppath != null) { - int loc = ppath.lastIndexOf('/'); - if (loc != -1) { - pgroup = ppath.substring(loc + 1); - ppath = ppath.substring(0, loc); - } else { - pgroup = ppath; - ppath = null; - } - } - popupmenuPath = ppath; - popupmenuGroup = pgroup; - - String tpath = actionElement.getAttribute(ATT_TOOLBAR_PATH); - String tgroup = null; - if (tpath != null) { - int loc = tpath.lastIndexOf('/'); - if (loc != -1) { - tgroup = tpath.substring(loc + 1); - tpath = tpath.substring(0, loc); - } else { - tgroup = tpath; - tpath = null; - } - } - toolbarPath = tpath; - toolbarGroup = tgroup; - - // Create action. - IAction action = createAction(actionElement); - if (action == null) - return; - - String label = actionElement.getAttribute(ATT_LABEL); - if (label != null) - action.setText(label); - - id = actionElement.getAttribute(ATT_ID); - if (id == null) { - id = actionElement.getAttribute(ATT_CLASS); - } - if (id != null) - action.setId(id); - - String defId = actionElement.getAttribute(ATT_DEFINITION_ID); - if (defId != null && defId.length() != 0) { - action.setActionDefinitionId(defId); - } - - String tooltip = actionElement.getAttribute(ATT_TOOLTIP); - if (tooltip != null) - action.setToolTipText(tooltip); - - String helpContextId = actionElement.getAttribute(ATT_HELP_CONTEXT_ID); - if (helpContextId != null) { - String fullID = helpContextId; - if (helpContextId.indexOf(".") == -1) //$NON-NLS-1$ - // For backward compatibility we auto qualify the id if it is - // not qualified) - fullID = actionElement.getDeclaringExtension().getNamespace() + "." + helpContextId; //$NON-NLS-1$ - PlatformUI.getWorkbench().getHelpSystem().setHelp(action, fullID); - } - - String description = actionElement.getAttribute(ATT_DESCRIPTION); - if (description != null) - action.setDescription(description); - - String state = actionElement.getAttribute(ATT_STATE); - if (state != null) { - action.setChecked(state.equals("true")); //$NON-NLS-1$ - } - - String icon = actionElement.getAttribute(ATT_ICON); - if (icon != null) { - action.setImageDescriptor(ImageUtil.getImageDescriptorFromExtension(actionElement.getDeclaringExtension(), icon)); - } - - String hoverIcon = actionElement.getAttribute(ATT_HOVERICON); - if (hoverIcon != null) { - action.setHoverImageDescriptor(ImageUtil.getImageDescriptorFromExtension(actionElement.getDeclaringExtension(), hoverIcon)); - } - - String disabledIcon = actionElement.getAttribute(ATT_DISABLEDICON); - if (disabledIcon != null) { - action.setDisabledImageDescriptor(ImageUtil.getImageDescriptorFromExtension(actionElement.getDeclaringExtension(), disabledIcon)); - } - - String accelerator = actionElement.getAttribute(ATT_ACCELERATOR); - if (accelerator != null) - processAccelerator(action, accelerator); - - item = new ActionContributionItem(action); - } - - /** - * Parses the given accelerator text, and converts it to an accelerator - * key code. - * - * @param acceleratorText - * the accelerator text - * @result the SWT key code, or 0 if there is no accelerator - */ - private int convertAccelerator(String acceleratorText) { - int accelerator = 0; - StringTokenizer stok = new StringTokenizer(acceleratorText, "+"); //$NON-NLS-1$ - - int keyCode = -1; - - boolean hasMoreTokens = stok.hasMoreTokens(); - while (hasMoreTokens) { - String token = stok.nextToken(); - hasMoreTokens = stok.hasMoreTokens(); - // Every token except the last must be one of the modifiers - // Ctrl, Shift, or Alt. - if (hasMoreTokens) { - int modifier = Action.findModifier(token); - if (modifier != 0) { - accelerator |= modifier; - } else { //Leave if there are none - return 0; - } - } else { - keyCode = Action.findKeyCode(token); - } - } - if (keyCode != -1) { - accelerator |= keyCode; - } - return accelerator; - } - - /** - */ - private IAction createAction(IConfigurationElement actionElement) { - Object action = new ExtendedEditorActionProxyForDelayLoading(actionElement, ATT_CLASS); - if (action == null) - return null; - if (action instanceof IActionValidator) { - if (!((IActionValidator) action).isValidAction()) - return null; - } - return (action instanceof IAction ? (IAction) ExtendedEditorActionProxy.newInstance(action) : null); - } - - /** - * Returns the action object held in this descriptor. - */ - public IAction getAction() { - return (item != null ? item.getAction() : null); - } - - /** - * Returns the IContributionItem object held in this descriptor. - */ - public IContributionItem getContributionItem() { - return item; - } - - /** - * Returns action's id as defined in the registry. - */ - public String getId() { - return id; - } - - /** - * Returns named slot (group) in the menu where this action should be - * added. - */ - public String getMenuGroup() { - return menuGroup; - } - - /** - * Returns menu path where this action should be added. If null, the - * action will not be added into the menu. - */ - - public String getMenuPath() { - return menuPath; - } - - /** - * Returns named slot (group) in the popup menu where this action should - * be added. - */ - public String getPopupMenuGroup() { - return popupmenuGroup; - } - - /** - * Returns popup menu path where this action should be added. If null, the - * action will not be added into the popup menu. - */ - - public String getPopupMenuPath() { - return popupmenuPath; - } - - /** - * Returns the named slot (group) in the tool bar where this action should - * be added. - */ - - public String getToolbarGroup() { - return toolbarGroup; - } - - /** - * Returns path in the tool bar where this action should be added. If - * null, action will not be added to the tool bar. - */ - public String getToolbarPath() { - return toolbarPath; - } - - /** - * Process the accelerator definition. If it is a number then process the - * code directly - if not then parse it and create the code - */ - private void processAccelerator(IAction action, String acceleratorText) { - - if (acceleratorText.length() == 0) - return; - - //Is it a numeric definition? - if (Character.isDigit(acceleratorText.charAt(0))) { - try { - action.setAccelerator(Integer.valueOf(acceleratorText).intValue()); - } catch (NumberFormatException exception) { - Logger.log(Logger.ERROR, "Invalid accelerator declaration: " + id); //$NON-NLS-1$ - } - } else - action.setAccelerator(convertAccelerator(acceleratorText)); - } - - /** - * For debugging only. - */ - public String toString() { - return "ActionDescriptor(" + id + ")"; //$NON-NLS-2$//$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/BreakpointProviderBuilder.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/BreakpointProviderBuilder.java deleted file mode 100644 index a4be6427b9..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/BreakpointProviderBuilder.java +++ /dev/null @@ -1,405 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider; -import org.osgi.framework.Bundle; - - -/** - * Reads breakpoint extension registory and returns breakpoint provider - * instances - */ -public class BreakpointProviderBuilder extends RegistryReader { - - private static final String ATT_CLASS = "class"; //$NON-NLS-1$ - // private static final String ATT_ID = "id"; //$NON-NLS-1$ - private static final String ATT_CONTENT_TYPES = "contentTypes"; //$NON-NLS-1$ - private static final String ATT_EXTENSIONS = "extensions"; //$NON-NLS-1$ - private static BreakpointProviderBuilder instance; - private static final String PL_BREAKPOINT = "breakpoint"; //$NON-NLS-1$ - - private static final String PLUGIN_ID = "org.eclipse.wst.sse.ui"; //$NON-NLS-1$ - - private static final String TAG_BREAKPOINT_CONTRIBUTION = "breakpointContribution"; //$NON-NLS-1$ - private static final String TAG_PROVIDER = "provider"; //$NON-NLS-1$ - - /* - * Creates an executable extension. @param element the config element - * defining the extension @param classAttribute the name of the attribute - * carrying the class @return the extension object @throws CoreException - */ - static Object createExecutableExtension(final IConfigurationElement element, final String classAttribute) throws CoreException { - return element.createExecutableExtension(classAttribute); - } - - /** - * Creates an extension. If the extension plugin has not been loaded a - * busy cursor will be activated during the duration of the load. - * - * @param element - * the config element defining the extension - * @param classAttribute - * the name of the attribute carrying the class - * @return the extension object - * @throws CoreException - */ - public static Object createExtension(final IConfigurationElement element, final String classAttribute) { - // If plugin has been loaded create extension. - // Otherwise, show busy cursor then create extension. - final Object[] result = new Object[1]; - String pluginId = element.getDeclaringExtension().getNamespace(); - Bundle bundle = Platform.getBundle(pluginId); - if (bundle.getState() == Bundle.ACTIVE) { - try { - result[0] = createExecutableExtension(element, classAttribute); - } - catch (Exception e) { - handleCreateExecutableException(result, e); - } - } - else { - BusyIndicator.showWhile(null, new Runnable() { - public void run() { - try { - result[0] = createExecutableExtension(element, classAttribute); - } - catch (CoreException e) { - handleCreateExecutableException(result, e); - } - } - }); - - } - return result[0]; - } - - /** - * returns singleton instance of BreakpointProviderBuilder - * - * @return BreakpointProviderBuilder - */ - public synchronized static BreakpointProviderBuilder getInstance() { - if (instance == null) { - instance = new BreakpointProviderBuilder(); - } - return instance; - } - - /** - * @param result - * @param e - */ - private static void handleCreateExecutableException(Object[] result, Throwable e) { - Logger.logException(e); - result[0] = null; - - } - - protected List cache; - private Map map = new HashMap(); - - protected String targetContributionTag; - - /* - * Constructor - */ - private BreakpointProviderBuilder() { - super(); - } - - /* - * Creates a breakpoint provider object to given element @param element - * configuration element object @return IBreakpointProvider - */ - protected IBreakpointProvider createBreakpointProvider(IConfigurationElement element) { - Object obj = createExtension(element, ATT_CLASS); - if (obj == null) - return null; - return (obj instanceof IBreakpointProvider) ? (IBreakpointProvider) obj : null; - } - - /* - * Creates an array of breakpoint providers matching the given key to the - * value of the IConfigurationElement attribute "attrName" @return - * IBreakpointProvider[] - */ - protected IBreakpointProvider[] createBreakpointProviders(String attrName, String key) { - if (cache == null) - return new IBreakpointProvider[0]; - - final int num = cache.size(); - if (num == 0) - return new IBreakpointProvider[0]; - - IBreakpointProvider[] bp = new IBreakpointProvider[num]; - int j = 0; - for (int i = 0; i < num; i++) { - Object obj = cache.get(i); - if (!(obj instanceof IConfigurationElement)) - continue; - - IConfigurationElement element = (IConfigurationElement) obj; - if (!TAG_PROVIDER.equals(element.getName())) - continue; - - boolean doCreate = false; - - String attrValues = element.getAttribute(attrName); - - if (attrValues != null) { - StringTokenizer tokenizer = new StringTokenizer(attrValues, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String type = tokenizer.nextToken(); - if (type.trim().equalsIgnoreCase(key.trim())) { - doCreate = true; - break; - } - } - } - - if (doCreate) { - IBreakpointProvider b = createBreakpointProvider(element); - if (b != null) { - bp[j] = b; - j++; - } - } - } - - IBreakpointProvider[] bp2 = new IBreakpointProvider[j]; - for (int i = 0; i < j; i++) { - bp2[i] = bp[i]; - } - - return bp2; - } - - /* - * Returns a matching array of extension points matching this key. Doesn't - * cause instantiation of providers. @return IBreakpointProvider[] - */ - protected IConfigurationElement[] findElements(String key) { - initCache(); - - if (cache == null || cache.size() == 0) - return new IConfigurationElement[0]; - - int num = cache.size(); - List elements = new ArrayList(1); - for (int i = 0; i < num; i++) { - Object obj = cache.get(i); - if (!(obj instanceof IConfigurationElement)) - continue; - - IConfigurationElement element = (IConfigurationElement) obj; - if (!TAG_PROVIDER.equals(element.getName())) - continue; - - boolean add = false; - String types = element.getAttribute(ATT_CONTENT_TYPES); - String exts = element.getAttribute(ATT_EXTENSIONS); - - if (types == null && exts == null) { - add = true; - } - - if (!add && types != null && types.length() > 0) { - IContentType testType = Platform.getContentTypeManager().getContentType(key); - StringTokenizer tokenizer = new StringTokenizer(types, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String type = tokenizer.nextToken(); - IContentType contentType = Platform.getContentTypeManager().getContentType(type); - if (contentType != null && testType != null && contentType.isKindOf(testType)) { - add = true; - break; - } - } - } - - if (!add && exts != null) { - StringTokenizer tokenizer = new StringTokenizer(exts, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String ext = tokenizer.nextToken(); - if (ext.trim().equals(key.trim())) { - add = true; - break; - } - } - } - - if (add) { - elements.add(element); - } - } - return (IConfigurationElement[]) elements.toArray(new IConfigurationElement[0]); - } - - /** - * Returns an array of breakpoint providers for a specified content type - * handler - * - * @param handler - * a content type handler - * @param ext - * file extension - * @return IBreakpointProvider[] - */ - public IBreakpointProvider[] getBreakpointProviders(IEditorPart editorpart, String contentTypeID, String ext) { - initCache(); - - // Get breakpoint providers for this content type handler - IBreakpointProvider[] providers1 = new IBreakpointProvider[0]; - IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeID); - List holdProviders = new ArrayList(2); - while (contentType != null) { - IBreakpointProvider[] providers = (IBreakpointProvider[]) map.get(contentType.getId()); - if (providers == null) { - providers = createBreakpointProviders(ATT_CONTENT_TYPES, contentType.getId()); - if (providers != null) { - map.put(contentType.getId(), providers); - } - } - // providers were retrieved from cache or newly created - if(providers != null) { - holdProviders.addAll(Arrays.asList(providers)); - } - contentType = contentType.getBaseType(); - } - providers1 = (IBreakpointProvider[]) holdProviders.toArray(new IBreakpointProvider[holdProviders.size()]); - - // Get breakpoint providers for this extension - IBreakpointProvider[] providers2 = new IBreakpointProvider[0]; - if (ext != null) { - providers2 = (IBreakpointProvider[]) map.get(ext); - if (providers2 == null) { - providers2 = createBreakpointProviders(ATT_EXTENSIONS, ext); - if (providers2 != null) { - map.put(ext, providers2); - } - } - } - - // create single hash set to remove duplication - Set s = new HashSet(); - s.addAll(Arrays.asList(providers1)); - s.addAll(Arrays.asList(providers2)); - - // create IBreakpointProvider[] to return - IBreakpointProvider[] providers = new IBreakpointProvider[s.size()]; - Iterator itr = s.iterator(); - int i = 0; - ISourceEditingTextTools tools = null; - if (editorpart != null && itr.hasNext()) - tools = (ISourceEditingTextTools) editorpart.getAdapter(ISourceEditingTextTools.class); - while (itr.hasNext()) { - providers[i] = (IBreakpointProvider) itr.next(); - providers[i].setSourceEditingTextTools(tools); - i++; - } - return providers; - } - - /** - * Returns corresponding resource from given parameters - * - * @param input - * @param handler - * @param ext - * @return IResource - */ - public IResource getResource(IEditorInput input, String contentType, String ext) { - IBreakpointProvider[] providers = getBreakpointProviders(null, contentType, ext); - IResource res = null; - for (int i = 0; i < providers.length; i++) { - res = providers[i].getResource(input); - if (res != null) { - break; - } - } - return res; - } - - private void initCache() { - if (cache == null) { - cache = new ArrayList(); - readContributions(TAG_BREAKPOINT_CONTRIBUTION, PL_BREAKPOINT); - } - } - - /** - * Returns an array of breakpoint providers for a specified content type - * handler - * - * @param contentType - * a content type ID or null - * @param ext - * a filename extension or null - * @return boolean - */ - public boolean isAvailable(String contentType, String ext) { - boolean available = false; - if (ext != null) - available = findElements(ext).length > 0; - if (!available && contentType != null) - available = findElements(contentType).length > 0; - return available; - } - - /** - * Reads the contributions from the registry for the provided workbench - * part and the provided extension point ID. - * - * @param tag - * @param extensionPoint - */ - protected void readContributions(String tag, String extensionPoint) { - targetContributionTag = tag; - IExtensionRegistry registry = Platform.getExtensionRegistry(); - readRegistry(registry, PLUGIN_ID, extensionPoint); - } - - protected boolean readElement(IConfigurationElement element) { - String tag = element.getName(); - if (tag.equals(targetContributionTag)) { - readElementChildren(element); - return true; - } - else if (tag.equals(TAG_PROVIDER)) { - cache.add(element); - return true; // just cache the element - don't go into it - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/DropActionProxy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/DropActionProxy.java deleted file mode 100644 index 0eebf4e9cb..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/DropActionProxy.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IDocument; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; -import org.eclipse.wst.sse.ui.internal.IExtendedSimpleEditor; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISelfValidateEditAction; - - -/** - */ -public class DropActionProxy implements InvocationHandler { - public static Object newInstance(Object obj) { - Object instance = null; - try { - Set set = new HashSet(); - Class clazz = obj.getClass(); - while (clazz != null) { - Class[] interfaces = clazz.getInterfaces(); - for (int i = 0; i < interfaces.length; i++) { - set.add(interfaces[i]); - } - clazz = clazz.getSuperclass(); - } - Class[] classes = new Class[set.size()]; - Iterator itr = set.iterator(); - int i = 0; - while (itr.hasNext()) { - classes[i] = (Class) itr.next(); - i++; - } - instance = Proxy.newProxyInstance(obj.getClass().getClassLoader(), classes, new DropActionProxy(obj)); - } catch (Error e) { - Logger.logException("Exception while proxying a drop action", e); //$NON-NLS-1$ - instance = obj; - } - return instance; - } - - private IExtendedSimpleEditor editor = null; - private IStructuredModel fRecorder; - private Object obj; - - private DropActionProxy(Object obj) { - this.obj = obj; - } - - private void beginRecording() { - IDocument document = null; - if (editor != null) { - document = editor.getDocument(); - if (document != null) - fRecorder = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - // Prepare for Undo - if (fRecorder != null) { - IStructuredTextUndoManager um = fRecorder.getUndoManager(); - if (um != null) { - if (this.obj instanceof IAction) - um.beginRecording(this, ((IAction) this.obj).getText(), ((IAction) this.obj).getDescription()); - else - um.beginRecording(this); - } - } - } - } - - private void endRecording() { - if (fRecorder != null) { - IStructuredTextUndoManager um = fRecorder.getUndoManager(); - if (um != null) - um.endRecording(this); - fRecorder.releaseFromEdit(); - fRecorder = null; - } - } - - /** - * @see java.lang.reflect.InvocationHandler#invoke(Object, Method, - * Object[]) - */ - public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { - Object result; - String name = m.getName(); - try { - if (name.equals("equals")) { //$NON-NLS-1$ - // Workaround for JDK's bug 4652876 - // "equals" always returns false even if both - // InvocationHandler - // class - // hold the same objects - // See - // http://developer.java.sun.com/developer/bugParade/bugs/4652876.html - // This problem is in the IBM SDK 1.3.1 - // but I don't see the bug in Sun's JDK 1.4.1 (beta) - Object arg = args[0]; - return (proxy.getClass() == arg.getClass() && equals(Proxy.getInvocationHandler(arg))) ? Boolean.TRUE : Boolean.FALSE; - } else if (name.equals("run")) { //$NON-NLS-1$ - if (args[1] instanceof IExtendedSimpleEditor) { - editor = (IExtendedSimpleEditor) args[1]; - } - beginRecording(); - if ((editor != null) && !(obj instanceof ISelfValidateEditAction)) { - - // TODO: cleanup validateEdit - // just leaving this check and following code here for transition. - // I assume we'll remove all need for 'validateEdit' - // or move to platform editor's validateState - -// IStatus status = editor.validateEdit(getDisplay().getActiveShell()); -// if (!status.isOK()) { -// return null; -// } - } - } - result = m.invoke(obj, args); - } catch (InvocationTargetException e) { - throw e.getTargetException(); - } catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } finally { - if (name.equals("run")) { //$NON-NLS-1$ - endRecording(); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ExtendedEditorActionProxy.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ExtendedEditorActionProxy.java deleted file mode 100644 index 72c7bba014..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ExtendedEditorActionProxy.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IDocument; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; -import org.eclipse.wst.sse.ui.internal.IExtendedSimpleEditor; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISelfValidateEditAction; - - -/** - * Begins and ends UndoManager recording around run() and runWithEvent(...) - */ -public class ExtendedEditorActionProxy implements InvocationHandler { - public static Object newInstance(Object obj) { - Set set = new HashSet(); - Class clazz = obj.getClass(); - while (clazz != null) { - Class[] interfaces = clazz.getInterfaces(); - for (int i = 0; i < interfaces.length; i++) { - set.add(interfaces[i]); - } - clazz = clazz.getSuperclass(); - } - Class[] classes = new Class[set.size()]; - Iterator itr = set.iterator(); - int i = 0; - while (itr.hasNext()) { - classes[i] = (Class) itr.next(); - i++; - } - return Proxy.newProxyInstance(obj.getClass().getClassLoader(), classes, new ExtendedEditorActionProxy(obj)); - } - - private IExtendedSimpleEditor editor = null; - private IStructuredModel fRecorder; - private Object obj; - - private ExtendedEditorActionProxy(Object obj) { - this.obj = obj; - } - - private void beginRecording() { - IDocument document = null; - if (editor != null) { - document = editor.getDocument(); - if (document != null) - fRecorder = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - // Prepare for Undo - if (fRecorder != null) { - IStructuredTextUndoManager um = fRecorder.getUndoManager(); - if (um != null) { - um.beginRecording(this, ((IAction) this.obj).getText(), ((IAction) this.obj).getDescription()); - } - } - } - } - - private void endRecording() { - if (fRecorder != null) { - IStructuredTextUndoManager um = fRecorder.getUndoManager(); - if (um != null) { - um.endRecording(this); - } - fRecorder.releaseFromEdit(); - fRecorder = null; - } - } - - /** - * @see java.lang.reflect.InvocationHandler#invoke(Object, Method, - * Object[]) - */ - public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { - Object result = null; - String name = m.getName(); - try { - if (name.equals("equals")) { //$NON-NLS-1$ - // Workaround for JDK's bug 4652876 - // "equals" always returns false even if both - // InvocationHandler - // class - // hold the same objects - // See - // http://developer.java.sun.com/developer/bugParade/bugs/4652876.html - // This problem is in the IBM SDK 1.3.1 - // but I don't see the bug in Sun's JDK 1.4.1 (beta) - Object arg = args[0]; - return (proxy.getClass() == arg.getClass() && equals(Proxy.getInvocationHandler(arg))) ? Boolean.TRUE : Boolean.FALSE; - } else if (name.equals("runWithEvent") || name.equals("run")) { //$NON-NLS-1$ //$NON-NLS-2$ - beginRecording(); - if ((editor != null) && !(this.obj instanceof ISelfValidateEditAction)) { - - // TODO: cleanup validateEdit - // just leaving this check and following code here for transition. - // I assume we'll remove all need for 'validateEdit' - // or move to platform editor's validateState - -// IStatus status = editor.validateEdit(getDisplay().getActiveShell()); -// if (!status.isOK()) { -// return null; -// } - } - } else if (name.equals("setActiveExtendedEditor")) { //$NON-NLS-1$ - if (args[0] instanceof IExtendedSimpleEditor) { - editor = (IExtendedSimpleEditor) args[0]; - } - } - result = m.invoke(this.obj, args); - } catch (InvocationTargetException e) { - Logger.logException(e.getTargetException()); - //throw e.getTargetException(); - } catch (Exception e) { - Logger.logException(e); - if (name.equals("runWithEvent") || name.equals("run")) { //$NON-NLS-1$ //$NON-NLS-2$ - // only expose user-driven exceptions from "running" to the - // user - throw new RuntimeException(e.getMessage()); - } - } finally { - if (name.equals("runWithEvent") || name.equals("run")) { //$NON-NLS-1$ //$NON-NLS-2$ - endRecording(); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ExtendedEditorActionProxyForDelayLoading.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ExtendedEditorActionProxyForDelayLoading.java deleted file mode 100644 index c4565df89f..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ExtendedEditorActionProxyForDelayLoading.java +++ /dev/null @@ -1,752 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuCreator; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.ListenerList; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.events.HelpListener; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.texteditor.IUpdate; -import org.eclipse.wst.sse.ui.internal.IExtendedEditorAction; -import org.eclipse.wst.sse.ui.internal.IExtendedSimpleEditor; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.osgi.framework.Bundle; - -public class ExtendedEditorActionProxyForDelayLoading implements IExtendedEditorAction, IExtendedEditorActionProxyForDelayLoading, IAction { - private IAction proxy; - private IAction dummy = new Action() { // this is for mainly its property change notify... - }; - // proxy'ed properties - private String p_id; - private boolean set_p_id; - private String p_text; - private boolean set_p_text; - private String p_toolTipText; - private boolean set_p_toolTipText; - private String p_actionDefinitionId; - private boolean set_p_actionDefinitionId; - private ImageDescriptor p_image; - private boolean set_p_image; - private ImageDescriptor p_hoverImage; - private boolean set_p_hoverImage; - private ImageDescriptor p_disabledImage; - private boolean set_p_disabledImage; - private int p_accelerator; - private boolean set_p_accelerator; - private int p_style = AS_PUSH_BUTTON; - //private boolean set_p_style; - private HelpListener p_helpListener; - private boolean set_p_helpListener; - private boolean p_enabled = true; // should be same as what is done in - private boolean set_p_enabled; - private ListenerList p_listeners = new ListenerList(3); - private boolean set_p_listeners; - private boolean p_checked; - private boolean set_p_checked; - private IExtendedSimpleEditor p_targetEditor; - private boolean set_p_targetEditor; - private boolean p_isvisible = true; // should be true - - private IConfigurationElement element; - private String classAttribute; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) - */ - public void addPropertyChangeListener(IPropertyChangeListener listener) { - p_listeners.add(listener); - set_p_listeners = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.addPropertyChangeListener(listener); - } else { - dummy.addPropertyChangeListener(listener); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getAccelerator() - */ - public int getAccelerator() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getAccelerator(); - } - return p_accelerator; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getActionDefinitionId() - */ - public String getActionDefinitionId() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getActionDefinitionId(); - } - return p_actionDefinitionId; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getDescription() - */ - public String getDescription() { - // System.out.println(p_id + ": getDescription"); - // System.out.flush(); - realize(); - if (proxy != null) { - return proxy.getDescription(); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getDisabledImageDescriptor() - */ - public ImageDescriptor getDisabledImageDescriptor() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getDisabledImageDescriptor(); - } - return p_disabledImage; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getHelpListener() - */ - public HelpListener getHelpListener() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getHelpListener(); - } - return p_helpListener; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getHoverImageDescriptor() - */ - public ImageDescriptor getHoverImageDescriptor() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getHoverImageDescriptor(); - } - return p_hoverImage; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getId() - */ - public String getId() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getId(); - } - return p_id; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getImageDescriptor() - */ - public ImageDescriptor getImageDescriptor() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getImageDescriptor(); - } - return p_image; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getMenuCreator() - */ - public IMenuCreator getMenuCreator() { - // System.out.println(p_id + ": getMenuCreator"); - // System.out.flush(); - realize(); - if (proxy != null) { - return proxy.getMenuCreator(); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getStyle() - */ - public int getStyle() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getStyle(); - } - return p_style; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getText() - */ - public String getText() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getText(); - } - return p_text; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#getToolTipText() - */ - public String getToolTipText() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.getToolTipText(); - } - return p_toolTipText; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#isChecked() - */ - public boolean isChecked() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.isChecked(); - } - return p_checked; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#isEnabled() - */ - public boolean isEnabled() { - // don't realize class. - // realize(); - if (proxy != null) { - return proxy.isEnabled(); - } - return p_enabled; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) - */ - public void removePropertyChangeListener(IPropertyChangeListener listener) { - p_listeners.remove(listener); - // don't realize class. - // realize(); - if (proxy != null) { - proxy.removePropertyChangeListener(listener); - } - dummy.removePropertyChangeListener(listener); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#run() - */ - public void run() { - realize(); - if (proxy != null) { - // if this has a key accelerator, first update this action and to - // see if this action is enabled or not. - if ((proxy.getAccelerator() > 0) || (proxy.getActionDefinitionId() != null)) { - update(); - if (isEnabled() == true) { - proxy.run(); - } - } else { - proxy.run(); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#runWithEvent(org.eclipse.swt.widgets.Event) - */ - public void runWithEvent(Event event) { - realize(); - if (proxy != null) { - // same as run() - if ((proxy.getAccelerator() > 0) || (proxy.getActionDefinitionId() != null)) { - update(); - if (isEnabled() == true) { - proxy.runWithEvent(event); - } - } else { - proxy.runWithEvent(event); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setActionDefinitionId(java.lang.String) - */ - public void setActionDefinitionId(String id) { - p_actionDefinitionId = id; - set_p_actionDefinitionId = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setActionDefinitionId(id); - } else { - dummy.setActionDefinitionId(id); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setChecked(boolean) - */ - public void setChecked(boolean checked) { - p_checked = checked; - set_p_checked = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setChecked(checked); - } else { - dummy.setChecked(checked); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setDescription(java.lang.String) - */ - public void setDescription(String text) { - // System.out.println(p_id + ": setDescription"); - // System.out.flush(); - realize(); - if (proxy != null) { - proxy.setDescription(text); - } else { - dummy.setDescription(text); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setDisabledImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) - */ - public void setDisabledImageDescriptor(ImageDescriptor newImage) { - p_disabledImage = newImage; - set_p_disabledImage = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setDisabledImageDescriptor(newImage); - } else { - dummy.setDisabledImageDescriptor(newImage); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setEnabled(boolean) - */ - public void setEnabled(boolean enabled) { - p_enabled = enabled; - set_p_enabled = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setEnabled(enabled); - } else { - dummy.setEnabled(enabled); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setHelpListener(org.eclipse.swt.events.HelpListener) - */ - public void setHelpListener(HelpListener listener) { - p_helpListener = listener; - set_p_helpListener = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setHelpListener(listener); - } else { - dummy.setHelpListener(listener); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setHoverImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) - */ - public void setHoverImageDescriptor(ImageDescriptor newImage) { - p_hoverImage = newImage; - set_p_hoverImage = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setHoverImageDescriptor(newImage); - } else { - dummy.setHoverImageDescriptor(newImage); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setId(java.lang.String) - */ - public void setId(String id) { - p_id = id; - set_p_id = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setId(id); - } else { - dummy.setId(id); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) - */ - public void setImageDescriptor(ImageDescriptor newImage) { - p_image = newImage; - set_p_image = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setImageDescriptor(newImage); - } else { - dummy.setImageDescriptor(newImage); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setMenuCreator(org.eclipse.jface.action.IMenuCreator) - */ - public void setMenuCreator(IMenuCreator creator) { - // System.out.println(p_id + ": setMenuCreator"); - // System.out.flush(); - realize(); - if (proxy != null) { - proxy.setMenuCreator(creator); - } else { - dummy.setMenuCreator(creator); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setText(java.lang.String) - */ - public void setText(String text) { - p_text = text; - set_p_text = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setText(text); - } else { - dummy.setText(text); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setToolTipText(java.lang.String) - */ - public void setToolTipText(String text) { - p_toolTipText = text; - set_p_toolTipText = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setToolTipText(text); - } else { - dummy.setToolTipText(text); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#setAccelerator(int) - */ - public void setAccelerator(int keycode) { - p_accelerator = keycode; - set_p_accelerator = true; - // don't realize class. - // realize(); - if (proxy != null) { - proxy.setAccelerator(keycode); - } else { - dummy.setAccelerator(keycode); - } - } - - - /* (non-Javadoc) - * @see org.eclipse.wst.sse.ui.internal.IExtendedEditorAction#setActiveExtendedEditor(com.ibm.sse.editor.extension.IExtendedSimpleEditor) - */ - public void setActiveExtendedEditor(IExtendedSimpleEditor targetEditor) { - p_targetEditor = targetEditor; - set_p_targetEditor = true; - // don't realize class. - // realize(); - if ((proxy != null) && (proxy instanceof IExtendedEditorAction)) { - ((IExtendedEditorAction)proxy).setActiveExtendedEditor(targetEditor); - } - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extension.IExtendedEditorAction#isVisible() - */ - public boolean isVisible() { - // don't realize class. - // realize(); - if ((proxy != null) && (proxy instanceof IExtendedEditorAction)) { - return ((IExtendedEditorAction)proxy).isVisible(); - } - return p_isvisible; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IAction#isHandled - */ - public boolean isHandled() { - return false; - } - - // see ActionDescriptor#createExtension - private static IAction newInstance(final IConfigurationElement elm, final String cla) { - final Object[] result = new Object[1]; - // If plugin has been loaded create extension. - // Otherwise, show busy cursor then create extension. - Bundle bundle= Platform.getBundle(elm.getDeclaringExtension().getNamespace()); - if (bundle != null && bundle.getState() == Bundle.ACTIVE) { - try { - result[0] = elm.createExecutableExtension(cla); - } - catch (Exception e) { - // catch and log ANY exception from extension point - handleCreateExecutableException(result, e); - } - } - else { - BusyIndicator.showWhile(null, new Runnable() { - public void run() { - try { - result[0] = elm.createExecutableExtension(cla); - } - catch (Exception e) { - // catch and log ANY exception from extension point - handleCreateExecutableException(result, e); - } - } - }); - } - if ((result[0] != null) && (result[0] instanceof IAction)) { - return (IAction)result[0]; - } - return null; - } - - private static void handleCreateExecutableException(final Object[] result, Throwable e) { - Logger.logException(e); - result[0] = null; - } - - /** - * Instantiate a real class here - */ - public void realize() { - if ((proxy == null) && (element != null) && (classAttribute != null)) { - proxy = newInstance(element, classAttribute); - if (proxy != null) { - element = null; - classAttribute = null; - // propagate proxy'ed properties - if (set_p_listeners == true) { - if (p_listeners.size() > 0) { - Object[] l = p_listeners.getListeners(); - int ls = l.length; - for (int i = 0; i < ls; i++) { - IPropertyChangeListener pl = (IPropertyChangeListener) l[i]; - proxy.addPropertyChangeListener(pl); - dummy.removePropertyChangeListener(pl); // remove listener from dymmy so that we don't send notifications twice anymore - } - } - } - if (set_p_accelerator == true) { - proxy.setAccelerator(p_accelerator); - } - if (set_p_actionDefinitionId == true) { - if (p_actionDefinitionId != null) { - proxy.setActionDefinitionId(p_actionDefinitionId); - } - } - if (set_p_checked == true) { - proxy.setChecked(p_checked); - } - if (set_p_disabledImage == true) { - if (p_disabledImage != null) { - proxy.setDisabledImageDescriptor(p_disabledImage); - } - } - if (set_p_enabled == true) { - proxy.setEnabled(p_enabled); - } - if (set_p_helpListener == true) { - if (p_helpListener != null) { - proxy.setHelpListener(p_helpListener); - } - } - if (set_p_hoverImage == true) { - if (p_hoverImage != null) { - proxy.setHoverImageDescriptor(p_hoverImage); - } - } - if (set_p_id == true) { - if (p_id != null) { - proxy.setId(p_id); - } - } - if (set_p_image == true) { - if (p_image != null) { - proxy.setImageDescriptor(p_image); - } - } - if (set_p_text == true) { - if (p_text != null) { - proxy.setText(p_text); - } - } - if (set_p_toolTipText == true) { - if (p_toolTipText != null) { - proxy.setToolTipText(p_toolTipText); - } - } - if (set_p_targetEditor == true) { - if (p_targetEditor != null) { - if (proxy instanceof IExtendedEditorAction) { - ((IExtendedEditorAction)proxy).setActiveExtendedEditor(p_targetEditor); - } - } - } - } - } - } - - public boolean isRealized() { - return (proxy != null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.IUpdate#update() - */ - public void update() { - // don't realize class. - // realize(); - if ((proxy != null) && (proxy instanceof IUpdate)) { - ((IUpdate) proxy).update(); - } - } - - /** - * get a real action class - */ - public IAction getAction() { - realize(); - return proxy; - } - - - /** - * These are Actions's constructors - */ - ExtendedEditorActionProxyForDelayLoading() { - super(); - } - public ExtendedEditorActionProxyForDelayLoading(final IConfigurationElement element, final String classAttribute) { - super(); - this.element = element; - this.classAttribute = classAttribute; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/IExtendedEditorActionProxyForDelayLoading.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/IExtendedEditorActionProxyForDelayLoading.java deleted file mode 100644 index 0152cbe899..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/IExtendedEditorActionProxyForDelayLoading.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - -import org.eclipse.jface.action.IAction; - - -public interface IExtendedEditorActionProxyForDelayLoading { - public IAction getAction(); - public boolean isRealized(); - public void realize(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ImageUtil.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ImageUtil.java deleted file mode 100644 index b4ec6938ff..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/ImageUtil.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - - - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; -import org.osgi.framework.Bundle; - -public class ImageUtil { - - - /** - * Convenience Method. Returns an ImageDescriptor whose path, relative to - * the plugin containing the <code>extension</code> is - * <code>subdirectoryAndFilename</code>. If there isn't any value - * associated with the name then <code>null - * </code> is returned. - * - * This method is convenience and only intended for use by the workbench - * because it explicitly uses the workbench's registry for - * caching/retrieving images from other extensions -- other plugins must - * user their own registry. This convenience method is subject to removal. - * - * Note: subdirectoryAndFilename must not have any leading "." or path - * separators / or \ ISV's should use icons/mysample.gif and not - * ./icons/mysample.gif - * - * Note: This consults the plugin for extension and obtains its - * installation location. all requested images are assumed to be in a - * directory below and relative to that plugins installation directory. - */ - public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String subdirectoryAndFilename) { - String pluginId = extension.getNamespace(); - Bundle bundle = Platform.getBundle(pluginId); - return getImageDescriptorFromBundle(bundle, subdirectoryAndFilename); - } - - /** - * Convenience Method. Return an ImageDescriptor whose path relative to - * the plugin described by <code>bundle</code> is - * <code>subdirectoryAndFilename</code>. Returns <code>null</code> if - * no image could be found. - * - * This method is convenience and only intended for use by the workbench - * because it explicitly uses the workbench's registry for - * caching/retrieving images from other extensions -- other plugins must - * user their own registry. This convenience method is subject to removal. - * - * Note: subdirectoryAndFilename must not have any leading "." or path - * separators / or \ ISV's should use icons/mysample.gif and not - * ./icons/mysample.gif - * - * Note: This consults the plugin for extension and obtains its - * installation location. all requested images are assumed to be in a - * directory below and relative to that plugins installation directory. - */ - public static ImageDescriptor getImageDescriptorFromBundle(Bundle bundle, String subdirectoryAndFilename) { - - URL path = bundle.getEntry("/"); //$NON-NLS-1$ - URL fullPathString = null; - try { - fullPathString = new URL(path, subdirectoryAndFilename); - return ImageDescriptor.createFromURL(fullPathString); - } catch (MalformedURLException e) { - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/RegistryReader.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/RegistryReader.java deleted file mode 100644 index bd444ce8e6..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/extension/RegistryReader.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.extension; - - - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IPluginRegistry; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.util.Sorter; - - -/** - * Template implementation of a registry reader that creates objects - * representing registry contents. Typically, an extension contains one - * element, but this reader handles multiple elements per extension. - * - * To start reading the extensions from the registry for an extension point, - * call the method <code>readRegistry</code>. - * - * To read children of an IConfigurationElement, call the method - * <code>readElementChildren</code> from your implementation of the method - * <code>readElement</code>, as it will not be done by default. - */ -public abstract class RegistryReader { - - - protected static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$ - - /** - * The constructor. - */ - protected RegistryReader() { - } - - /** - * This method extracts description as a subelement of the given element. - * - * @return description string if defined, or empty string if not. - */ - protected String getDescription(IConfigurationElement config) { - IConfigurationElement[] children = config.getChildren(TAG_DESCRIPTION); - if (children.length >= 1) { - return children[0].getValue(); - } - return ""; //$NON-NLS-1$ - } - - /** - * Logs the error in the workbench log using the provided text and the - * information in the configuration element. - */ - protected void logError(IConfigurationElement element, String text) { - IExtension extension = element.getDeclaringExtension(); - StringBuffer buf = new StringBuffer(); - buf.append("Plugin " + extension.getNamespace() + ", extension " + extension.getExtensionPointUniqueIdentifier()); //$NON-NLS-2$//$NON-NLS-1$ - buf.append("\n" + text); //$NON-NLS-1$ - Logger.log(Logger.ERROR, buf.toString()); - } - - /** - * Logs a very common registry error when a required attribute is missing. - */ - protected void logMissingAttribute(IConfigurationElement element, String attributeName) { - logError(element, "Required attribute '" + attributeName + "' not defined"); //$NON-NLS-2$//$NON-NLS-1$ - } - - /** - * Logs a registry error when the configuration element is unknown. - */ - protected void logUnknownElement(IConfigurationElement element) { - logError(element, "Unknown extension tag found: " + element.getName()); //$NON-NLS-1$ - } - - /** - * Apply a reproducable order to the list of extensions provided, such - * that the order will not change as extensions are added or removed. - */ - protected IExtension[] orderExtensions(IExtension[] extensions) { - // By default, the order is based on plugin id sorted - // in ascending order. The order for a plugin providing - // more than one extension for an extension point is - // dependent in the order listed in the XML file. - Sorter sorter = new Sorter() { - public boolean compare(Object extension1, Object extension2) { - String s1 = ((IExtension) extension1).getNamespace().toUpperCase(); - String s2 = ((IExtension) extension2).getNamespace().toUpperCase(); - //Return true if elementTwo is 'greater than' elementOne - return s2.compareTo(s1) > 0; - } - }; - - Object[] sorted = sorter.sort(extensions); - IExtension[] sortedExtension = new IExtension[sorted.length]; - System.arraycopy(sorted, 0, sortedExtension, 0, sorted.length); - return sortedExtension; - } - - /** - * Implement this method to read element's attributes. If children should - * also be read, then implementor is responsible for calling - * <code>readElementChildren</code>. Implementor is also responsible - * for logging missing attributes. - * - * @return true if element was recognized, false if not. - */ - protected abstract boolean readElement(IConfigurationElement element); - - /** - * Read the element's children. This is called by the subclass' - * readElement method when it wants to read the children of the element. - */ - protected void readElementChildren(IConfigurationElement element) { - readElements(element.getChildren()); - } - - /** - * Read each element one at a time by calling the subclass implementation - * of <code>readElement</code>. - * - * Logs an error if the element was not recognized. - */ - protected void readElements(IConfigurationElement[] elements) { - for (int i = 0; i < elements.length; i++) { - if (!readElement(elements[i])) - logUnknownElement(elements[i]); - } - } - - /** - * Read one extension by looping through its configuration elements. - */ - protected void readExtension(IExtension extension) { - readElements(extension.getConfigurationElements()); - } - - /** - * @deprecated use readRegistry(IExtensionRegistry registry, String pluginId, String extensionPoint) - */ - protected void readRegistry(IPluginRegistry registry, String pluginId, String extensionPoint) { - IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPoint); - if (point != null) { - IExtension[] extensions = point.getExtensions(); - extensions = orderExtensions(extensions); - for (int i = 0; i < extensions.length; i++) - readExtension(extensions[i]); - } - } - - /** - * Start the registry reading process using the supplied plugin ID and - * extension point. - */ - protected void readRegistry(IExtensionRegistry registry, String pluginId, String extensionPoint) { - IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPoint); - if (point != null) { - IExtension[] extensions = point.getExtensions(); - extensions = orderExtensions(extensions); - for (int i = 0; i < extensions.length; i++) - readExtension(extensions[i]); - } - } -} |