diff options
author | cbridgha | 2004-11-24 04:07:56 +0000 |
---|---|---|
committer | cbridgha | 2004-11-24 04:07:56 +0000 |
commit | 90b9b6610ae2ee1aba64e2ea5962a7ca00322310 (patch) | |
tree | 28383c498c9828de122be30b074b735f70c5555c /plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui | |
parent | cb3ff303368ebb2c1d02d87e61cf43e37c9a8654 (diff) | |
download | webtools.common-90b9b6610ae2ee1aba64e2ea5962a7ca00322310.tar.gz webtools.common-90b9b6610ae2ee1aba64e2ea5962a7ca00322310.tar.xz webtools.common-90b9b6610ae2ee1aba64e2ea5962a7ca00322310.zip |
internal rename
Diffstat (limited to 'plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui')
58 files changed, 7856 insertions, 0 deletions
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/CommonUIPluginConstants.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/CommonUIPluginConstants.java new file mode 100644 index 000000000..1aaaa3621 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/CommonUIPluginConstants.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Jan 16, 2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +/** + * @author blancett + * + * To change the template for this generated type comment go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +public interface CommonUIPluginConstants { + public static final String PLUGIN_ID = "org.eclipse.wst.common.frameworks.internal.ui"; //$NON-NLS-1$ + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtendableWizard.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtendableWizard.java new file mode 100644 index 000000000..65d8c71fe --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtendableWizard.java @@ -0,0 +1,221 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Jan 16, 2004 + * + * To change the template for this generated file go to Window - Preferences - Java - Code Generation - Code and + * Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.wst.common.frameworks.internal.operations.FailSafeComposedOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; +import org.eclipse.wst.common.frameworks.internal.ui.WTPWizard; + +import com.ibm.wtp.common.logger.proxy.Logger; + +/** + * @author blancett + * + * To change the template for this generated type comment go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +public abstract class ExtendableWizard extends WTPWizard { + + private IExtendedWizardPage[] extendedPages = null; + private IExtendedPageHandler[] extendedPageHandlers = null; + + public ExtendableWizard(WTPOperationDataModel model) { + super(model); + } + + public ExtendableWizard() { + super(); + } + + /** + * + * @return the wizard ID that clients should extend to add to this wizard + */ + public abstract String getWizardID(); + + /** + * Add all wizard pages that come from this wizard + */ + protected abstract void doAddPages(); + + /** + * Create the operation that should be used by this wizard + * + * @return + */ + protected abstract WTPOperation createBaseOperation(); + + private void addExtensionPages() { + String wizardID = getWizardID(); + WizardPageElement wizElement = null; + if (wizardID == null) + return; + WizardPageElement[] elements = WizardPageExtensionManager.getInstance().getPageElements(getWizardID()); + IExtendedWizardPage[] extendedPagesLocal = null; + IExtendedPageHandler extendedPageHandler = null; + List extendedPagesList = new ArrayList(); + List extendedPageHandlerList = new ArrayList(); + for (int i = 0; i < elements.length; i++) { + wizElement = elements[i]; + try { + extendedPagesLocal = wizElement.createPageGroup(model); + if (null != extendedPagesLocal) { + for (int j = 0; j < extendedPagesLocal.length; j++) { + addPage(extendedPagesLocal[j]); + extendedPagesList.add(extendedPagesLocal[j]); + } + } + extendedPageHandler = wizElement.createPageHandler(model); + if (null != extendedPageHandler && !extendedPageHandlerList.contains(extendedPageHandler)) { + extendedPageHandlerList.add(extendedPageHandler); + } + } catch (RuntimeException runtime) { + Logger.getLogger().logError(WTPCommonUIResourceHandler.getString("ExtendableWizard_UI_0", new Object[]{wizElement.getPluginID(), wizElement.pageGroupID})); //$NON-NLS-1$ + Logger.getLogger().logError(runtime); + } + } + extendedPages = new IExtendedWizardPage[extendedPagesList.size()]; + for (int i = 0; i < extendedPages.length; i++) { + extendedPages[i] = (IExtendedWizardPage) extendedPagesList.get(i); + } + extendedPageHandlers = new IExtendedPageHandler[extendedPageHandlerList.size()]; + for (int i = 0; i < extendedPageHandlers.length; i++) { + extendedPageHandlers[i] = (IExtendedPageHandler) extendedPageHandlerList.get(i); + } + + } + + public boolean canFinish() { + if (!super.canFinish()) { + return false; + } + for (int i = 0; null != extendedPages && i < extendedPages.length; i++) { + if (!extendedPages[i].canPageFinish()) { + return false; + } + } + return true; + } + + protected final WTPOperation createOperation() { + WTPOperation baseOperation = createBaseOperation(); + FailSafeComposedOperation composedOperation = null; + for (int i = 0; null != extendedPages && i < extendedPages.length; i++) { + WTPOperation op = extendedPages[i].createOperation(); + if (op != null) { + if (composedOperation == null) { + composedOperation = new FailSafeComposedOperation(); + composedOperation.append(baseOperation); + } + composedOperation.append(op); + } + } + return composedOperation != null ? composedOperation : baseOperation; + } + + /** + * The <code>Wizard</code> implementation of this <code>IWizard</code> method creates all + * the pages controls using <code>IDialogPage.createControl</code>. Subclasses should + * reimplement this method if they want to delay creating one or more of the pages lazily. The + * framework ensures that the contents of a page will be created before attempting to show it. + */ + public void createPageControls(Composite pageContainer) { + IWizardPage[] pages = getPages(); + // the default behavior is to create all the pages controls + for (int i = 0; i < pages.length; i++) { + if (isExtendedPage(pages[i])) { + try { + pages[i].createControl(pageContainer); + } catch (Exception e) { + Logger.getLogger().logError(e); + continue; + } + } else { + pages[i].createControl(pageContainer); + } + // page is responsible for ensuring the created control is + // accessable + // via getControl. + Assert.isNotNull(pages[i].getControl()); + } + } + + protected boolean isExtendedPage(IWizardPage page) { + for (int i = 0; null != extendedPages && i < extendedPages.length; i++) { + if (page == extendedPages[i]) { + return true; + } + } + return false; + } + + + public final void addPages() { + doAddPages(); + addExtensionPages(); + } + + public IWizardPage getNextPage(IWizardPage page) { + IWizardPage expectedPage = super.getNextPage(page); + String expectedPageName = (null == expectedPage) ? null : expectedPage.getName(); + String nextPageName = null; + for (int i = 0; null != extendedPageHandlers && i < extendedPageHandlers.length; i++) { + nextPageName = extendedPageHandlers[i].getNextPage(page.getName(), expectedPageName); + if (null != nextPageName) { + if (nextPageName.equals(IExtendedPageHandler.SKIP_PAGE)) { + return getNextPage(expectedPage); + } else if (nextPageName.startsWith(IExtendedPageHandler.PAGE_AFTER)) { + String tempNextPageName = nextPageName.substring(IExtendedPageHandler.PAGE_AFTER.length()); + IWizardPage tempNextPage = getPage(tempNextPageName); + return null == tempNextPage ? null : super.getNextPage(tempNextPage); + } + return getPage(nextPageName); + } + } + return expectedPage; + } + + public IWizardPage getPreviousPage(IWizardPage page) { + IWizardPage expectedPage = super.getPreviousPage(page); + String expectedPageName = (null == expectedPage) ? null : expectedPage.getName(); + String previousPageName = null; + for (int i = 0; null != extendedPageHandlers && i < extendedPageHandlers.length; i++) { + previousPageName = extendedPageHandlers[i].getPreviousPage(page.getName(), expectedPageName); + if (null != previousPageName) { + if (previousPageName.equals(IExtendedPageHandler.SKIP_PAGE)) { + return getPreviousPage(expectedPage); + } else if (previousPageName.startsWith(IExtendedPageHandler.PAGE_AFTER)) { + String tempPreviousPageName = previousPageName.substring(IExtendedPageHandler.PAGE_AFTER.length()); + IWizardPage tempPreviousPage = getPage(tempPreviousPageName); + return null == tempPreviousPage ? null : super.getPreviousPage(tempPreviousPage); + } + return getPage(previousPageName); + } + } + return expectedPage; + } + + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtendedWizardPage.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtendedWizardPage.java new file mode 100644 index 000000000..43afffb4a --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtendedWizardPage.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Jan 19, 2004 + * + * To change the template for this generated file go to Window - Preferences - + * Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + + +import org.eclipse.core.internal.runtime.Assert; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; +import org.eclipse.wst.common.frameworks.internal.ui.WTPWizardPage; + + +/** + * @author jsholl + * + * To change the template for this generated type comment go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +public abstract class ExtendedWizardPage extends WTPWizardPage implements IExtendedWizardPage { + + private String id; + + protected ExtendedWizardPage(WTPOperationDataModel model, String pageName) { + super(model, pageName); + } + + /** + * @return Returns the id. + */ + public final String getGroupID() { + return id; + } + + /** + * Will only set the id once. Further invocations will be ignored. + * + * @param id + * The id to set. + */ + public final void setGroupID(String id) { + Assert.isTrue(this.id == null, WTPCommonUIResourceHandler.getString("ExtendedWizardPage_ERROR_0")); //$NON-NLS-1$ + Assert.isNotNull(id, WTPCommonUIResourceHandler.getString("ExtendedWizardPage_ERROR_1")); //$NON-NLS-1$ + this.id = id; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtensibleViewRegistry.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtensibleViewRegistry.java new file mode 100644 index 000000000..efff49668 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/ExtensibleViewRegistry.java @@ -0,0 +1,173 @@ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.common.frameworks.internal.ui.WTPUIPlugin; + +import com.ibm.wtp.common.RegistryReader; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2001, 2002 - All + * Rights Reserved. US Government Users Restricted Rights - Use, duplication or + * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. + */ + +/** + * @author mdelder + */ +public class ExtensibleViewRegistry extends RegistryReader { + + private static ExtensibleViewRegistry INSTANCE = null; + private Map extendedViewerMap = null; + private Map descriptorMap = null; + + protected interface Elements { + public static final String EXTENDED_VIEWER = "extendedViewer"; //$NON-NLS-1$ + public static final String VIEWER_ID = "viewerID"; //$NON-NLS-1$ + public static final String PARENT_VIEWER_ID = "parentViewerID"; //$NON-NLS-1$ + public static final String FACTORY_CLASS = "factoryClass"; //$NON-NLS-1$ + public static final String ICON = "icon"; //$NON-NLS-1$ + public static final String LABEL = "label"; //$NON-NLS-1$ + public static final String FUNCTION_GROUP_ID = "functionGroupID"; //$NON-NLS-1$ + } + + /** + * + */ + private ExtensibleViewRegistry() { + super(WTPUIPlugin.PLUGIN_ID, WTPUIPlugin.EXTENDED_VIEWER_REGISTRY_EXTENSION_POINT); + } + + public static ExtensibleViewRegistry getInstance() { + if (INSTANCE == null) { + INSTANCE = new ExtensibleViewRegistry(); + INSTANCE.readRegistry(); + } + return INSTANCE; + } + + public Descriptor getDescriptor(String viewerID) { + return (Descriptor) getDescriptorMap().get(viewerID); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.registry.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement) + */ + public boolean readElement(IConfigurationElement element) { + if (element.getName().equals(Elements.EXTENDED_VIEWER)) { + Descriptor descriptor = new Descriptor(element); + getDescriptorMap().put(descriptor.getViewerID(), descriptor); + return true; + } + return false; + } + + /** + * @return Returns the extendedViewerMap. + */ + protected Map getExtendedViewerMap() { + if (extendedViewerMap == null) + extendedViewerMap = new HashMap(); + return extendedViewerMap; + } + + /** + * @return Returns the descriptorMap. + */ + protected Map getDescriptorMap() { + if (descriptorMap == null) + descriptorMap = new HashMap(); + return descriptorMap; + } + + public class Descriptor { + + private String viewerID = null; + private String parentViewerID = null; + private String factoryClass = null; + private String icon = null; + private String label = null; + private String functionGroupID = null; + + private String toStringCache = null; + private IConfigurationElement element = null; + + /** + * + */ + public Descriptor(IConfigurationElement element) { + this.element = element; + + this.viewerID = this.element.getAttribute(ExtensibleViewRegistry.Elements.VIEWER_ID); + this.parentViewerID = this.element.getAttribute(ExtensibleViewRegistry.Elements.PARENT_VIEWER_ID); + this.factoryClass = this.element.getAttribute(ExtensibleViewRegistry.Elements.FACTORY_CLASS); + this.icon = this.element.getAttribute(ExtensibleViewRegistry.Elements.ICON); + this.label = this.element.getAttribute(ExtensibleViewRegistry.Elements.LABEL); + this.functionGroupID = this.element.getAttribute(ExtensibleViewRegistry.Elements.FUNCTION_GROUP_ID); + } + + public IExtensibleViewFactory createFactoryInstance() { + IExtensibleViewFactory factoryInstance = null; + try { + factoryInstance = (IExtensibleViewFactory) this.element.createExecutableExtension(getFactoryClass()); + } catch (CoreException e) { + WTPUIPlugin.getLogger().logError(e); + } + return factoryInstance; + } + + /** + * @return Returns the factoryClass. + */ + public String getFactoryClass() { + return factoryClass; + } + + /** + * @return Returns the functionGroupID. + */ + public String getFunctionGroupID() { + return functionGroupID; + } + + /** + * @return Returns the icon. + */ + public String getIcon() { + return icon; + } + + /** + * @return Returns the label. + */ + public String getLabel() { + return label; + } + + /** + * @return Returns the parentViewerID. + */ + public String getParentViewerID() { + return parentViewerID; + } + + /** + * @return Returns the viewerID. + */ + public String getViewerID() { + return viewerID; + } + + public String toString() { + if (toStringCache == null) + toStringCache = "ExtensibleViewRegistry.Info [viewerID=\"" + getViewerID() + "\",parentViewerID=\"" + getParentViewerID() + "\",factoryClass=" + getFactoryClass() + "\",functionGroupID=\"" + getFunctionGroupID() + "\"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + return toStringCache; + } + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IActionWTPOperation.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IActionWTPOperation.java new file mode 100644 index 000000000..4427ce85a --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IActionWTPOperation.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 10, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.jdt.ui.actions.SelectionDispatchAction; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.wst.common.frameworks.internal.operations.NonConflictingRule; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; +import org.eclipse.wst.common.frameworks.internal.ui.WTPUIPlugin; + + +/** + * @author mdelder + * + */ +public class IActionWTPOperation extends WTPOperation { + + private static final ISchedulingRule nonconflictingRule = new NonConflictingRule(); + + boolean done; + + /** + * + */ + public IActionWTPOperation() { + super(); + } + + /** + * @param operationDataModel + */ + public IActionWTPOperation(WTPOperationDataModel operationDataModel) { + super(operationDataModel); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#execute(org.eclipse.core.runtime.IProgressMonitor) + */ + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + + final IAction action = (IAction) getOperationDataModel().getProperty(IActionWTPOperationDataModel.IACTION); + if (action == null) + throw new CoreException(new Status(IStatus.WARNING, WTPUIPlugin.PLUGIN_ID, 0, WTPCommonUIResourceHandler.getString("IActionWTPOperation_UI_0"), null)); //$NON-NLS-1$ + + final ISelection selection = (IStructuredSelection) getOperationDataModel().getProperty(IActionWTPOperationDataModel.ISTRUCTURED_SELECTION); + /* + * ISelectionProvider selectionProvider = (ISelectionProvider) + * getOperationDataModel().getProperty(IActionWTPOperationDataModel.ISTRUCTURED_SELECTION); + */ + + /* + * if(selectionProvider != null) selection = (selection != null) ? selection : + * selectionProvider.getSelection(); + */ + Shell shell = (Shell) getOperationDataModel().getProperty(IActionWTPOperationDataModel.SHELL); + done = false; + + Runnable executeAction = new Runnable() { + + public void run() { + try { + if (action instanceof IActionDelegate) { + ((IActionDelegate) action).selectionChanged(action, selection); + ((IActionDelegate) action).run(action); + } else if (action instanceof IViewActionDelegate) { + ((IViewActionDelegate) action).selectionChanged(action, selection); + ((IActionDelegate) action).run(action); + } else if (action instanceof SelectionDispatchAction) { + ((SelectionDispatchAction) action).update(selection); + ((SelectionDispatchAction) action).run(); + } /* + * else if (action instanceof ISelectionChangedListener) { + * ((ISelectionChangedListener)action).selectionChanged(new + * SelectionChangedEvent(selectionProvider, selection)); action.run(); } + */ + + + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + getOperationDataModel().dispose(); + done = true; + } + } + }; + + Display current = Display.getCurrent(); + if (current != null) { + executeAction.run(); + } else { + shell.getDisplay().asyncExec(executeAction); + } + + while (!done) { + Thread.sleep(100); + } + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#getSchedulingRule() + */ + protected ISchedulingRule getSchedulingRule() { + return nonconflictingRule; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IActionWTPOperationDataModel.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IActionWTPOperationDataModel.java new file mode 100644 index 000000000..7bec17b56 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IActionWTPOperationDataModel.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 10, 2004 + * + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.jdt.ui.actions.SelectionDispatchAction; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + + + +/** + * @author mdelder + * + */ +public class IActionWTPOperationDataModel extends WTPOperationDataModel implements IPropertyChangeListener { + + public static final String IACTION = "IActionWTPOperationDataModel.IACTION"; //$NON-NLS-1$ + public static final String ISTRUCTURED_SELECTION = "IActionWTPOperationDataModel.ISTRUCTURED_SELECTION"; //$NON-NLS-1$ + public static final String ISELECTION_PROVIDER = "IActionWTPOperationDataModel.ISELECTION_PROVIDER"; //$NON-NLS-1$ + public static final String SHELL = "IActionWTPOperationDataModel.SHELL"; //$NON-NLS-1$ + public static final String ACTION_RAN_SUCCESSFULLY = "IActionWTPOperationDataModel.ACTION_RAN_SUCCESSFULLY"; //$NON-NLS-1$ + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#initValidBaseProperties() + */ + protected void initValidBaseProperties() { + super.initValidBaseProperties(); + addValidBaseProperty(IACTION); + addValidBaseProperty(ISTRUCTURED_SELECTION); + addValidBaseProperty(ISELECTION_PROVIDER); + addValidBaseProperty(SHELL); + addValidBaseProperty(ACTION_RAN_SUCCESSFULLY); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#getDefaultOperation() + */ + public WTPOperation getDefaultOperation() { + return new IActionWTPOperation(this); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#isResultProperty(java.lang.String) + */ + protected boolean isResultProperty(String propertyName) { + if (ACTION_RAN_SUCCESSFULLY.equals(propertyName)) + return true; + return super.isResultProperty(propertyName); + } + + /** + * @param action + * @param selection + * @param provider + * @return + */ + public static WTPOperationDataModel createDataModel(IActionDelegate action, IStructuredSelection selection, ISelectionProvider provider, Shell shell) { + WTPOperationDataModel dataModel = new IActionWTPOperationDataModel(); + dataModel.setProperty(IACTION, action); + dataModel.setProperty(ISTRUCTURED_SELECTION, selection); + dataModel.setProperty(ISELECTION_PROVIDER, provider); + dataModel.setProperty(SHELL, shell); + return dataModel; + } + + /** + * @param action + * @param selection + * @param provider + * @return + */ + public static WTPOperationDataModel createDataModel(SelectionDispatchAction action, IStructuredSelection selection, ISelectionProvider provider, Shell shell) { + WTPOperationDataModel dataModel = new IActionWTPOperationDataModel(); + dataModel.setProperty(IACTION, action); + dataModel.setProperty(ISTRUCTURED_SELECTION, selection); + dataModel.setProperty(ISELECTION_PROVIDER, provider); + dataModel.setProperty(SHELL, shell); + return dataModel; + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#doSetProperty(java.lang.String, + * java.lang.Object) + */ + protected boolean doSetProperty(String propertyName, Object propertyValue) { + + + if (IACTION.equals(propertyName)) { + + IAction oldAction = (IAction) getProperty(IACTION); + if (oldAction != null) + oldAction.removePropertyChangeListener(this); + + boolean result = super.doSetProperty(propertyName, propertyValue); + + IAction newAction = (IAction) getProperty(IACTION); + if (newAction != null) + newAction.addPropertyChangeListener(this); + + return result; + } + return super.doSetProperty(propertyName, propertyValue); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#getDefaultProperty(java.lang.String) + */ + protected Object getDefaultProperty(String propertyName) { + if (ACTION_RAN_SUCCESSFULLY.equals(propertyName)) + return Boolean.TRUE; + return super.getDefaultProperty(propertyName); + } + + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#dispose() + */ + public void dispose() { + super.dispose(); + IAction action = (IAction) getProperty(IACTION); + if (action != null) + action.removePropertyChangeListener(this); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + IAction action = (IAction) getProperty(IACTION); + if (action == null || action != event.getSource()) + return; + // TODO MDE Implement this method + //notifyListeners(event.getProperty(), 0, event.getOldValue(), event.getNewValue()); + if (IAction.RESULT.equals(event.getProperty())) { + setProperty(ACTION_RAN_SUCCESSFULLY, event.getNewValue()); + } + + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtendedPageHandler.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtendedPageHandler.java new file mode 100644 index 000000000..53319150e --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtendedPageHandler.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Apr 8, 2004 + * + * To change the template for this generated file go to Window - Preferences - + * Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +/** + * @author jsholl + * + * To change the template for this generated type comment go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +public interface IExtendedPageHandler { + + /** + * return this as the page name if the expectedNextPageName or expectedPreviousPageName should + * be skipped + */ + public static final String SKIP_PAGE = "IExtendedPageHandler.SKIP_PAGE"; //$NON-NLS-1$ + + /** + * prefix this string with the name of the page which occurs before the page that should be + * returned. E.G. suppose your page contributions know about pages A, B and C, and you want the + * to skip pages B and C, when going to the next page from A. To do this, return PAGE_AFTER+C. + * The framework will then ask the wizard for the page that normally comes after page C. + * PAGE_BEFORE works similarly. + */ + public static final String PAGE_AFTER = "IExtendedPageHandler.PAGE_AFTER"; //$NON-NLS-1$ + + /** + * same as PAGE_AFTER, except for returing the page before. + */ + public static final String PAGE_BEFORE = "IExtendedPageHandler.PAGE_BEFORE"; //$NON-NLS-1$ + + /** + * Return the name of the page that should be next + * + * @param currentPageName + * the page the wizard is currently on + * @param expectedNextPageName + * the page that would normally be next + * @return + */ + public String getNextPage(String currentPageName, String expectedNextPageName); + + /** + * Return the name of the page that should be previous + * + * @param currentPageName + * the page the wizard is currently on + * @param expectedNextPageName + * the page that would normally be previous + * @return + */ + public String getPreviousPage(String currentPageName, String expectedPreviousPageName); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtendedWizardPage.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtendedWizardPage.java new file mode 100644 index 000000000..49057107b --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtendedWizardPage.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Jan 21, 2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; + +/** + * @author jsholl + * + * To change the template for this generated type comment go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +public interface IExtendedWizardPage extends IWizardPage { + + WTPOperation createOperation(); + + boolean canPageFinish(); + + String getGroupID(); + + void setGroupID(String id); + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtensibleViewFactory.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtensibleViewFactory.java new file mode 100644 index 000000000..b144f92d4 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IExtensibleViewFactory.java @@ -0,0 +1,17 @@ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + +/** + * @author mdelder + */ +public interface IExtensibleViewFactory { + + + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IOperationNode.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IOperationNode.java new file mode 100644 index 000000000..747b5ca80 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/IOperationNode.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 5, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public interface IOperationNode { + + public IOperationNode[] getChildren(); + + public boolean isChecked(); + + /** + * Same as calling setChecked(checked, true) + * + * @param checked + */ + public void setChecked(boolean checked); + + public String getName(); + + public String getDescription(); + + public IOperationNode getParent(); + + /** + * @return + */ + public boolean isAlwaysExecute(); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/MasterDescriptor.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/MasterDescriptor.java new file mode 100644 index 000000000..436f531fc --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/MasterDescriptor.java @@ -0,0 +1,112 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +/* + * Created on May 5, 2004 + * + * TODO To change the template for this generated file go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.Iterator; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.internal.ActionExpression; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; + +import com.ibm.wtp.common.logger.proxy.Logger; + +public class MasterDescriptor extends SlaveDescriptor { + + public static final String MASTER_OPERATION = "masterOperation"; //$NON-NLS-1$ + + public static final String ATT_EXTENDED_OPERATION_ID = "extendedGenericId"; //$NON-NLS-1$ + + public static final String SELECTION_ENABLEMENT = "selectionEnablement"; //$NON-NLS-1$ + + private static final String ATT_POPULATOR_CLASS = "populatorClass"; //$NON-NLS-1$ + + private static final String ATT_ALWAYS_EXECUTE = "alwaysExecute"; //$NON-NLS-1$ + + private ActionExpression enablement; + + private String extendedOperationId; + + private WTPOperationDataModelUICreator creator; + + private boolean alwaysExecute; + + + public MasterDescriptor(IConfigurationElement element) { + super(element); + init(); + } + + private void init() { + this.extendedOperationId = getElement().getAttribute(ATT_EXTENDED_OPERATION_ID); + if (null == extendedOperationId) + Logger.getLogger().log(WTPCommonUIResourceHandler.getString("MasterDescriptor_UI_0", new Object[]{ATT_EXTENDED_OPERATION_ID})); //$NON-NLS-1$ + + + if (Boolean.valueOf(getElement().getAttribute(ATT_ALWAYS_EXECUTE)).booleanValue()) + alwaysExecute = true; + + IConfigurationElement[] elements = getElement().getChildren(SELECTION_ENABLEMENT); + if (elements.length == 1) + this.enablement = new ActionExpression(elements[0]); + else + Logger.getLogger().log(WTPCommonUIResourceHandler.getString("MasterDescriptor_ERROR_2")); //$NON-NLS-1$ + + } + + /** + * @return Returns the extendedOperationId. + */ + public String getExtendedOperationId() { + return extendedOperationId; + } + + + public boolean isEnabledFor(IStructuredSelection selection) { + if (getEnablement() == null) + return true; + boolean result = false; + for (Iterator itr = selection.iterator(); itr.hasNext();) { + result = getEnablement().isEnabledFor(itr.next()); + if (result) + break; + } + return result; + } + + public WTPOperationDataModelUICreator getCreator() { + if (creator == null) { + try { + creator = (WTPOperationDataModelUICreator) getElement().createExecutableExtension(ATT_POPULATOR_CLASS); + } catch (CoreException e) { + Logger.getLogger().logError(e); + } + } + return creator; + } + + protected ActionExpression getEnablement() { + return enablement; + } + + + /** + * @return Returns the alwaysExecute. + */ + public boolean isAlwaysExecute() { + return alwaysExecute; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PasteActionOperation.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PasteActionOperation.java new file mode 100644 index 000000000..c09631c8e --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PasteActionOperation.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Aug 27, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + + +/** + * @author mdelder + * + */ +public class PasteActionOperation extends IActionWTPOperation { + + public PasteActionOperation() { + super(); + } + + public PasteActionOperation(PasteActionOperationDataModel opMdl) { + super(opMdl); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PasteActionOperationDataModel.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PasteActionOperationDataModel.java new file mode 100644 index 000000000..dca2618c9 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PasteActionOperationDataModel.java @@ -0,0 +1,293 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Aug 26, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.ui.actions.SelectionDispatchAction; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + +//TODO This class has code commented out to get compile errors cleanup for Eclipse 3.1 as the internal classes ReorgResult and PasteActions have been removed in 3.1 - VKB + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Style - Code Templates + * + */ +public class PasteActionOperationDataModel extends IActionWTPOperationDataModel { + + /** + * Result Property. A java.util.Map of old-types-to-new-types + */ + public static final String REFACTORED_RESOURCES = "PasteActionOperationDataModel.REFACTORED_RESOURCES"; //$NON-NLS-1$ + public static final String DESTINATION = "PasteActionOperationDataModel.DESTINATION"; //$NON-NLS-1$ + private Map prepasteSnapshot = new HashMap(); + //TODO Needs Clean up of compile errors for Eclipse 3.1 - VKB + //private ReorgResult cachedResult; + + /** + * @param action + * @param selection + * @param provider + * @return + */ + public static WTPOperationDataModel createDataModel(IActionDelegate action, IStructuredSelection selection, ISelectionProvider provider, Shell shell) { + WTPOperationDataModel dataModel = new PasteActionOperationDataModel(); + dataModel.setProperty(IACTION, action); + dataModel.setProperty(ISTRUCTURED_SELECTION, selection); + dataModel.setProperty(ISELECTION_PROVIDER, provider); + dataModel.setProperty(SHELL, shell); + return dataModel; + } + + /** + * @param action + * @param selection + * @param provider + * @return + */ + public static WTPOperationDataModel createDataModel(SelectionDispatchAction action, IStructuredSelection selection, ISelectionProvider provider, Shell shell) { + WTPOperationDataModel dataModel = new PasteActionOperationDataModel(); + dataModel.setProperty(IACTION, action); + dataModel.setProperty(ISTRUCTURED_SELECTION, selection); + dataModel.setProperty(ISELECTION_PROVIDER, provider); + dataModel.setProperty(SHELL, shell); + return dataModel; + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.extension.ui.IActionWTPOperationDataModel#initValidBaseProperties() + */ + protected void initValidBaseProperties() { + super.initValidBaseProperties(); + addValidBaseProperty(REFACTORED_RESOURCES); + addValidBaseProperty(DESTINATION); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#getDefaultOperation() + */ + public WTPOperation getDefaultOperation() { + return new PasteActionOperation(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.extension.ui.IActionWTPOperationDataModel#isResultProperty(java.lang.String) + */ + protected boolean isResultProperty(String propertyName) { + if (REFACTORED_RESOURCES.equals(propertyName) || DESTINATION.equals(propertyName)) + return true; + return super.isResultProperty(propertyName); + } + + + /* + * (non-Javadoc) + * TODO Needs Clean up of compile errors for Eclipse 3.1 - VKB + * @see org.eclipse.wst.common.frameworks.internal.operation.extension.ui.IActionWTPOperationDataModel#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ +// public void propertyChange(PropertyChangeEvent event) { +// if (PasteAction.PASTE_PRE_NOTIFICATION.equals(event.getProperty())) { +// +// ReorgResult result = (ReorgResult) event.getNewValue(); +// updatePrepasteSnapshot(result); +// } else if (PasteAction.PASTE_RESULT_NOTIFICATION.equals(event.getProperty())) { +// //System.out.println("Caching result"); +// cachedResult = (ReorgResult) event.getNewValue(); +// } else if (IAction.RESULT.equals(event.getProperty()) && cachedResult != null) { +// //System.out.println("Applying cached result"); +// fillMapAsNecessary(cachedResult); +// +// Map refactorMap = cachedResult.getNameChanges(); +// setProperty(REFACTORED_RESOURCES, refactorMap); +// +// Object destination = cachedResult.getDestination(); +// if (cachedResult.getResourcesToCopy().length == 1) { +// if (cachedResult.getResourcesToCopy()[0].equals(destination)) +// destination = cachedResult.getResourcesToCopy()[0].getParent(); +// } else if (cachedResult.getJavaElementsToCopy().length == 1) { +// if (cachedResult.getJavaElementsToCopy()[0].equals(destination)) +// destination = cachedResult.getJavaElementsToCopy()[0].getParent(); +// } +// setProperty(DESTINATION, destination); +// cachedResult = null; +// +// } +// super.propertyChange(event); +// } + +// TODO Needs Clean up of compile errors for Eclipse 3.1 - VKB + +// protected void updatePrepasteSnapshot(ReorgResult result) { +// +// resetPrepasteSnapshot(); +// +// IContainer container = getContainerFromResult(result); +// if (container == null) +// return; +// +// IResource resourceExisting = null; +// +// IResource[] resources = result.getResourcesToCopy(); +// if (resources != null) { +// for (int i = 0; i < resources.length; i++) { +// resourceExisting = getCorrespondingFileOrFolder(resources[i], new Path(resources[i].getName()), container); +// if (resourceExisting.exists()) +// prepasteSnapshot.put(resourceExisting, new Long(resourceExisting.getModificationStamp())); +// } +// } +// +// IJavaElement[] elements = result.getJavaElementsToCopy(); +// if (elements != null) { +// for (int i = 0; i < elements.length; i++) { +// try { +// resourceExisting = getCorrespondingFileOrFolder(elements[i].getCorrespondingResource(), new Path(elements[i].getCorrespondingResource().getName()), container); +// if (resourceExisting != null && resourceExisting.exists()) +// prepasteSnapshot.put(resourceExisting, new Long(resourceExisting.getModificationStamp())); +// } catch (JavaModelException e) { +// } +// } +// } +// } + + /** + * + */ + private void resetPrepasteSnapshot() { + if (prepasteSnapshot == null) + prepasteSnapshot = new HashMap(); + else + prepasteSnapshot.clear(); + } + +// TODO Needs Clean up of compile errors for Eclipse 3.1 - VKB + +// protected void fillMapAsNecessary(ReorgResult result) { +// +// IContainer container = getContainerFromResult(result); +// +// if (container == null) +// return; +// +// /* +// * If you Ctrl+C -> Ctrl+V a Project, you get no pre-notification and the prepasteSnapshot +// * is null +// */ +// if (prepasteSnapshot == null) +// prepasteSnapshot = new HashMap(); +// +// Map nameChanges = result.getNameChanges(); +// +// IResource resourceExisting = null; +// +// IResource[] resources = result.getResourcesToCopy(); +// if (resources != null) { +// for (int i = 0; i < resources.length; i++) { +// resourceExisting = getCorrespondingFileOrFolder(resources[i], new Path(resources[i].getName()), container); +// +// if (prepasteSnapshot.containsKey(resourceExisting)) { +// Long timestamp = (Long) prepasteSnapshot.get(resourceExisting); +// if (timestamp.longValue() != resourceExisting.getModificationStamp()) +// nameChanges.put(resources[i], resourceExisting); +// } else +// nameChanges.put(resources[i], resourceExisting); +// } +// } +// +// IJavaElement[] elements = result.getJavaElementsToCopy(); +// if (elements != null) { +// for (int i = 0; i < elements.length; i++) { +// try { +// resourceExisting = getCorrespondingFileOrFolder(elements[i].getCorrespondingResource(), new Path(elements[i].getCorrespondingResource().getName()), container); +// +// if (prepasteSnapshot.containsKey(resourceExisting)) { +// Long timestamp = (Long) prepasteSnapshot.get(resourceExisting); +// if (timestamp.longValue() != resourceExisting.getModificationStamp()) +// nameChanges.put(elements[i].getCorrespondingResource(), resourceExisting); +// } else +// nameChanges.put(elements[i].getCorrespondingResource(), resourceExisting); +// } catch (JavaModelException e) { +// } +// } +// } +// resetPrepasteSnapshot(); +// } +// +// private IContainer getContainerFromResult(ReorgResult result) { +// +// Object destination = result.getDestination(); +// +// IContainer container = null; +// if (result.getDestination() instanceof IContainer) { +// container = (IContainer) destination; +// } else if (destination instanceof IJavaElement) { +// IJavaElement containerElement = (IJavaElement) destination; +// IPackageFragment fragment = null; +// IPackageFragmentRoot fragmentRoot = null; +// switch (containerElement.getElementType()) { +// case IJavaElement.PACKAGE_FRAGMENT : +// fragment = (IPackageFragment) containerElement; +// break; +// case IJavaElement.PACKAGE_FRAGMENT_ROOT : +// fragmentRoot = (IPackageFragmentRoot) containerElement; +// break; +// +// } +// try { +// if (fragmentRoot == null ^ fragment == null) { +// container = (fragmentRoot != null) ? (IContainer) fragmentRoot.getCorrespondingResource() : (IContainer) fragment.getCorrespondingResource(); +// } +// } catch (JavaModelException e1) { +// } +// } +// return container; +// } + + private IResource getCorrespondingFileOrFolder(IResource existing, IPath expectedPath, IContainer container) { + IResource resourceExisting = null; + switch (existing.getType()) { + case IResource.FOLDER : + resourceExisting = container.getFolder(expectedPath); + break; + case IResource.FILE : + resourceExisting = container.getFile(expectedPath); + break; + } + return resourceExisting; + } + + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PostPasteActionOperation.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PostPasteActionOperation.java new file mode 100644 index 000000000..644f68e73 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/PostPasteActionOperation.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Aug 27, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; + + + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Style - Code Templates + */ +public class PostPasteActionOperation extends WTPOperation { + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#execute(org.eclipse.core.runtime.IProgressMonitor) + */ + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + PasteActionOperationDataModel dataMdl = (PasteActionOperationDataModel) getOperationDataModel(); + + Map refactoredResourcesMap = (Map) dataMdl.getProperty(PasteActionOperationDataModel.REFACTORED_RESOURCES); + System.out.println(getClass().getName()); + System.out.println("Map:" + refactoredResourcesMap); //$NON-NLS-1$ + + Object destination = dataMdl.getProperty(PasteActionOperationDataModel.DESTINATION); + System.out.println("Destination:" + destination); //$NON-NLS-1$ + + + + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/SlaveDescriptor.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/SlaveDescriptor.java new file mode 100644 index 000000000..3dc34b64f --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/SlaveDescriptor.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 5, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; + +import com.ibm.wtp.common.logger.proxy.Logger; + +/** + * @author jsholl + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class SlaveDescriptor { + + public static final String SLAVE_OPERATION = "slaveOperation"; //$NON-NLS-1$ + + public static final String ATT_OPERATION_CLASS = "operationClass"; //$NON-NLS-1$ + public static final String ATT_ID = "id"; //$NON-NLS-1$ + private static final String ATT_OVERRIDE_ID = "overrideId"; //$NON-NLS-1$ + public static final String ATT_NAME = "name"; //$NON-NLS-1$ + public static final String ATT_DESCRIPTION = "description"; //$NON-NLS-1$ + + private String id; + private String name; + private String description; + private String operationClass; + private String overrideId; + private final IConfigurationElement element; + + public SlaveDescriptor(IConfigurationElement element) { + this.element = element; + init(); + } + + private void init() { + this.id = this.element.getAttribute(ATT_ID); + this.overrideId = this.element.getAttribute(ATT_OVERRIDE_ID); + this.name = this.element.getAttribute(ATT_NAME); + this.description = this.element.getAttribute(ATT_DESCRIPTION); + this.operationClass = this.element.getAttribute(ATT_OPERATION_CLASS); + } + + public String getDescription() { + return description; + } + + public String getName() { + return name; + } + + public WTPOperation createOperation() { + try { + return (WTPOperation) this.element.createExecutableExtension(ATT_OPERATION_CLASS); + } catch (CoreException e) { + Logger.getLogger().logError(e); + } + return null; + } + + /** + * @return Returns the element. + */ + protected IConfigurationElement getElement() { + return element; + } + + /** + * @return Returns the operationClass. + */ + public String getOperationClass() { + return operationClass; + } + + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + public String toString() { + return getClass() + "[name=" + getName() + ", operationClass=" + getOperationClass() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + /** + * @return Returns the id. + */ + public String getId() { + return id; + } + + /** + * @return Returns the overrideId. + */ + public String getOverrideId() { + return overrideId; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/UIOperationExtensionRegistry.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/UIOperationExtensionRegistry.java new file mode 100644 index 000000000..d6272f552 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/UIOperationExtensionRegistry.java @@ -0,0 +1,188 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 4, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.wst.common.frameworks.internal.operations.OperationExtensionRegistry; +import org.eclipse.wst.common.frameworks.internal.ui.WTPUIPlugin; + +import com.ibm.wtp.common.RegistryReader; + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class UIOperationExtensionRegistry extends RegistryReader { + + public static final UIOperationExtensionRegistry INSTANCE = new UIOperationExtensionRegistry(); + + public static final String EXTENSION_POINT = "wtpuiAction"; //$NON-NLS-1$ + + private Map slaveDescriptorMap; + + private Map masterDescriptorMap; + + private HashMap overriddingDescriptorMap; + + static { + INSTANCE.readRegistry(); + } + + protected UIOperationExtensionRegistry() { + super(WTPUIPlugin.PLUGIN_ID, EXTENSION_POINT); + } + + public MasterDescriptor[] getExtendedUIOperations(String extendedOperationId, IStructuredSelection selection) { + if (selection == null || selection.isEmpty()) + return new MasterDescriptor[0]; + List enabledExtendedOperations = new ArrayList(); + List descs = getMasterDescriptorsById(extendedOperationId); + MasterDescriptor descriptor = null; + for (Iterator itr = descs.iterator(); itr.hasNext();) { + descriptor = (MasterDescriptor) itr.next(); + if (descriptor.isEnabledFor(selection) && !isOverridden(descriptor, selection)) + enabledExtendedOperations.add(descriptor); + } + if (enabledExtendedOperations.size() == 0) + return new MasterDescriptor[0]; + MasterDescriptor[] enabledExtendedOperationsArray = new MasterDescriptor[enabledExtendedOperations.size()]; + enabledExtendedOperations.toArray(enabledExtendedOperationsArray); + return enabledExtendedOperationsArray; + } + + /** + * @param descriptor + * @return + */ + protected boolean isOverridden(MasterDescriptor descriptor, IStructuredSelection selection) { + MasterDescriptor overriddingDescriptor = getOverriddingDescriptor(descriptor); + if (overriddingDescriptor == null) + return false; + return overriddingDescriptor.isEnabledFor(selection); + } + + /** + * @param descriptor + * @return + */ + protected MasterDescriptor getOverriddingDescriptor(MasterDescriptor descriptor) { + return (MasterDescriptor) getOverriddingDescriptorMap().get(descriptor.getId()); + } + + /** + * @return + */ + protected Map getOverriddingDescriptorMap() { + if (overriddingDescriptorMap == null) + overriddingDescriptorMap = new HashMap(); + return overriddingDescriptorMap; + } + + public SlaveDescriptor[] getSlaveDescriptors(String parentOperationClass) { + String[] slaves = OperationExtensionRegistry.getRegisteredOperations(parentOperationClass); + List slaveDescriptors = new ArrayList(); + SlaveDescriptor slaveDescriptor = null; + for (int i = 0; null != slaves && i < slaves.length; i++) { + slaveDescriptor = getSlaveDescriptor(slaves[i]); + if (slaveDescriptor != null) + slaveDescriptors.add(slaveDescriptor); + } + SlaveDescriptor[] slaveDescriptorsArray = new SlaveDescriptor[slaveDescriptors.size()]; + slaveDescriptors.toArray(slaveDescriptorsArray); + return slaveDescriptorsArray; + } + + /** + * @param string + * @return + */ + public SlaveDescriptor getSlaveDescriptor(String operationClass) { + return (SlaveDescriptor) getSlaveDescriptorMap().get(operationClass); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement) + */ + public boolean readElement(IConfigurationElement element) { + if (MasterDescriptor.MASTER_OPERATION.equals(element.getName())) { + MasterDescriptor md = new MasterDescriptor(element); + addDescriptor(md); + if (md.getOverrideId() != null && md.getOverrideId().length() > 0) + getOverriddingDescriptorMap().put(md.getOverrideId(), md); + } else if (SlaveDescriptor.SLAVE_OPERATION.equals(element.getName())) { + addDescriptor(new SlaveDescriptor(element)); + } else { + return false; + } + return true; + } + + /** + * @param descriptor + */ + protected void addDescriptor(MasterDescriptor descriptor) { + getMasterDescriptorsById(descriptor.getExtendedOperationId()).add(descriptor); + } + + /** + * @param descriptor + */ + protected void addDescriptor(SlaveDescriptor descriptor) { + getSlaveDescriptorMap().put(descriptor.getOperationClass(), descriptor); + } + + /** + * @param string + * @return + */ + protected List getMasterDescriptorsById(String extendedOperationId) { + List descs = (List) getMasterDescriptorMap().get(extendedOperationId); + if (descs == null) { + getMasterDescriptorMap().put(extendedOperationId, (descs = new ArrayList())); + } + return descs; + } + + /** + * @return + */ + protected Map getMasterDescriptorMap() { + if (masterDescriptorMap == null) + masterDescriptorMap = new HashMap(); + return masterDescriptorMap; + } + + /** + * @return Returns the slaveDescriptorMap. + */ + protected Map getSlaveDescriptorMap() { + if (slaveDescriptorMap == null) + slaveDescriptorMap = new HashMap(); + return slaveDescriptorMap; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionContentProvider.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionContentProvider.java new file mode 100644 index 000000000..2cd231f25 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionContentProvider.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 5, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class WTPActionContentProvider implements ITreeContentProvider { + + /** + * + */ + public WTPActionContentProvider() { + super(); + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object parentElement) { + IOperationNode[] children = null; + if (parentElement instanceof IOperationNode) + children = ((IOperationNode) parentElement).getChildren(); + return (children != null) ? WTPOptionalOperationDataModel.filterRequiredChildren(children) : new Object[0]; + } + + + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + + if (element instanceof IOperationNode) + return ((IOperationNode) element).getParent(); + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object element) { + + return getChildren(element).length != 0; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + IOperationNode[] elements = null; + if (inputElement != null && inputElement instanceof WTPOptionalOperationDataModel) { + IOperationNode root = ((WTPOptionalOperationDataModel) inputElement).getOperationTree(); + if (root != null) + elements = root.getChildren(); + } + return (elements != null) ? WTPOptionalOperationDataModel.filterRequiredChildren(elements) : new Object[0]; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, + * java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionDialog.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionDialog.java new file mode 100644 index 000000000..a973f4510 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionDialog.java @@ -0,0 +1,286 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 4, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeViewerListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeExpansionEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelEvent; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelListener; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; + + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class WTPActionDialog extends Dialog implements WTPOperationDataModelListener { + + private ITreeViewerListener actionTreeListener; + + private ICheckStateListener checkStateListener; + + private ISelectionChangedListener updateDescriptionSelectionListener; + + private CheckboxTreeViewer checkboxTreeViewer; + + Text descriptionText; + + private final WTPOptionalOperationDataModel operationDataModel; + + /** + * This action's id, or <code>null</code> if none. + */ + private String id; + + /** + * @param arg0 + */ + public WTPActionDialog(Shell arg0, WTPOptionalOperationDataModel operationDataModel) { + super(arg0); + this.operationDataModel = operationDataModel; + this.operationDataModel.addListener(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + return super.createContents(parent); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + getShell().setText(WTPCommonUIResourceHandler.getString("WTPActionDialog_UI_0")); //$NON-NLS-1$ + Composite superComposite = (Composite) super.createDialogArea(parent); + + Composite composite = new Composite(superComposite, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; //convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = 0; //convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = 0; //convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = 0; //convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.numColumns = 1; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + // set infopop based on id if id is set + if (getId() != null) + WorkbenchHelp.setHelp(composite, getId()); + Label availableFiltersLabel = new Label(composite, SWT.BOLD); + GridData availableFiltersLabelGridData = new GridData(GridData.FILL_HORIZONTAL); + availableFiltersLabelGridData.heightHint = convertHeightInCharsToPixels(1); + availableFiltersLabel.setLayoutData(availableFiltersLabelGridData); + availableFiltersLabel.setText(WTPCommonUIResourceHandler.getString("WTPActionDialog_UI_0")); //$NON-NLS-1$ + + checkboxTreeViewer = new CheckboxTreeViewer(composite, SWT.CHECK | SWT.BORDER); + + checkboxTreeViewer.setContentProvider(new WTPActionContentProvider()); + checkboxTreeViewer.setLabelProvider(new WTPActionLabelProvider()); + + checkboxTreeViewer.setInput(this.operationDataModel); + + Tree tree = checkboxTreeViewer.getTree(); + GridLayout treeLayout = new GridLayout(); + treeLayout.marginHeight = 0; //convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + treeLayout.marginWidth = 0; //convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + treeLayout.verticalSpacing = 0; //convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + treeLayout.horizontalSpacing = 0; //convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + treeLayout.numColumns = 1; + GridData treeGridData = new GridData(GridData.FILL_HORIZONTAL); + treeGridData.widthHint = convertHorizontalDLUsToPixels(225); + treeGridData.heightHint = convertVerticalDLUsToPixels(150); + tree.setLayout(treeLayout); + tree.setLayoutData(treeGridData); + + descriptionText = new Text(composite, SWT.BORDER | SWT.WRAP); + GridData descriptionTextGridData = new GridData(GridData.FILL_HORIZONTAL); + descriptionTextGridData.heightHint = convertHeightInCharsToPixels(3); + descriptionText.setLayoutData(descriptionTextGridData); + descriptionText.setBackground(superComposite.getBackground()); + + initListeners(); + updateCheckedItems(); + + return composite; + } + + /** + * + */ + protected void initListeners() { + checkboxTreeViewer.addCheckStateListener(getCheckStateListener()); + checkboxTreeViewer.addSelectionChangedListener(getSelectionListener()); + checkboxTreeViewer.addTreeListener(getActionTreeListener()); + } + + /** + * @return + */ + protected ICheckStateListener getCheckStateListener() { + if (checkStateListener == null) + checkStateListener = new CheckStateListener(); + return checkStateListener; + } + + + + public class CheckStateListener implements ICheckStateListener { + + public void checkStateChanged(CheckStateChangedEvent event) { + boolean checked = event.getChecked(); + IOperationNode node = (IOperationNode) event.getElement(); + node.setChecked(checked); + } + } + + public class TreeViewerListener implements ITreeViewerListener { + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeViewerListener#treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent) + */ + public void treeCollapsed(TreeExpansionEvent event) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeViewerListener#treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent) + */ + public void treeExpanded(TreeExpansionEvent event) { + } + } + + public class SelectionChangedListener implements ISelectionChangedListener { + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + + IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection(); + Object element = structuredSelection.getFirstElement(); + String text = ""; //$NON-NLS-1$ + if (element instanceof IOperationNode) + text = ((IOperationNode) element).getDescription(); + descriptionText.setText(text != null ? text : ""); //$NON-NLS-1$ + } + + } + + /** + * @return + */ + private ISelectionChangedListener getSelectionListener() { + if (updateDescriptionSelectionListener == null) + updateDescriptionSelectionListener = new SelectionChangedListener(); + return updateDescriptionSelectionListener; + } + + /** + * @return + */ + private ITreeViewerListener getActionTreeListener() { + if (actionTreeListener == null) + actionTreeListener = new TreeViewerListener(); + return actionTreeListener; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModelListener#propertyChanged(org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModelEvent) + */ + public void propertyChanged(WTPOperationDataModelEvent event) { + switch (event.getFlag()) { + case WTPOperationDataModelEvent.PROPERTY_CHG : + if (WTPOptionalOperationDataModel.OPERATION_TREE.equals(event.getPropertyName())) + updateCheckedItems(); + break; + } + } + + /** + * + */ + private void updateCheckedItems() { + IOperationNode root = (IOperationNode) this.operationDataModel.getProperty(WTPOptionalOperationDataModel.OPERATION_TREE); + updateCheckedState(root); + + } + + /** + * @param root + */ + private void updateCheckedState(IOperationNode root) { + if (root == null) + return; + + IOperationNode[] children = root.getChildren(); + if (children == null) + return; + for (int i = 0; i < children.length; i++) { + checkboxTreeViewer.setChecked(children[i], children[i].isChecked()); + boolean disabled = (children[i].getParent() != null) ? children[i].getParent().isChecked() : false; + checkboxTreeViewer.setGrayed(children[i], disabled); + updateCheckedState(children[i]); + } + } + + /** + * @return Returns the id. + */ + public String getId() { + return id; + } + + /** + * @param id + * The id to set. + */ + public void setId(String id) { + this.id = id; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionLabelProvider.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionLabelProvider.java new file mode 100644 index 000000000..06bfdc4b9 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPActionLabelProvider.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 5, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class WTPActionLabelProvider implements ILabelProvider { + + /** + * + */ + public WTPActionLabelProvider() { + super(); + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + public void addListener(ILabelProviderListener listener) { + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() + */ + public void dispose() { + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, + * java.lang.String) + */ + public boolean isLabelProperty(Object element, String property) { + + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + public void removeListener(ILabelProviderListener listener) { + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + */ + public Image getImage(Object element) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + if (element instanceof IOperationNode) + return ((IOperationNode) element).getName(); + + return element.toString(); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPOperationDataModelUICreator.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPOperationDataModelUICreator.java new file mode 100644 index 000000000..e8109aca1 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPOperationDataModelUICreator.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 4, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + + + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public interface WTPOperationDataModelUICreator { + + WTPOperationDataModel createDataModel(String extendedOperationId, String operationClass, IStructuredSelection selection, IWorkbenchSite site); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPOptionalOperationDataModel.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPOptionalOperationDataModel.java new file mode 100644 index 000000000..994a92f6b --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WTPOptionalOperationDataModel.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 5, 2004 + * + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.wst.common.frameworks.internal.operations.ComposedOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; +import org.eclipse.wst.common.frameworks.internal.ui.WTPUIPlugin; + + +/** + * @author jsholl + * + */ +public class WTPOptionalOperationDataModel extends WTPOperationDataModel { + + + + /** + * String, this is required along with a STRUCTURED_SELECTION unless MASTER_OPERATION_LIST is + * set + */ + public static final String EXTENDED_OPERATION_ID = "WTPOptionalOperationDataModel.EXTENDED_OPERATION_ID"; //$NON-NLS-1$ + + /** + * IStructuredSelection, this is required along with a EXTENDED_OPERATION_ID unless + * MASTER_OPERATION_LIST is set + */ + public static final String STRUCTURED_SELECTION = "WTPOptionalOperationDataModel.STRUCTURED_SELECTION"; //$NON-NLS-1$ + + /** + * List of MasterDescriptor, required unless both EXTENDED_OPERATION_ID and STRUCTURED_SELECTION + * are set + */ + public static final String MASTER_OPERATION_LIST = "WTPOptionalOperationDataModel.MASTER_OPERATION_LIST"; //$NON-NLS-1$ + + /** + * A root IOperationNode whose operation is null and children are the contents of the + * MASTER_OPERATION_LIST + */ + public static final String OPERATION_TREE = "WTPOptionalOperationDataModel.OPERATION_TREE"; //$NON-NLS-1$ + + /** + * Optional. Allow the WTPOperationDataModelUICreators access to the workbench site for + * additional initializations. + */ + public static final String IWORKBENCH_SITE = "IWORKBENCH_SITE"; //$NON-NLS-1$ + + public static WTPOptionalOperationDataModel createDataModel(String extendedOperationId, IStructuredSelection selection) { + WTPOptionalOperationDataModel dataModel = new WTPOptionalOperationDataModel(); + dataModel.setProperty(EXTENDED_OPERATION_ID, extendedOperationId); + dataModel.setProperty(STRUCTURED_SELECTION, selection); + return dataModel; + } + + private class OperationNode implements IOperationNode { + + private WTPOperationDataModel dataModel = null; + + private SlaveDescriptor descriptor = null; + + private List children = null; + + private OperationNode parent = null; + + private boolean checked = false; + + public OperationNode(OperationNode parent, SlaveDescriptor descriptor) { + this.parent = parent; + this.descriptor = descriptor; + verifyRoot(); + } + + private void verifyRoot() { + if (null == parent) { + return; + } + IOperationNode root = getOperationTree(); + OperationNode node = this; + while (node.parent != null) { + node = node.parent; + } + if (node != root) { + throw new RuntimeException(); + } + } + + public String getName() { + return descriptor.getName(); + } + + public String getDescription() { + return descriptor.getDescription(); + } + + public WTPOperationDataModel getDataModel() { + IWorkbenchSite site = (IWorkbenchSite) getProperty(IWORKBENCH_SITE); + if (dataModel == null) { + IOperationNode root = getOperationTree(); + if (this.parent == root) { + MasterDescriptor masterDescriptor = (MasterDescriptor) descriptor; + dataModel = masterDescriptor.getCreator().createDataModel(masterDescriptor.getExtendedOperationId(), masterDescriptor.getOperationClass(), getStructuredSelection(), site); + } else + dataModel = parent.getDataModel(); + } + return dataModel; + } + + public WTPOperation getOperation() { + WTPOperation operation = descriptor.createOperation(); + WTPOperationDataModel dataModel1 = getDataModel(); + if (dataModel1 != null) { + if (operation == null) + operation = dataModel.getDefaultOperation(); + else + operation.setOperationDataModel(dataModel); + } + return operation; + } + + public IOperationNode[] getChildren() { + verifyRoot(); + return getChildren(true); + } + + public IOperationNode[] getChildren(boolean expandChildren) { + if (expandChildren && null == children && null != parent) { + children = new ArrayList(); + SlaveDescriptor[] slaveDescriptors = UIOperationExtensionRegistry.INSTANCE.getSlaveDescriptors(descriptor.getOperationClass()); + for (int i = 0; null != slaveDescriptors && i < slaveDescriptors.length; i++) { + OperationNode child = new OperationNode(this, slaveDescriptors[i]); + child.checked = checked; + addChild(child); + } + } + if (null == children) { + return null; + } + OperationNode[] childNodes = new OperationNode[children.size()]; + children.toArray(childNodes); + return childNodes; + } + + public void clearChildren() { + if (null != children) { + children.clear(); + } + } + + public void addChild(OperationNode childNode) { + if (null == children) { + children = new ArrayList(); + } + children.add(childNode); + } + + public boolean isChecked() { + verifyRoot(); + if (descriptor instanceof MasterDescriptor && ((MasterDescriptor) descriptor).isAlwaysExecute()) + return true; + return checked; + } + + public void setChecked(boolean checked) { + if (descriptor instanceof MasterDescriptor && ((MasterDescriptor) descriptor).isAlwaysExecute()) + return; + internalSetChecked(checked); + Object root = getProperty(OPERATION_TREE); + notifyListeners(OPERATION_TREE, root, root); + } + + public IOperationNode getParent() { + return parent; + } + + protected void internalSetChecked(boolean checked1) { + this.checked = checked1; + if (checked) { + OperationNode[] children1 = (OperationNode[]) getChildren(false); + for (int i = 0; null != children && i < children1.length; i++) + children1[i].internalSetChecked(checked); + } else { + if (this.parent != null) + this.parent.internalSetChecked(checked); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.operation.extension.ui.IOperationNode#isAlwaysExecute() + */ + public boolean isAlwaysExecute() { + if (descriptor instanceof MasterDescriptor && ((MasterDescriptor) descriptor).isAlwaysExecute()) + return true; + return false; + } + } + + protected void init() { + super.init(); + setProperty(OPERATION_TREE, new OperationNode(null, null)); + } + + protected void initValidBaseProperties() { + super.initValidBaseProperties(); + addValidBaseProperty(MASTER_OPERATION_LIST); + addValidBaseProperty(OPERATION_TREE); + addValidBaseProperty(STRUCTURED_SELECTION); + addValidBaseProperty(EXTENDED_OPERATION_ID); + addValidBaseProperty(IWORKBENCH_SITE); + } + + IStructuredSelection getStructuredSelection() { + return (IStructuredSelection) getProperty(STRUCTURED_SELECTION); + } + + public IOperationNode getOperationTree() { + return (IOperationNode) getProperty(OPERATION_TREE); + } + + public static IOperationNode[] getOptionalChildren(IOperationNode node) { + IOperationNode[] children = node.getChildren(); + children = filterRequiredChildren(children); + return children; + } + + /** + * @param children + * @return + */ + public static IOperationNode[] filterRequiredChildren(IOperationNode[] children) { + List filteredChildren = new ArrayList(Arrays.asList(children)); + for (int i = 0; i < children.length; i++) + if (children[i].isAlwaysExecute()) + filteredChildren.remove(children[i]); + filteredChildren.toArray((children = new IOperationNode[filteredChildren.size()])); + return children; + } + + protected boolean doSetProperty(String propertyName, Object propertyValue) { + boolean returnVal = super.doSetProperty(propertyName, propertyValue); + if (propertyName.equals(STRUCTURED_SELECTION) || propertyName.equals(EXTENDED_OPERATION_ID)) { + String extendedOperationID = getStringProperty(EXTENDED_OPERATION_ID); + IStructuredSelection selection = (IStructuredSelection) getProperty(STRUCTURED_SELECTION); + setProperty(MASTER_OPERATION_LIST, UIOperationExtensionRegistry.INSTANCE.getExtendedUIOperations(extendedOperationID, selection)); + } + if (propertyName.equals(MASTER_OPERATION_LIST)) { + OperationNode rootNode = (OperationNode) getOperationTree(); + rootNode.clearChildren(); + MasterDescriptor[] descriptors = (MasterDescriptor[]) propertyValue; + if (null != descriptors) { + for (int i = 0; i < descriptors.length; i++) { + OperationNode child = new OperationNode(rootNode, descriptors[i]); + child.setChecked(true); + rootNode.addChild(child); + } + } + notifyListeners(OPERATION_TREE, rootNode, rootNode); + } + return returnVal; + } + + public WTPOperation getDefaultOperation() { + ComposedOperation operation = new ComposedOperation(); + OperationNode root = (OperationNode) getOperationTree(); + addOperationIfNecessary(operation, root); + return operation; + } + + private void addOperationIfNecessary(ComposedOperation operation, OperationNode node) { + if (node.isAlwaysExecute() || node.isChecked()) { + WTPOperation op = node.getOperation(); + if (op != null) + operation.addRunnable(op); + } else { + IOperationNode[] children = node.getChildren(false); + for (int i = 0; null != children && i < children.length; i++) + addOperationIfNecessary(operation, (OperationNode) children[i]); + } + } + + private boolean hasSelectedNodes(OperationNode node) { + if (node.isChecked()) { + return true; + } + boolean foundSelection = false; + OperationNode[] children = (OperationNode[]) node.getChildren(false); + for (int i = 0; !foundSelection && null != children && i < children.length; i++) { + foundSelection = hasSelectedNodes(children[i]); + } + return foundSelection; + } + + protected IStatus doValidateProperty(String propertyName) { + if (propertyName.equals(OPERATION_TREE)) { + OperationNode root = (OperationNode) getOperationTree(); + if (root.isChecked()) { + return WTPUIPlugin.createErrorStatus(WTPCommonUIResourceHandler.getString("WTPOptionalOperationDataModel_UI_0")); //$NON-NLS-1$ + } else if (!hasSelectedNodes(root)) { + return WTPUIPlugin.createErrorStatus(WTPCommonUIResourceHandler.getString("WTPOptionalOperationDataModel_UI_1"));} //$NON-NLS-1$ + } + return super.doValidateProperty(propertyName); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardExtensionFactory.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardExtensionFactory.java new file mode 100644 index 000000000..d539adf00 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardExtensionFactory.java @@ -0,0 +1,28 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + + +public abstract class WizardExtensionFactory { + + public WizardExtensionFactory() { + super(); + } + + public abstract IExtendedWizardPage[] createPageGroup(WTPOperationDataModel dataModel, String pageGroupID); + + /* + * this is optional + */ + public IExtendedPageHandler createPageHandler(WTPOperationDataModel dataModel, String pageGroupID) { + return null; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageElement.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageElement.java new file mode 100644 index 000000000..76f5be104 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageElement.java @@ -0,0 +1,226 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclispe.wst.common.frameworks.internal.enablement.IdentifiableComparator; + +import com.ibm.wtp.common.logger.proxy.Logger; + +public class WizardPageElement extends AbstractRegistryDescriptor implements Comparable { + /** Type designation for an {@link ExtendedEditorPage} */ + public static final int EXTENDED_EDITOR_PAGE = 0; + /** Type designation for a nested editor */ + public static final int NESTED_EDITOR = 1; + static final String[] EMPTY_STRING_ARRAY = new String[0]; + static final String ELEMENT_PAGE_GROUP = "wizardPageGroup"; //$NON-NLS-1$ + static final String ATT_PAGE_ID = "pageGroupID"; //$NON-NLS-1$ + static final String ATT_WIZARD_ID = "wizardID"; //$NON-NLS-1$ + static final String ATT_GROUP_ID = "groupID"; //$NON-NLS-1$ + static final String ATT_ALLOWS_EXTENDED_PAGES_AFTER = "allowsExtendedPagesAfter"; //$NON-NLS-1$ + static final String ATT_PAGE_INSERTION_ID = "pageGroupInsertionID"; //$NON-NLS-1$ + static final String ELEMENT_FACTORY = "factory"; //$NON-NLS-1$ + + protected WizardPageFactoryElement wizardPageFactoryElement; + protected String pluginID; + protected String wizardID; + protected String pageGroupID; + protected String wizardFactoryElement; + protected boolean allowsExtendedPagesAfter; + protected String pageInsertionID; + private int loadOrder; + private static int loadOrderCounter; + + + private int type; + + public WizardPageElement(IConfigurationElement element1) { + super(element1); + pluginID = element1.getDeclaringExtension().getDeclaringPluginDescriptor().getUniqueIdentifier(); + wizardID = element1.getAttribute(ATT_WIZARD_ID); + pageGroupID = element1.getAttribute(ATT_PAGE_ID); + readAllowsExtendedPageAfter(element1); + pageInsertionID = element1.getAttribute(ATT_PAGE_INSERTION_ID); + readFactory(element1); + validateSettings(); + loadOrder = loadOrderCounter++; + } + + private void validateSettings() { + if (wizardID == null || wizardPageFactoryElement == null) { + Logger.getLogger().logError("Incomplete page extension specification."); //$NON-NLS-1$ + } + } + + + private void readAllowsExtendedPageAfter(IConfigurationElement element1) { + String allowsPageAfterValue = element1.getAttribute(ATT_ALLOWS_EXTENDED_PAGES_AFTER); + allowsExtendedPagesAfter = allowsPageAfterValue == null ? false : Boolean.valueOf(allowsPageAfterValue).booleanValue(); + } + + private void readFactory(IConfigurationElement element1) { + IConfigurationElement[] factories = element1.getChildren(ELEMENT_FACTORY); + if (factories != null && factories.length > 0) { + wizardPageFactoryElement = new WizardPageFactoryElement(factories[0], pageGroupID); + } + } + + public IExtendedPageHandler createPageHandler(WTPOperationDataModel dataModel) { + if (wizardPageFactoryElement != null) + return wizardPageFactoryElement.createPageHandler(dataModel); + return null; + } + + public IExtendedWizardPage[] createPageGroup(WTPOperationDataModel dataModel) { + if (wizardPageFactoryElement != null) + return wizardPageFactoryElement.createPageGroup(dataModel); + return null; + } + + + public int compareTo(Object o) { + return IdentifiableComparator.getInstance().compare(this, o); + /* + * if (o == null) return GREATER_THAN; WizardPageElement element = (WizardPageElement) o; if + * (getID() == null && element.getID() == null) return compareLoadOrder(element); if + * (getID() == null) return GREATER_THAN; else if (element.getID() == null) return + * LESS_THAN; + * + * int priority = getPriority(); int elementPriority =element.getPriority(); + * + * if (priority == elementPriority) return compareLoadOrder(element); if (priority < + * elementPriority) return GREATER_THAN; if (priority > elementPriority) return LESS_THAN; + * return EQUAL; + */ + } + + /** + * @return + */ + public boolean allowsExtendedPagesAfter() { + return allowsExtendedPagesAfter; + } + + /** + * @return + */ + public String getPluginID() { + return pluginID; + } + + /** + * @return + */ + public String getPageID() { + return pageGroupID; + } + + /** + * @return + */ + public String getPageInsertionID() { + return pageInsertionID; + } + + /** + * @return + */ + public int getType() { + return type; + } + + /** + * @return + */ + public int getLoadOrder() { + return loadOrder; + } + + + /** + * @return Returns the allowsExtendedPagesAfter. + */ + public boolean isAllowsExtendedPagesAfter() { + return allowsExtendedPagesAfter; + } + + /** + * @param allowsExtendedPagesAfter + * The allowsExtendedPagesAfter to set. + */ + public void setAllowsExtendedPagesAfter(boolean allowsExtendedPagesAfter) { + this.allowsExtendedPagesAfter = allowsExtendedPagesAfter; + } + + /** + * @return Returns the wizardFactoryElement. + */ + public String getWizardFactoryElement() { + return wizardFactoryElement; + } + + /** + * @param wizardFactoryElement + * The wizardFactoryElement to set. + */ + public void setWizardFactoryElement(String wizardFactoryElement) { + this.wizardFactoryElement = wizardFactoryElement; + } + + /** + * @return Returns the wizardID. + */ + public String getWizardID() { + return wizardID; + } + + /** + * @param wizardID + * The wizardID to set. + */ + public void setWizardID(String wizardID) { + this.wizardID = wizardID; + } + + /** + * @return Returns the wizardPageFactoryElement. + */ + public WizardPageFactoryElement getWizardPageFactoryElement() { + return wizardPageFactoryElement; + } + + /** + * @param wizardPageFactoryElement + * The wizardPageFactoryElement to set. + */ + public void setWizardPageFactoryElement(WizardPageFactoryElement wizardPageFactoryElement) { + this.wizardPageFactoryElement = wizardPageFactoryElement; + } + + + /** + * @param pageID + * The pageID to set. + */ + public void setPageID(String pageID) { + this.pageGroupID = pageID; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor#getID() + */ + public String getID() { + return getPageID(); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageExtensionManager.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageExtensionManager.java new file mode 100644 index 000000000..7e97e4004 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageExtensionManager.java @@ -0,0 +1,278 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.wst.common.frameworks.internal.ui.WTPCommonUIResourceHandler; +import org.eclispe.wst.common.frameworks.internal.enablement.EnablementManager; + +import com.ibm.wtp.common.RegistryReader; +import com.ibm.wtp.common.logger.proxy.Logger; + +public class WizardPageExtensionManager { + + public static final String ORG_ECLIPSE_UI = "org.eclipse.ui"; //$NON-NLS-1$ + + protected static WizardPageExtensionManager instance = null; + + HashMap wizardPluginIDMap = null; + + TreeMap wizardPageElements = null; + + //private TreeSet wizardExtPageElements = null; + List nonSyncedPageElementList = null; + + private WizardPageExtensionReader reader = null; + + private WizardPageExtensionManager() { + setupWizardPluginIDMap(); + readFromRegistry(); + postReadFromRegistry(); + } + + private void setupWizardPluginIDMap() { + wizardPluginIDMap = new HashMap(); + // get editor plugin and save it to a hash map + // Note: editors extension id is different from editor id + + IExtensionPoint[] point = new IExtensionPoint[]{Platform.getPluginRegistry().getExtensionPoint(ORG_ECLIPSE_UI, "exportWizards"), //$NON-NLS-1$ + Platform.getPluginRegistry().getExtensionPoint(ORG_ECLIPSE_UI, "importWizards"), //$NON-NLS-1$ + Platform.getPluginRegistry().getExtensionPoint(ORG_ECLIPSE_UI, "newWizards"), //$NON-NLS-1$ + Platform.getPluginRegistry().getExtensionPoint("org.eclipse.wst.common.frameworks.ui", "extendableWizard")}; //$NON-NLS-1$ //$NON-NLS-2$ + + for (int x = 0; x < point.length; x++) { + IConfigurationElement[] elements = point[x].getConfigurationElements(); + for (int i = 0; i < elements.length; i++) { + String wizardID = elements[i].getAttribute("id"); //$NON-NLS-1$ + String pluginID = elements[i].getDeclaringExtension().getDeclaringPluginDescriptor().getUniqueIdentifier(); + wizardPluginIDMap.put(wizardID, pluginID); + } + } + } + + private void readFromRegistry() { + wizardPageElements = new TreeMap(); + //wizardExtPageElements = new TreeSet(); + nonSyncedPageElementList = new ArrayList(); + // Read all page extensions into editorPageElements + reader = new WizardPageExtensionReader(); + reader.readRegistry(); + + } + + protected class WizardPageExtensionReader extends RegistryReader { + + public WizardPageExtensionReader() { + super(CommonUIPluginConstants.PLUGIN_ID, WizardPageElement.ELEMENT_PAGE_GROUP); + } + + public boolean readElement(IConfigurationElement element) { + if (!WizardPageElement.ELEMENT_PAGE_GROUP.equals(element.getName())) + return false; + WizardPageElement newElement = new WizardPageElement(element); + + // put the element into a hashmap, wizardID as key, + // list of page elements as object + String wizardID = newElement.getWizardID(); + if (!wizardPageElements.containsKey(wizardID)) { + wizardPageElements.put(wizardID, createPageMapEntry(newElement)); + } else { + TreeMap pageMap = (TreeMap) wizardPageElements.get(wizardID); + insertPageElement(pageMap, newElement); + } + + return true; + } + + public void insertPageElement(TreeMap pageMap, WizardPageElement newElement) { + if (newElement.pageInsertionID == null) { + pageMap.put(newElement, new TreeSet()); + } else { + String elementName = newElement.pageInsertionID; + WizardPageElement parentElement = getPageElement(elementName, pageMap); + insertExtPageElement(pageMap, parentElement, newElement); + } + + newElement.getPageInsertionID(); + + } + + private void insertExtPageElement(TreeMap pageMap, WizardPageElement parentElement, WizardPageElement newElement) { + if (parentElement == null) { + nonSyncedPageElementList.add(newElement); + return; + } + if (!parentElement.allowsExtendedPagesAfter()) { + Logger.getLogger().logError(WTPCommonUIResourceHandler.getString("WizardPageExtensionManager_UI_0", new Object[]{parentElement.getPageID()})); //$NON-NLS-1$ + Logger.getLogger().logError(WTPCommonUIResourceHandler.getString("WizardPageExtensionManager_UI_1", new Object[]{newElement.getPageID()})); //$NON-NLS-1$ + return; + } + TreeSet set = (TreeSet) pageMap.get(parentElement); + set.add(newElement); + + if (newElement.allowsExtendedPagesAfter) + pageMap.put(newElement, new TreeSet()); + + if (nonSyncedPageElementList.contains(newElement)) + nonSyncedPageElementList.remove(newElement); + } + + private WizardPageElement getPageElement(String elementName, TreeMap map) { + Set keySet = map.keySet(); + for (Iterator iter = keySet.iterator(); iter.hasNext();) { + WizardPageElement element = (WizardPageElement) iter.next(); + if (element.getPageID().equals(elementName)) + return element; + } + return null; + + } + + private TreeMap createPageMapEntry(WizardPageElement newElement) { + TreeMap pageMap = new TreeMap(); + TreeSet pageExtensionSet = new TreeSet(); + pageMap.put(newElement, pageExtensionSet); + return pageMap; + + } + + } + + public boolean hasExtensionElements(String wizardID) { + TreeMap treeMap = (TreeMap) wizardPageElements.get(wizardID); + return treeMap.isEmpty(); + } + + public WizardPageElement[] getPageElements(String wizardID) { + TreeMap elementMap = (TreeMap) wizardPageElements.get(wizardID); + if (elementMap == null || elementMap.isEmpty()) { + return new WizardPageElement[0]; + } + ArrayList alreadyVistedList = new ArrayList(elementMap.size()); + Set allPageElementsList = elementMap.keySet(); + ArrayList orderedPageList = new ArrayList(elementMap.size()); + + for (Iterator iter = allPageElementsList.iterator(); iter.hasNext();) { + WizardPageElement element = (WizardPageElement) iter.next(); + if (alreadyVistedList.contains(element)) + continue; + if (EnablementManager.INSTANCE.getIdentifier(element.getID(), null).isEnabled()) { + orderedPageList.add(element); + TreeSet treeSet = (TreeSet) elementMap.get(element); + if (treeSet != null && !treeSet.isEmpty()) + flatenTreeSet(treeSet, allPageElementsList, alreadyVistedList, orderedPageList, elementMap); + } + } + return getPageArray(orderedPageList); + + } + + private WizardPageElement[] getPageArray(ArrayList orderedPageList) { + WizardPageElement[] pageElements = new WizardPageElement[orderedPageList.size()]; + for (int i = 0; i < orderedPageList.size(); i++) { + pageElements[i] = (WizardPageElement) orderedPageList.get(i); + } + return pageElements; + } + + private void flatenTreeSet(TreeSet treeSet, Set allPageElementsList, ArrayList alreadyVistedList, ArrayList orderedPageList, TreeMap elementMap) { + for (Iterator iter = treeSet.iterator(); iter.hasNext();) { + WizardPageElement element = (WizardPageElement) iter.next(); + if (alreadyVistedList.contains(element)) { + Logger.getLogger().logError(WTPCommonUIResourceHandler.getString("WizardPageExtensionManager_UI_2", new Object[]{element.getPageID(), WizardPageElement.ATT_PAGE_INSERTION_ID})); //$NON-NLS-1$ + return; + } + if (allPageElementsList.contains(element)) { + TreeSet set = (TreeSet) elementMap.get(element); + orderedPageList.add(element); + alreadyVistedList.add(element); + flatenTreeSet(set, allPageElementsList, alreadyVistedList, orderedPageList, elementMap); + } else { + orderedPageList.add(element); + alreadyVistedList.add(element); + } + + } + + } + + // if child elements are read in before parent element. Do post read. + protected ArrayList listRemoveObjects; + + private void postReadFromRegistry() { + listRemoveObjects = new ArrayList(nonSyncedPageElementList.size()); + for (int i = 0; i < nonSyncedPageElementList.size(); i++) { + WizardPageElement element = (WizardPageElement) nonSyncedPageElementList.get(i); + TreeMap pageMap = (TreeMap) wizardPageElements.get(element.wizardID); + if (element.pageInsertionID == null) { + addToFirstAvialiable(pageMap, element); + } else if (reader != null && pageMap != null) + reader.insertPageElement(pageMap, element); + } + nonSyncedPageElementList.removeAll(listRemoveObjects); + if (!nonSyncedPageElementList.isEmpty()) + logMissingClassError(); + nonSyncedPageElementList.clear(); + + } + + /** + * @param pageMap + * @param element + */ + private void addToFirstAvialiable(TreeMap pageMap, WizardPageElement newElement) { + boolean insertNotFound = true; + for (Iterator iter = pageMap.keySet().iterator(); iter.hasNext();) { + WizardPageElement element = (WizardPageElement) iter.next(); + if (element.allowsExtendedPagesAfter) { + TreeSet set = (TreeSet) pageMap.get(element); + set.add(newElement); + listRemoveObjects.add(newElement); + return; + } + } + if (insertNotFound) { + Logger logger = Logger.getLogger(); + logger.logError(WTPCommonUIResourceHandler.getString("WizardPageExtensionManager_UI_3")); //$NON-NLS-1$ + } + + } + + private void logMissingClassError() { + Logger logger = Logger.getLogger(); + for (int i = 0; i < nonSyncedPageElementList.size(); i++) { + WizardPageElement element = (WizardPageElement) nonSyncedPageElementList.get(i); + logger.logError(WTPCommonUIResourceHandler.getString("WizardPageExtensionManager_UI_4", new Object[]{element.pageInsertionID, element.getPageID(), element.pluginID})); //$NON-NLS-1$ + } + nonSyncedPageElementList.clear(); + + } + + /** + * Gets the instance. + * + * @return Returns a EjbPageExtensionRegistry + */ + public static WizardPageExtensionManager getInstance() { + if (instance == null) { + instance = new WizardPageExtensionManager(); + } + return instance; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageFactoryElement.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageFactoryElement.java new file mode 100644 index 000000000..802ae5db7 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/operation/extensionui/WizardPageFactoryElement.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Oct 20, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.operation.extensionui; + + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.common.frameworks.internal.ConfigurationElementWrapper; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + +import com.ibm.wtp.common.logger.proxy.Logger; + +/** + * @author schacher + * + * To change the template for this generated type comment go to Window>Preferences>Java>Code + * Generation>Code and Comments + */ +public class WizardPageFactoryElement extends ConfigurationElementWrapper { + + static final String ATT_CLASS_NAME = "className"; //$NON-NLS-1$ + + protected String className; + protected WizardExtensionFactory wizardPageFactory; + protected boolean isPageFactoryInitialized; + protected String pageGroupID; + + /** + * @param element + */ + public WizardPageFactoryElement(IConfigurationElement element, String pageGroupID) { + super(element); + className = element.getAttribute(ATT_CLASS_NAME); + this.pageGroupID = pageGroupID; + } + + public IExtendedPageHandler createPageHandler(WTPOperationDataModel dataModel) { + if (!isPageFactoryInitialized) + initPageFactory(); + if (wizardPageFactory == null) + return null; + + IExtendedPageHandler handler = wizardPageFactory.createPageHandler(dataModel, pageGroupID); + return handler; + } + + public IExtendedWizardPage[] createPageGroup(WTPOperationDataModel dataModel) { + if (!isPageFactoryInitialized) + initPageFactory(); + + if (wizardPageFactory == null) + return null; + + IExtendedWizardPage[] pages = wizardPageFactory.createPageGroup(dataModel, pageGroupID); + for (int i = 0; i < pages.length; i++) { + pages[i].setGroupID(pageGroupID); + } + return pages; + } + + private void initPageFactory() { + try { + wizardPageFactory = (WizardExtensionFactory) element.createExecutableExtension(ATT_CLASS_NAME); + } catch (CoreException e) { + Logger.getLogger().logError("Error getting page factory: " + className); //$NON-NLS-1$ + Logger.getLogger().logError(e); + } finally { + isPageFactoryInitialized = true; + } + } + + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/AbstractWTPUIPlugin.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/AbstractWTPUIPlugin.java new file mode 100644 index 000000000..b2477db2d --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/AbstractWTPUIPlugin.java @@ -0,0 +1,50 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +/* + * Created on Dec 10, 2003 + * + * To change the template for this generated file go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import com.ibm.wtp.common.logger.proxy.Logger; +import com.ibm.wtp.logger.proxyrender.DefaultPluginTraceRenderer; +import com.ibm.wtp.logger.proxyrender.IMsgLogger; + +public abstract class AbstractWTPUIPlugin extends AbstractUIPlugin implements IMsgLogger { + protected static Logger logger = null; + + /** + * @param descriptor + */ + public AbstractWTPUIPlugin(IPluginDescriptor descriptor) { + super(descriptor); + } + + public Logger getMsgLogger() { + if (logger == null) { + logger = Logger.getLogger(getPluginID()); + setRenderer(logger); + } + return logger; + } + + public abstract String getPluginID(); + + /** + * @param aLogger + */ + protected void setRenderer(Logger aLogger) { + new DefaultPluginTraceRenderer(aLogger); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ClosableWizardDialog.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ClosableWizardDialog.java new file mode 100644 index 000000000..7316c8b64 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ClosableWizardDialog.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Mar 24, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; + +/** + * @author DABERG + * + * To change the template for this generated type comment go to Window>Preferences>Java>Code + * Generation>Code and Comments + */ +public class ClosableWizardDialog extends WizardDialog { + /** + * @param parentShell + * @param newWizard + */ + public ClosableWizardDialog(Shell parentShell, IWizard newWizard) { + super(parentShell, newWizard); + } + + public void finishAndClose() { + super.finishPressed(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/DisplayUtility.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/DisplayUtility.java new file mode 100644 index 000000000..647f58e59 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/DisplayUtility.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Apr 19, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.swt.widgets.Display; + +/** + * @author mdelder + */ +public class DisplayUtility { + + public static void asyncExec(Runnable runnable) { + + Display d = Display.getCurrent(); + if (d == null) + Display.getDefault().asyncExec(runnable); + else + runnable.run(); + + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ErrorDialog.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ErrorDialog.java new file mode 100644 index 000000000..9cd3cf11d --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ErrorDialog.java @@ -0,0 +1,187 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2002 - All + * Rights Reserved. US Government Users Restricted Rights - Use, duplication or + * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. + */ +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTError; +import org.eclipse.swt.SWTException; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * Added a Details button to the MessageDialog to show the exception stack trace. + * + * Borrowed from an eclipse InternalErrorDialog + */ +public class ErrorDialog extends MessageDialog { + protected static final String[] LABELS_OK = {IDialogConstants.OK_LABEL}; + protected static final String[] LABELS_OK_CANCEL = {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}; + protected static final String[] LABELS_OK_DETAILS = {IDialogConstants.OK_LABEL, IDialogConstants.SHOW_DETAILS_LABEL}; + protected static final String[] LABELS_OK_CANCEL_DETAILS = {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL, IDialogConstants.SHOW_DETAILS_LABEL}; + private Throwable detail; + private int detailButtonID = -1; + private Text text; + private String message; + //Workaround. SWT does not seem to set the default button if + //there is not control with focus. Bug: 14668 + private int defaultButtonIndex = 0; + /** + * Size of the text in lines. + */ + private static final int TEXT_LINE_COUNT = 15; + + public ErrorDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, Throwable detail, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex); + defaultButtonIndex = defaultIndex; + this.detail = detail; + message = dialogMessage; + setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL | SWT.RESIZE); + } + + //Workaround. SWT does not seem to set rigth the default button if + //there is not control with focus. Bug: 14668 + public int open() { + create(); + Button b = getButton(defaultButtonIndex); + b.setFocus(); + b.getShell().setDefaultButton(b); + return super.open(); + } + + /** + * Set the detail button; + */ + public void setDetailButton(int index) { + detailButtonID = index; + } + + /* + * (non-Javadoc) Method declared on Dialog. + */ + protected void buttonPressed(int buttonId) { + if (buttonId == detailButtonID) { + toggleDetailsArea(); + } else { + setReturnCode(buttonId); + close(); + } + } + + /** + * Toggles the unfolding of the details area. This is triggered by the user pressing the details + * button. + */ + private void toggleDetailsArea() { + Point windowSize = getShell().getSize(); + Point oldSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); + if (text != null) { + text.dispose(); + text = null; + getButton(detailButtonID).setText(IDialogConstants.SHOW_DETAILS_LABEL); + } else { + createDropDownText((Composite) getContents()); + getButton(detailButtonID).setText(IDialogConstants.HIDE_DETAILS_LABEL); + } + Point newSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); + getShell().setSize(new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y))); + } + + /** + * Create this dialog's drop-down list component. + * + * @param parent + * the parent composite + * @return the drop-down list component + */ + protected void createDropDownText(Composite parent) { + // create the list + text = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + // print the stacktrace in the text field + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + detail.printStackTrace(ps); + if ((detail instanceof SWTError) && (((SWTError) detail).throwable != null)) { + ps.println("\n*** Stack trace of contained exception ***"); //$NON-NLS-1$ + ((SWTError) detail).throwable.printStackTrace(ps); + } else if ((detail instanceof SWTException) && (((SWTException) detail).throwable != null)) { + ps.println("\n*** Stack trace of contained exception ***"); //$NON-NLS-1$ + ((SWTException) detail).throwable.printStackTrace(ps); + } + ps.flush(); + baos.flush(); + text.setText(baos.toString()); + } catch (IOException e) { + } + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL); + data.heightHint = text.getLineHeight() * TEXT_LINE_COUNT; + text.setLayoutData(data); + } + + public static boolean openError(Shell parent, String title, String message, Throwable detail, int defaultIndex, boolean showCancel) { + String[] labels; + if (detail == null) + labels = showCancel ? LABELS_OK_CANCEL : LABELS_OK; + else + labels = showCancel ? LABELS_OK_CANCEL_DETAILS : LABELS_OK_DETAILS; + ErrorDialog dialog = new ErrorDialog(parent, title, null, // accept + // the + // default + // window + // icon + message, detail, ERROR, labels, defaultIndex); + if (detail != null) + dialog.setDetailButton(labels.length - 1); + return dialog.open() == 0; + } + + protected Control createDialogArea(Composite parent) { + // create a composite with standard margins and spacing + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + composite.setFont(parent.getFont()); + ((GridLayout) composite.getLayout()).numColumns = 2; + // create image + Image image = composite.getDisplay().getSystemImage(SWT.ICON_ERROR); + if (image != null) { + Label label = new Label(composite, 0); + image.setBackground(label.getBackground()); + label.setImage(image); + label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING)); + } + // create message + if (message != null) { + Label label = new Label(composite, SWT.WRAP); + label.setText(message); + GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); + ; + label.setLayoutData(data); + label.setFont(parent.getFont()); + } + return composite; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/GenericWizardNode.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/GenericWizardNode.java new file mode 100644 index 000000000..62d4cec09 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/GenericWizardNode.java @@ -0,0 +1,69 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.IWizardNode; +import org.eclipse.swt.graphics.Point; + +/** + * @version 1.0 + * @author + */ +public abstract class GenericWizardNode implements IWizardNode { + + protected IWizard wizard; + + /** + * Constructor for GenericWizardNode. + */ + public GenericWizardNode() { + super(); + } + + /* + * @see IWizardNode#dispose() + */ + public void dispose() { + if (wizard != null) + wizard.dispose(); + } + + /* + * @see IWizardNode#getContents() + */ + public Point getContents() { + return null; + } + + public final IWizard getWizard() { + if (wizard == null) + wizard = createWizard(); + return wizard; + } + + /** + * Subclasses must override to create the wizard + */ + protected abstract IWizard createWizard(); + + /* + * @see IWizardNode#isContentCreated() + */ + public boolean isContentCreated() { + return wizard != null; + } + + /** + * @see org.eclipse.jface.wizard.IWizardNode#getExtent() + */ + public Point getExtent() { + return null; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ListMessageDialog.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ListMessageDialog.java new file mode 100644 index 000000000..aed38af51 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ListMessageDialog.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Aug 5, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; + +/** + * @author dfholt + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class ListMessageDialog extends MessageDialog { + protected String[] listItems; + protected List list; + + /** + * EJBSelectiveImportDialog constructor comment. + * + * @param parentShell + * org.eclipse.swt.widgets.Shell + * @param dialogTitle + * java.lang.String + * @param dialogTitleImage + * org.eclipse.swt.graphics.Image + * @param dialogMessage + * java.lang.String + * @param dialogImageType + * int + * @param dialogButtonLabels + * java.lang.String[] + * @param defaultIndex + * int + */ + public ListMessageDialog(org.eclipse.swt.widgets.Shell parentShell, String dialogTitle, org.eclipse.swt.graphics.Image dialogTitleImage, String dialogMessage, int dialogImageType, java.lang.String[] dialogButtonLabels, int defaultIndex) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex); + } + + /** + * ListMessageDialog constructor comment. + * + * @param parentShell + * org.eclipse.swt.widgets.Shell + * @param dialogTitle + * java.lang.String + * @param dialogTitleImage + * org.eclipse.swt.graphics.Image + * @param dialogMessage + * java.lang.String + * @param dialogImageType + * int + * @param dialogButtonLabels + * java.lang.String[] + * @param defaultIndex + * int + */ + public ListMessageDialog(org.eclipse.swt.widgets.Shell parentShell, String dialogTitle, org.eclipse.swt.graphics.Image dialogTitleImage, String dialogMessage, int dialogImageType, java.lang.String[] dialogButtonLabels, int defaultIndex, String[] names) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex); + listItems = names; + } + + /** + * Creates and returns the contents of an area of the dialog which appears below the message and + * above the button bar. + * <p> + * The default implementation of this framework method returns <code>null</code>. Subclasses + * may override. + * </p> + * + * @param the + * parent composite to contain the custom area + * @return the custom area control, or <code>null</code> + */ + protected Control createCustomArea(Composite parent) { + + Composite composite = new Composite(parent, 0); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + if (listItems != null) { + list = new List(composite, SWT.BORDER); + GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER); + list.setLayoutData(data); + list.setItems(listItems); + } + + return composite; + + } + + /** + * Convenience method to open a simple confirm (OK/Cancel) dialog. + * + * @param parent + * the parent shell of the dialog, or <code>null</code> if none + * @param title + * the dialog's title, or <code>null</code> if none + * @param message + * the message + * @return <code>true</code> if the user presses the OK button, <code>false</code> otherwise + */ + public static boolean openConfirm(Shell parent, String title, String message, String[] items) { + ListMessageDialog dialog = new ListMessageDialog(parent, title, null, // accept the default + // window icon + message, QUESTION, new String[]{IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 0, items); // OK + // is + // the + // default + return dialog.open() == 0; + } + + /** + * Convenience method to open a standard error dialog. + * + * @param parent + * the parent shell of the dialog, or <code>null</code> if none + * @param title + * the dialog's title, or <code>null</code> if none + * @param message + * the message + */ + public static void openError(Shell parent, String title, String message, String[] items) { + ListMessageDialog dialog = new ListMessageDialog(parent, title, null, // accept the default + // window icon + message, ERROR, new String[]{IDialogConstants.OK_LABEL}, 0, items); // ok is the + // default + dialog.open(); + return; + } + + /** + * Convenience method to open a standard information dialog. + * + * @param parent + * the parent shell of the dialog, or <code>null</code> if none + * @param title + * the dialog's title, or <code>null</code> if none + * @param message + * the message + */ + public static void openInformation(Shell parent, String title, String message, String[] items) { + ListMessageDialog dialog = new ListMessageDialog(parent, title, null, // accept the default + // window icon + message, INFORMATION, new String[]{IDialogConstants.OK_LABEL}, 0, items); + // ok is the default + dialog.open(); + return; + } + + /** + * Convenience method to open a simple Yes/No question dialog. + * + * @param parent + * the parent shell of the dialog, or <code>null</code> if none + * @param title + * the dialog's title, or <code>null</code> if none + * @param message + * the message + * @return <code>true</code> if the user presses the OK button, <code>false</code> otherwise + */ + public static boolean openQuestion(Shell parent, String title, String message, String[] items) { + ListMessageDialog dialog = new ListMessageDialog(parent, title, null, // accept the default + // window icon + message, QUESTION, new String[]{IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 0, items); // yes + // is + // the + // default + return dialog.open() == 0; + } + + /** + * Convenience method to open a standard warning dialog. + * + * @param parent + * the parent shell of the dialog, or <code>null</code> if none + * @param title + * the dialog's title, or <code>null</code> if none + * @param message + * the message + */ + public static void openWarning(Shell parent, String title, String message, String[] items) { + ListMessageDialog dialog = new ListMessageDialog(parent, title, null, // accept the default + // window icon + message, WARNING, new String[]{IDialogConstants.OK_LABEL}, 0, items); // ok is + // the + // default + dialog.open(); + return; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ListenerList.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ListenerList.java new file mode 100644 index 000000000..ce5671452 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ListenerList.java @@ -0,0 +1,77 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. US + * Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP + * Schedule Contract with IBM Corp. + */ + + +import java.awt.event.ActionListener; + +public class ListenerList { + private final static ActionListener[] NULL_ARRAY = new ActionListener[0]; + protected transient ActionListener[] listenerList = NULL_ARRAY; + + /** + * Add the listener as a listener of the specified type. + * + * @param t + * the type of the listener to be added + * @param l + * the listener to be added + */ + public synchronized void add(ActionListener l) { + if (l == null) + return; + if (listenerList == NULL_ARRAY) { + // if this is the first listener added, + // initialize the lists + listenerList = new ActionListener[]{l}; + } else { + // Otherwise copy the array and add the new listener + int i = listenerList.length; + ActionListener[] tmp = new ActionListener[i + 1]; + System.arraycopy(listenerList, 0, tmp, 0, i); + + tmp[i + 1] = l; + + listenerList = tmp; + } + } + + /** + * Return the total number of listeners for this listenerlist + */ + public int getListenerCount() { + return listenerList.length; + } + + public ActionListener[] getListenerList() { + return listenerList; + } + + public synchronized void remove(ActionListener l) { + if (l == null) + return; + int index = -1; + for (int i = listenerList.length - 1; i >= 0; i -= 1) { + if (listenerList[i].equals(l)) { + index = i; + break; + } + } + if (index != -1) { + ActionListener[] tmp = new ActionListener[listenerList.length - 1]; + // Copy the list up to index + System.arraycopy(listenerList, 0, tmp, 0, index); + // Copy from two past the index, up to + // the end of tmp (which is two elements + // shorter than the old list) + if (index < tmp.length) + System.arraycopy(listenerList, index + 1, tmp, index, tmp.length - index); + // set the listener array to the new array or null + listenerList = (tmp.length == 0) ? NULL_ARRAY : tmp; + } + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/NewProjectGroup.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/NewProjectGroup.java new file mode 100644 index 000000000..3faf52d79 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/NewProjectGroup.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Nov 3, 2003 + * + * To change the template for this generated file go to Window>Preferences>Java>Code + * Generation>Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.io.File; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModel; + +/** + * @author DABERG + * + * To change the template for this generated type comment go to Window>Preferences>Java>Code + * Generation>Code and Comments + */ +public class NewProjectGroup { + private ProjectCreationDataModel model; + public Text projectNameField = null; + protected Text locationPathField = null; + protected Button browseButton = null; + // constants + private static final int SIZING_TEXT_FIELD_WIDTH = 305; + // default values + private String defProjectNameLabel = WTPCommonUIResourceHandler.getString("Name_"); //$NON-NLS-1$ + private String defBrowseButtonLabel = WTPCommonUIResourceHandler.getString("Browse_");//$NON-NLS-1$ + private static final String defDirDialogLabel = "Directory"; //$NON-NLS-1$ + + private WTPDataModelSynchHelper synchHelper; + + /** + * @param parent + * @param style + */ + public NewProjectGroup(Composite parent, int style, ProjectCreationDataModel model) { + this.model = model; + synchHelper = new WTPDataModelSynchHelper(model); + buildComposites(parent); + } + + /** + * Create the controls within this composite + */ + public void buildComposites(Composite parent) { + createProjectNameGroup(parent); + createProjectLocationGroup(parent); + projectNameField.setFocus(); + } + + /** + * + */ + private void createProjectNameGroup(Composite parent) { + // set up project name label + Label projectNameLabel = new Label(parent, SWT.NONE); + projectNameLabel.setText(defProjectNameLabel); + GridData data = new GridData(); + projectNameLabel.setLayoutData(data); + // set up project name entry field + projectNameField = new Text(parent, SWT.BORDER); + data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = SIZING_TEXT_FIELD_WIDTH; + projectNameField.setLayoutData(data); + new Label(parent, SWT.NONE); // pad + synchHelper.synchText(projectNameField, ProjectCreationDataModel.PROJECT_NAME, new Control[]{projectNameLabel}); + } + + /** + * + */ + private void createProjectLocationGroup(Composite parent) { + // set up location path label + Label locationPathLabel = new Label(parent, SWT.NONE); + locationPathLabel.setText(WTPCommonUIResourceHandler.getString("Project_location_"));//$NON-NLS-1$ + GridData data = new GridData(); + locationPathLabel.setLayoutData(data); + // set up location path entry field + locationPathField = new Text(parent, SWT.BORDER | SWT.READ_ONLY); + data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = SIZING_TEXT_FIELD_WIDTH; + locationPathField.setLayoutData(data); + // set up browse button + browseButton = new Button(parent, SWT.PUSH); + browseButton.setText(defBrowseButtonLabel); + browseButton.setLayoutData((new GridData(GridData.FILL_HORIZONTAL))); + browseButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleLocationBrowseButtonPressed(); + } + }); + browseButton.setEnabled(true); + synchHelper.synchText(locationPathField, ProjectCreationDataModel.PROJECT_LOCATION, null); + } + + /** + * Open an appropriate directory browser + */ + protected void handleLocationBrowseButtonPressed() { + DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell()); + dialog.setMessage(defDirDialogLabel); + String dirName = model.getStringProperty(ProjectCreationDataModel.PROJECT_LOCATION); + if ((dirName != null) && (dirName.length() != 0)) { + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(dirName); + } + } + String selectedDirectory = dialog.open(); + if (selectedDirectory != null) { + model.setProperty(ProjectCreationDataModel.PROJECT_LOCATION, selectedDirectory); + } + } + + public void dispose() { + model.removeListener(synchHelper); + synchHelper.dispose(); + model = null; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/OverlayIcon.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/OverlayIcon.java new file mode 100644 index 000000000..a52cbe9a2 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/OverlayIcon.java @@ -0,0 +1,117 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2000, 2001, 2002 - All Rights + * Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by + * GSA ADP Schedule Contract with IBM Corp. + */ + + + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; + +public class OverlayIcon extends org.eclipse.jface.resource.CompositeImageDescriptor { + // //$NON-NLS-1$ + static final int DEFAULT_WIDTH = 16; + static final int DEFAULT_HEIGHT = 16; + private Point fSize = null; + private ImageDescriptor fBase; + private ImageDescriptor fOverlays[][]; + + public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays) { + fBase = base; + if (fBase == null) + fBase = ImageDescriptor.getMissingImageDescriptor(); + fOverlays = overlays; + fSize = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT); + } + + public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays, Point size) { + fBase = base; + if (fBase == null) + fBase = ImageDescriptor.getMissingImageDescriptor(); + fOverlays = overlays; + fSize = size; + } + + protected void drawBottomLeft(ImageDescriptor[] overlays) { + if (overlays == null) + return; + int length = overlays.length; + int x = 0; + for (int i = 0; i < 3; i++) { + if (i < length && overlays[i] != null) { + ImageData id = overlays[i].getImageData(); + drawImage(id, x, getSize().y - id.height); + x += id.width; + } + } + } + + protected void drawBottomRight(ImageDescriptor[] overlays) { + if (overlays == null) + return; + int length = overlays.length; + int x = getSize().x; + for (int i = 2; i >= 0; i--) { + if (i < length && overlays[i] != null) { + ImageData id = overlays[i].getImageData(); + x -= id.width; + drawImage(id, x, getSize().y - id.height); + } + } + } + + protected void drawCompositeImage(int width, int height) { + ImageData bg = fBase.getImageData(); + drawImage(bg, 0, 0); + + if (fOverlays != null) { + if (fOverlays.length > 0) + drawTopRight(fOverlays[0]); + + if (fOverlays.length > 1) + drawBottomRight(fOverlays[1]); + + if (fOverlays.length > 2) + drawBottomLeft(fOverlays[2]); + + if (fOverlays.length > 3) + drawTopLeft(fOverlays[3]); + } + } + + protected void drawTopLeft(ImageDescriptor[] overlays) { + if (overlays == null) + return; + int length = overlays.length; + int x = 0; + for (int i = 0; i < 3; i++) { + if (i < length && overlays[i] != null) { + ImageData id = overlays[i].getImageData(); + drawImage(id, x, 0); + x += id.width; + } + } + } + + protected void drawTopRight(ImageDescriptor[] overlays) { + if (overlays == null) + return; + int length = overlays.length; + int x = getSize().x; + for (int i = 2; i >= 0; i--) { + if (i < length && overlays[i] != null) { + ImageData id = overlays[i].getImageData(); + x -= id.width; + drawImage(id, x, 0); + } + } + } + + protected Point getSize() { + return fSize; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/RunnableWithProgressWrapper.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/RunnableWithProgressWrapper.java new file mode 100644 index 000000000..ec4846d91 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/RunnableWithProgressWrapper.java @@ -0,0 +1,80 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + + + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.wst.common.frameworks.internal.operations.IHeadlessRunnableWithProgress; + + +/** + * This is a wrapper for our IHeadlessRunnableWithProgress to the IRunnableWithProgress. This class + * needs to be used when running the operation from a IRunnableContext. + * + * @see IRunnableContext + * @see JavaUIPlugin#getRunnableWithProgress Creation date: (5/8/2001 1:28:45 PM) + * @author: Administrator + */ +public class RunnableWithProgressWrapper implements org.eclipse.jface.operation.IRunnableWithProgress { + // //$NON-NLS-1$ + private IHeadlessRunnableWithProgress headlessRunnable; + + /** + * RunnableWithProgressWrapper constructor comment. + */ + public RunnableWithProgressWrapper(IHeadlessRunnableWithProgress aHeadlessRunnableWithProgress) { + setHeadlessRunnable(aHeadlessRunnableWithProgress); + } + + /** + * Insert the method's description here. Creation date: (5/8/2001 1:29:52 PM) + * + * @return com.ibm.etools.j2ee.operations.IHeadlessRunnableWithProgress + */ + protected org.eclipse.wst.common.frameworks.internal.operations.IHeadlessRunnableWithProgress getHeadlessRunnable() { + return headlessRunnable; + } + + /** + * Runs this operation. Progress should be reported to the given progress monitor. This method + * is usually invoked by an <code>IRunnableContext</code>'s<code>run</code> method, which + * supplies the progress monitor. A request to cancel the operation should be honored and + * acknowledged by throwing <code>InterruptedException</code>. + * + * @param monitor + * the progress monitor to use to display progress and receive requests for + * cancelation + * @exception InvocationTargetException + * if the run method must propagate a checked exception, it should wrap it inside + * an <code>InvocationTargetException</code>; runtime exceptions are + * automatically wrapped in an <code>InvocationTargetException</code> by the + * calling context + * @exception InterruptedException + * if the operation detects a request to cancel, using + * <code>IProgressMonitor.isCanceled()</code>, it should exit by throwing + * <code>InterruptedException</code> + * + * @see IRunnableContext#run + */ + public void run(org.eclipse.core.runtime.IProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException { + getHeadlessRunnable().run(monitor); + } + + /** + * Insert the method's description here. Creation date: (5/8/2001 1:29:52 PM) + * + * @param newHeadlessRunnable + * com.ibm.etools.j2ee.operations.IHeadlessRunnableWithProgress + */ + protected void setHeadlessRunnable(org.eclipse.wst.common.frameworks.internal.operations.IHeadlessRunnableWithProgress newHeadlessRunnable) { + headlessRunnable = newHeadlessRunnable; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/SaveHandlerUI.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/SaveHandlerUI.java new file mode 100644 index 000000000..2309b783b --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/SaveHandlerUI.java @@ -0,0 +1,125 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. US + * Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP + * Schedule Contract with IBM Corp. + */ + + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.wst.common.frameworks.internal.ISaveHandler; +import org.eclipse.wst.common.frameworks.internal.SaveFailedException; +import org.eclispe.wst.common.frameworks.internal.plugin.WTPCommonPlugin; + + +public class SaveHandlerUI implements ISaveHandler { + public static final String SAVE_FAILED = WTPCommonPlugin.getResourceString("16"); //$NON-NLS-1$ + public static final String BEGINNING_MESSAGE = WTPCommonPlugin.getResourceString("17"); //$NON-NLS-1$ + protected boolean isYesToAll = false; + protected int referenceCount = 0; + + /** + * SaveHandlerUI constructor comment. + */ + public SaveHandlerUI() { + super(); + } + + /** + * access method comment. + */ + public void access() { + referenceCount++; + } + + protected Shell getParentShellForDialog() { + if (Display.getCurrent() != null) + return Display.getCurrent().getActiveShell(); + + return null; + } + + protected Display getDisplay() { + Display result = Display.getCurrent(); + return result == null ? Display.getDefault() : result; + } + + public void handleSaveFailed(SaveFailedException ex, IProgressMonitor monitor) { + if (referenceCount > 1) + //Let the outermost reference handle it + throw ex; + String exMsg = ex.getInnerMostNestedException() == null ? ex.getMessage() : ex.getInnerMostNestedException().getMessage(); + final String message = BEGINNING_MESSAGE + ":\n" + exMsg;//$NON-NLS-1$ + getDisplay().syncExec(new Runnable() { + public void run() { + MessageDialog.openError(getParentShellForDialog(), SAVE_FAILED, message); + } + }); + if (monitor != null) + monitor.setCanceled(true); + else + throw ex; + } + + protected boolean promptUserToSaveReadOnly(IFile aFile) { + + String[] buttonStrings = {WTPCommonPlugin.getResourceString("Yes_UI_"), WTPCommonPlugin.getResourceString("Yes_To_All_UI_"), WTPCommonPlugin.getResourceString("No_UI_")}; //$NON-NLS-3$ = "No" //$NON-NLS-2$ = "Yes To All" //$NON-NLS-1$ = "Yes" + String title = WTPCommonPlugin.getResourceString("Saving_Read-Only_File_UI_"); //$NON-NLS-1$ = "Saving Read-Only File" + String message = WTPCommonPlugin.getResourceString("2concat_INFO_", (new Object[]{aFile.getFullPath()})); //$NON-NLS-1$ = "The file {0} is read-only and cannot be saved. Would you like to make it editable and save anyway?" + + final MessageDialog dialog = new MessageDialog(getParentShellForDialog(), title, null, // accept + // the + // default + // window + // icon + message, MessageDialog.QUESTION, buttonStrings, 0); // Yes is the default + + final int[] ret = new int[1]; + getDisplay().syncExec(new Runnable() { + public void run() { + dialog.setBlockOnOpen(true); + ret[0] = dialog.open(); + } + }); + + switch (ret[0]) { + case 0 : { + return true; + } + case 1 : { + isYesToAll = true; + return true; + } + case 2 : { + return false; + } + } + return false; + } + + /** + * release method comment. + */ + public void release() { + referenceCount--; + if (referenceCount == 0) + isYesToAll = false; + + } + + /** + * shouldContinueAndMakeFileEditable method comment. + */ + public boolean shouldContinueAndMakeFileEditable(IFile aFile) { + boolean yes = isYesToAll || promptUserToSaveReadOnly(aFile); + if (yes) + aFile.setReadOnly(false); + + return yes; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimedKeyListener.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimedKeyListener.java new file mode 100644 index 000000000..0106d5233 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimedKeyListener.java @@ -0,0 +1,131 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + +import java.awt.event.ActionListener; + +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.widgets.Widget; + +/** + * Insert the type's description here. Creation date: (8/30/2001 4:00:28 PM) + * + * @author: Administrator + */ +public class TimedKeyListener extends Timer implements KeyListener, MouseListener, MouseTrackListener, ModifyListener { + + protected Widget monitoringTarget; + + private final static int TIME_LIMIT = 200; + + /** + * J2EETimedKeyListener constructor comment. + * + * @param delay + * int + * @param listener + * java.awt.event.ActionListener + */ + public TimedKeyListener(int delay, ActionListener listener) { + super(delay, listener); + setRepeats(false); + } + + /** + * Insert the method's description here. Creation date: (8/30/2001 4:43:33 PM) + * + * @param a + * java.awt.event.ActionListener + */ + public TimedKeyListener(ActionListener listener) { + this(TIME_LIMIT, listener); + } + + /** + * Sent when a key is pressed on the system keyboard. + * + * @param e + * an event containing information about the key press + */ + public void keyPressed(org.eclipse.swt.events.KeyEvent e) { + } + + /** + * Sent when a key is released on the system keyboard. + * + * @param e + * an event containing information about the key release + */ + public void keyReleased(org.eclipse.swt.events.KeyEvent e) { + // Replaced with SWT.Modify -- see modifyText() in this class + // monitoringTarget = (Widget) e.getSource(); + // restart(); + } + + /** + * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(MouseEvent) + */ + public void mouseDoubleClick(MouseEvent e) { + } + + /** + * @see org.eclipse.swt.events.MouseListener#mouseDown(MouseEvent) + */ + public void mouseDown(MouseEvent e) { + } + + /** + * @see org.eclipse.swt.events.MouseListener#mouseUp(MouseEvent) + */ + public void mouseUp(MouseEvent e) { + monitoringTarget = (Widget) e.getSource(); + restart(); + } + + /** + * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter(MouseEvent) + */ + public void mouseEnter(MouseEvent e) { + } + + /** + * @see org.eclipse.swt.events.MouseTrackListener#mouseExit(MouseEvent) + */ + public void mouseExit(MouseEvent e) { + } + + /** + * @see org.eclipse.swt.events.MouseTrackListener#mouseHover(MouseEvent) + */ + public void mouseHover(MouseEvent e) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.ui.util.Timer#getSource() + */ + protected Object getSource() { + return monitoringTarget; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) + */ + public void modifyText(ModifyEvent e) { + monitoringTarget = (Widget) e.getSource(); + restart(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimedModifyListener.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimedModifyListener.java new file mode 100644 index 000000000..72b1ab6e8 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimedModifyListener.java @@ -0,0 +1,51 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + +/** + * This class perform the same function as the J2EETimedKeyListener but using the Modify SWT event + * instead of the KeyUp. Creation date: (9/10/2001 11:46:51 AM) + * + * @author: Administrator + */ +import java.awt.event.ActionListener; + +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Widget; + +public class TimedModifyListener extends TimedKeyListener implements ModifyListener { + /** + * J2EETimedModefyListener constructor comment. + * + * @param delay + * int + * @param listener + * java.awt.event.ActionListener + */ + public TimedModifyListener(int delay, ActionListener listener) { + super(delay, listener); + } + + /** + * J2EETimedModefyListener constructor comment. + * + * @param listener + * java.awt.event.ActionListener + */ + public TimedModifyListener(ActionListener listener) { + super(listener); + } + + /* + * Re/Start the timer + */ + public void modifyText(org.eclipse.swt.events.ModifyEvent e) { + monitoringTarget = (Widget) e.getSource(); + restart(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/Timer.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/Timer.java new file mode 100644 index 000000000..f200e24a5 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/Timer.java @@ -0,0 +1,252 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. US + * Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP + * Schedule Contract with IBM Corp. + */ + + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.event.EventListenerList; + + + +public class Timer { + /** + * DoPostEvent is a runnable class that fires actionEvents to the listeners on the + * EventDispatchThread, via invokeLater. + * + * @see #post + */ + class DoPostEvent implements Runnable { + public void run() { + if (eventQueued) { + fireActionPerformed(new ActionEvent(getSource(), 0, null)); + cancelEvent(); + } + } + + Timer getTimer() { + return Timer.this; + } + } + + protected ListenerList listenerList = new ListenerList(); + boolean eventQueued = false; + int initialDelay, delay; + boolean repeats = true, coalesce = true; + private Runnable doPostEvent; + // These fields are maintained by TimerQueue. + // eventQueued can also be reset by the TimerQueue, but will only ever + // happen in applet case when TimerQueues thread is destroyed. + long expirationTime; + Timer nextTimer; + boolean running; + + /** + * Creates a Timer that will notify its listeners every <i>delay </i> milliseconds. + * + * @param delay + * The number of milliseconds between listener notification + * @param listener + * An initial listener + * @see #setInitialDelay + * @see #setRepeats + */ + public Timer(int delay, ActionListener listener) { + super(); + this.delay = delay; + this.initialDelay = delay; + + doPostEvent = new DoPostEvent(); + + if (listener != null) { + addActionListener(listener); + } + } + + /** + * Adds an actionListener to the Timer + */ + public void addActionListener(ActionListener listener) { + listenerList.add(listener); + } + + synchronized void cancelEvent() { + eventQueued = false; + } + + /** + * Notify all listeners that have registered interest for notification on this event type. The + * event instance is lazily created using the parameters passed into the fire method. + * + * @see EventListenerList + */ + protected void fireActionPerformed(ActionEvent e) { + // Guaranteed to return a non-null array + ActionListener[] listeners = listenerList.getListenerList(); + + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 1; i >= 0; i -= 1) { + listeners[i].actionPerformed(e); + } + } + + /** + * Returns the Timer's delay. + * + * @see #setDelay + */ + public int getDelay() { + return delay; + } + + /** + * Returns the Timer's initial delay. + * + * @see #setDelay + */ + public int getInitialDelay() { + return initialDelay; + } + + /** + * Returns <b>true </b> if the Timer coalesces multiple pending <b>performCommand() </b> + * messages. + * + * @see #setCoalesce + */ + public boolean isCoalesce() { + return coalesce; + } + + /** + * Returns <b>true </b> if the Timer will send a <b>actionPerformed() </b> message to its + * listeners multiple times. + * + * @see #setRepeats + */ + public boolean isRepeats() { + return repeats; + } + + /** + * Returns <b>true </b> if the Timer is running. + * + * @see #start + */ + public boolean isRunning() { + return timerQueue().containsTimer(this); + } + + synchronized void post() { + if (!eventQueued) { + eventQueued = true; + org.eclipse.swt.widgets.Display.getDefault().asyncExec(doPostEvent); + } + } + + /** + * Removes an ActionListener from the Timer. + */ + public void removeActionListener(ActionListener listener) { + listenerList.remove(listener); + } + + /** + * Restarts a Timer, canceling any pending firings, and causing it to fire with its initial + * dely. + */ + public void restart() { + stop(); + start(); + } + + /** + * Sets whether the Timer coalesces multiple pending ActionEvent firings. A busy application may + * not be able to keep up with a Timer's message generation, causing multiple + * <b>actionPerformed() </b> message sends to be queued. When processed, the application sends + * these messages one after the other, causing the Timer's listeners to receive a sequence of + * <b>actionPerformed() </b> messages with no delay between them. Coalescing avoids this + * situation by reducing multiple pending messages to a single message send. Timers coalesce + * their message sends by default. + */ + public void setCoalesce(boolean flag) { + coalesce = flag; + } + + /** + * Sets the Timer's delay, the number of milliseconds between successive <b>actionPerfomed() + * </b> messages to its listeners + * + * @see #setInitialDelay + */ + public void setDelay(int delay) { + if (delay < 0) { + String msg = WTPCommonUIResourceHandler.getString("Timer_UI_0", new Object[]{Integer.toString(delay)}); //$NON-NLS-1$ + throw new IllegalArgumentException(msg); + } + this.delay = delay; + } + + /** + * Sets the Timer's initial delay. This will be used for the first "ringing" of the Timer only. + * Subsequent ringings will be spaced using the delay property. + * + * @see #setDelay + */ + public void setInitialDelay(int initialDelay) { + if (initialDelay < 0) { + String msg = WTPCommonUIResourceHandler.getString("Timer_UI_1", new Object[]{Integer.toString(initialDelay)}); //$NON-NLS-1$ + throw new IllegalArgumentException(msg); + } + this.initialDelay = initialDelay; + } + + /** + * If <b>flag </b> is <b>false </b>, instructs the Timer to send <b>actionPerformed() </b> to + * its listeners only once, and then stop. + */ + public void setRepeats(boolean flag) { + repeats = flag; + } + + /** + * Starts the Timer, causing it to send <b>actionPerformed() </b> messages to its listeners. + * + * @see #stop + */ + public void start() { + timerQueue().addTimer(this, System.currentTimeMillis() + getInitialDelay()); + } + + /** + * Stops a Timer, causing it to stop sending <b>actionPerformed() </b> messages to its Target. + * + * @see #start + */ + public void stop() { + timerQueue().removeTimer(this); + cancelEvent(); + } + + /** + * Returns the timer queue. + */ + TimerQueue timerQueue() { + return TimerQueue.singleton(); + } + + /** + * Return the source for the ActionEvent that is fired. + * + * @return + */ + protected Object getSource() { + return this; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimerQueue.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimerQueue.java new file mode 100644 index 000000000..3ca9284c8 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/TimerQueue.java @@ -0,0 +1,229 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +package org.eclipse.wst.common.frameworks.internal.ui; + + + + +class TimerQueue implements Runnable { + private static TimerQueue singleton; + Timer firstTimer; + boolean running; + private static final Object classLock = new Object(); + + /** + * Constructor for TimerQueue. + */ + public TimerQueue() { + super(); + + // Now start the TimerQueue thread. + start(); + } + + synchronized void addTimer(Timer timer, long expirationTime) { + Timer previousTimer; + Timer nextTimer; + + // If the Timer is already in the queue, then ignore the add. + if (timer.running) { + return; + } + + previousTimer = null; + nextTimer = firstTimer; + + // Insert the Timer into the linked list in the order they will + // expire. If two timers expire at the same time, put the newer entry + // later so they expire in the order they came in. + + while (nextTimer != null) { + if (nextTimer.expirationTime > expirationTime) + break; + + previousTimer = nextTimer; + nextTimer = nextTimer.nextTimer; + } + + if (previousTimer == null) { + firstTimer = timer; + } else { + previousTimer.nextTimer = timer; + } + + timer.expirationTime = expirationTime; + timer.nextTimer = nextTimer; + timer.running = true; + notify(); + } + + synchronized boolean containsTimer(Timer timer) { + return timer.running; + } + + /** + * If there are a ton of timers, this method may never return. It loops checking to see if the + * head of the Timer list has expired. If it has, it posts the Timer and reschedules it if + * necessary. + */ + synchronized long postExpiredTimers() { + Timer timer; + long currentTime; + long timeToWait; + + // The timeToWait we return should never be negative and only be zero + // when we have no Timers to wait for. + + do { + timer = firstTimer; + if (timer == null) + return 0; + + currentTime = System.currentTimeMillis(); + timeToWait = timer.expirationTime - currentTime; + + if (timeToWait <= 0) { + try { + timer.post(); // have timer post an event + } catch (SecurityException e) { + } + + // Remove the timer from the queue + removeTimer(timer); + + // This tries to keep the interval uniform at + // the cost of drift. + if (timer.isRepeats()) { + addTimer(timer, currentTime + timer.getDelay()); + } + } + + // Allow other threads to call addTimer() and removeTimer() + // even when we are posting Timers like mad. Since the wait() + // releases the lock, be sure not to maintain any state + // between iterations of the loop. + + try { + wait(1); + } catch (InterruptedException e) { + } + } while (timeToWait <= 0); + + return timeToWait; + } + + synchronized void removeTimer(Timer timer) { + Timer previousTimer; + Timer nextTimer; + boolean found; + + if (!timer.running) + return; + + previousTimer = null; + nextTimer = firstTimer; + found = false; + + while (nextTimer != null) { + if (nextTimer == timer) { + found = true; + break; + } + + previousTimer = nextTimer; + nextTimer = nextTimer.nextTimer; + } + + if (!found) + return; + + if (previousTimer == null) { + firstTimer = timer.nextTimer; + } else { + previousTimer.nextTimer = timer.nextTimer; + } + + timer.expirationTime = 0; + timer.nextTimer = null; + timer.running = false; + } + + public synchronized void run() { + long timeToWait; + + try { + while (running) { + timeToWait = postExpiredTimers(); + try { + wait(timeToWait); + } catch (InterruptedException e) { + } + } + } catch (ThreadDeath td) { + running = false; + // Mark all the timers we contain as not being queued. + Timer timer = firstTimer; + while (timer != null) { + timer.eventQueued = false; + timer = timer.nextTimer; + } + synchronized (this) { + if (!this.running) + start(); + } + throw td; + } + } + + public static TimerQueue singleton() { + if (singleton == null) + synchronized (classLock) { + singleton = new TimerQueue(); + } + return singleton; + } + + synchronized void start() { + if (running) { + throw new RuntimeException(WTPCommonUIResourceHandler.getString("TimerQueue_ERROR_0")); //$NON-NLS-1$ + } + Thread timerThread = new Thread(this, "TimerQueue");//$NON-NLS-1$ + try { + timerThread.setDaemon(true); + } catch (SecurityException e) { + } + timerThread.start(); + running = true; + } + + synchronized void stop() { + running = false; + notify(); + } + + public synchronized String toString() { + StringBuffer buf; + Timer nextTimer; + + buf = new StringBuffer(); + buf.append("TimerQueue (");//$NON-NLS-1$ + + nextTimer = firstTimer; + while (nextTimer != null) { + buf.append(nextTimer.toString()); + + nextTimer = nextTimer.nextTimer; + if (nextTimer != null) + buf.append(", ");//$NON-NLS-1$ + } + + buf.append(")");//$NON-NLS-1$ + return buf.toString(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIEnablementIdentifier.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIEnablementIdentifier.java new file mode 100644 index 000000000..c46f4d69a --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIEnablementIdentifier.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Feb 12, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.core.resources.IProject; +import org.eclipse.ui.activities.IActivityManager; +import org.eclipse.ui.activities.IIdentifier; +import org.eclipse.ui.activities.IIdentifierListener; +import org.eclipse.ui.activities.IdentifierEvent; +import org.eclispe.wst.common.frameworks.internal.enablement.EnablementIdentifier; +import org.eclispe.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent; +import org.eclispe.wst.common.frameworks.internal.enablement.IEnablementManager; + + +/** + * @author schacher + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +class UIEnablementIdentifier extends EnablementIdentifier implements IIdentifierListener { + + private IIdentifier activityIdentifier; + + /** + * @param id + * @param project + */ + public UIEnablementIdentifier(String id, IProject project) { + super(id, project); + activityIdentifier = getActivityManager().getIdentifier(id); + activityIdentifier.addIdentifierListener(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.activities.IIdentifierListener#identifierChanged(org.eclipse.ui.activities.IdentifierEvent) + */ + public void identifierChanged(IdentifierEvent identifierEvent) { + boolean enabledChanged = resetEnabled(); + EnablementIdentifierEvent evt = new EnablementIdentifierEvent(this, false, enabledChanged); + fireIdentifierChanged(evt); + } + + protected IActivityManager getActivityManager() { + return ((UIEnablementManager) IEnablementManager.INSTANCE).getActivityManager(); + } + + /* + * (non-Javadoc) + * + * @see org.eclispe.wst.common.frameworks.internal.enablement.EnablementIdentifier#getNewEnabled() + */ + protected boolean getNewEnabled() { + return activityIdentifier.isEnabled() && super.getNewEnabled(); + } + + + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIEnablementManager.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIEnablementManager.java new file mode 100644 index 000000000..47a1930ef --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIEnablementManager.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Feb 3, 2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.core.resources.IProject; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.activities.IActivityManager; +import org.eclipse.ui.activities.IWorkbenchActivitySupport; +import org.eclispe.wst.common.frameworks.internal.enablement.EnablementIdentifier; +import org.eclispe.wst.common.frameworks.internal.enablement.EnablementManager; + +/** + * @author mdelder + */ +public class UIEnablementManager extends EnablementManager { + + private IWorkbenchActivitySupport activitySupport = null; + + public UIEnablementManager() { + super(); + } + + protected IActivityManager getActivityManager() { + return getActivitySupport().getActivityManager(); + } + + /** + * @return Returns the activitySupport. + */ + protected IWorkbenchActivitySupport getActivitySupport() { + if (activitySupport == null) + activitySupport = PlatformUI.getWorkbench().getActivitySupport(); + return activitySupport; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.enablement.EnablementManager#createIdentifier(java.lang.String, + * org.eclipse.core.resources.IProject) + */ + protected EnablementIdentifier createIdentifier(String identifierId, IProject project) { + return new UIEnablementIdentifier(identifierId, project); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIOperationHandler.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIOperationHandler.java new file mode 100644 index 000000000..b596e8abb --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UIOperationHandler.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Aug 5, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler; + + +/** + * @author dfholt + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class UIOperationHandler implements IOperationHandler { + protected Shell parentShell; + final public static String DEFAULT_INFORMATION = "Information";//EMFWorkbenchUIResourceHandler.getString("Information_UI__UI_"); + // //$NON-NLS-1$ + // //$NON-NLS-1$ = "Information" + final public static String DEFAULT_ERROR = "Error";// EMFWorkbenchUIResourceHandler.getString("Error_UI_"); + // //$NON-NLS-1$ + // //$NON-NLS-1$ = "Error" + final public static String DEFAULT_CONFIRM = "Confirm";//EMFWorkbenchUIResourceHandler.getString("Confirm_UI_"); + // //$NON-NLS-1$ + // //$NON-NLS-1$ = "Confirm" + protected String informationTitle = DEFAULT_INFORMATION; + protected String confirmTitle = DEFAULT_CONFIRM; + protected String errorTitle = DEFAULT_ERROR; + + /** + * UIOperationHandler constructor comment. + */ + public UIOperationHandler() { + super(); + } + + /** + * UIOperationHandler constructor comment. + */ + public UIOperationHandler(Shell parent) { + super(); + parentShell = parent; + } + + /** + * A decision needs to made as to whether an action/operation can continue + */ + public boolean canContinue(String message) { + return MessageDialog.openQuestion(getParentShell(), getConfirmTitle(), message); + } + + /** + * A decision needs to made as to whether an action/operation can continue + */ + public boolean canContinue(String message, String[] items) { + return ListMessageDialog.openQuestion(getParentShell(), getConfirmTitle(), message, items); + } + + /** + * A decision needs to made as to whether an action/operation can continue. The boolean array + * will return two booleans. The first indicates their response to the original question and the + * second indicates if they selected the apply to all check box. + * + * Return the return code for the dialog. 0 = Yes, 1 = Yes to all, 2 = No + */ + public int canContinueWithAllCheck(String message) { + MessageDialog dialog = new MessageDialog(getParentShell(), getConfirmTitle(), null, // accept + // the + // default + // window + // icon + message, MessageDialog.QUESTION, new String[]{IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL}, 1); // yes + // is + // the + // default + return dialog.open(); + } + + /* + * (non-Javadoc) + * + * @see com.ibm.etools.j2ee.operations.IOperationHandler#canContinueWithAllCheckAllowCancel(java.lang.String) + */ + public int canContinueWithAllCheckAllowCancel(String message) { + MessageDialog dialog = new MessageDialog(getParentShell(), getConfirmTitle(), null, // accept + // the + // default + // window + // icon + message, MessageDialog.QUESTION, new String[]{IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}, 1); // yes + // is + // the + // default + return dialog.open(); + } + + /** + * An error has occurred + */ + public void error(String message) { + MessageDialog.openError(getParentShell(), getErrorTitle(), message); + } + + /** + * The dialog title to be used for confirmations + */ + public java.lang.String getConfirmTitle() { + return confirmTitle; + } + + /** + * The dialog title to be used for errors + */ + public java.lang.String getErrorTitle() { + return errorTitle; + } + + /** + * The dialog title to be used for information + */ + public java.lang.String getInformationTitle() { + return informationTitle; + } + + public Shell getParentShell() { + if (parentShell == null) + parentShell = WTPUIPlugin.getPluginWorkbench().getActiveWorkbenchWindow().getShell(); + + return parentShell; + } + + /** + * An informational message needs to be presented + */ + public void inform(String message) { + MessageDialog.openInformation(getParentShell(), getInformationTitle(), message); + } + + /** + * Insert the method's description here. Creation date: (8/9/2001 11:51:36 AM) + * + * @param newConfirmTitle + * java.lang.String + */ + public void setConfirmTitle(java.lang.String newConfirmTitle) { + confirmTitle = newConfirmTitle; + } + + /** + * Insert the method's description here. Creation date: (8/9/2001 11:51:36 AM) + * + * @param newErrorTitle + * java.lang.String + */ + public void setErrorTitle(java.lang.String newErrorTitle) { + errorTitle = newErrorTitle; + } + + /** + * Insert the method's description here. Creation date: (8/9/2001 11:51:36 AM) + * + * @param newInformationTitle + * java.lang.String + */ + public void setInformationTitle(java.lang.String newInformationTitle) { + informationTitle = newInformationTitle; + } + + /** + * @see com.ibm.etools.j2ee.operations.IOperationHandler#getContext() + */ + public Object getContext() { + return getParentShell(); + } + + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UITesterImpl.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UITesterImpl.java new file mode 100644 index 000000000..e22ce99af --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/UITesterImpl.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Oct 27, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.Workbench; + +import com.ibm.wtp.common.UITester; + + +/** + * @author schacher + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class UITesterImpl implements UITester { + + /** + * + */ + public UITesterImpl() { + super(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.UITester#isCurrentContextUI() + */ + public boolean isCurrentContextUI() { + try { + return PlatformUI.isWorkbenchRunning() || ((Workbench) PlatformUI.getWorkbench()).isClosing(); + } catch (RuntimeException e) { + return false; + } + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ValidationStatus.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ValidationStatus.java new file mode 100644 index 000000000..926f899bc --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/ValidationStatus.java @@ -0,0 +1,163 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + + +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.swt.widgets.Control; + +/** + * This object encompas a set of Validation status Creation date: (9/10/2001 5:35:12 PM) + * + * @author: Administrator + */ +public class ValidationStatus { + Hashtable errMsgs = new Hashtable(); + Hashtable errStatus = new Hashtable(); + Hashtable tControls = new Hashtable(); + Map warnMsgs; + Map warnStatus; + + /** + * ValidationStatus constructor comment. + */ + public ValidationStatus() { + super(); + } + + /* + * Look for any error. If there is more than one, return errors according to their key. i.e., + * lower key errors will be returned first. + */ + public String getLastErrMsg() { + + Enumeration e = errStatus.keys(); + String[] errs = new String[errStatus.size()]; + for (int i = 0; i < errs.length; i++) + errs[i] = null; + boolean foundOne = false; + while (e.hasMoreElements()) { + Integer key = (Integer) e.nextElement(); + if (!((Boolean) errStatus.get(key)).booleanValue()) { + errs[key.intValue() % errs.length] = (String) errMsgs.get(key); + foundOne = true; + } + } + if (foundOne) + for (int i = 0; i < errs.length; i++) + if (errs[i] != null) + return errs[i]; + return null; + } + + private Map getWarningMsgs() { + if (warnMsgs == null) + warnMsgs = new HashMap(); + return warnMsgs; + } + + private Map getWarningStatusMap() { + if (warnStatus == null) + warnStatus = new HashMap(); + return warnStatus; + } + + /* + * Look for any warning. If there is more than one, return warnings according to their key. + * i.e., lower key errors will be returned first. + */ + public String getLastWarningMsg() { + if (warnStatus == null) + return null; + Iterator e = warnStatus.keySet().iterator(); + String[] warns = new String[warnStatus.size()]; + for (int i = 0; i < warns.length; i++) + warns[i] = null; + boolean foundOne = false; + while (e.hasNext()) { + Integer key = (Integer) e.next(); + if (!((Boolean) warnStatus.get(key)).booleanValue()) { + warns[key.intValue() % warns.length] = (String) warnMsgs.get(key); + foundOne = true; + } + } + if (foundOne) + for (int i = 0; i < warns.length; i++) + if (warns[i] != null) + return warns[i]; + return null; + } + + public String getLastErrMsgAndFocus() { + + Enumeration e = errStatus.keys(); + + Integer theOne = null; + while (e.hasMoreElements()) { + Integer key = (Integer) e.nextElement(); + if (!((Boolean) errStatus.get(key)).booleanValue()) { + if (theOne == null || key.intValue() < theOne.intValue()) { + theOne = key; + } + } + } + if (theOne != null) { + Control control = (Control) tControls.get(theOne); + if (control != null) { + control.setFocus(); + } + return ((String) errMsgs.get(theOne)); + } + return null; + } + + public boolean hasError(Integer key) { + Boolean stat = (Boolean) errStatus.get(key); + if (stat != null) + return stat.booleanValue(); + return true; + } + + public void setControl(Integer key, Control control) { + tControls.put(key, control); + } + + public void setErrorStatus(Integer key, Boolean status, String msg) { + errMsgs.put(key, msg); + errStatus.put(key, status); + } + + public void setErrorStatus(Integer key, String msg) { + errMsgs.put(key, msg); + errStatus.put(key, new Boolean(false)); + } + + public void setWarningStatus(Integer key, String msg) { + getWarningMsgs().put(key, msg); + getWarningStatusMap().put(key, new Boolean(false)); + } + + public void setOKStatus(Integer key) { + errMsgs.put(key, ""); //$NON-NLS-1$ + errStatus.put(key, new Boolean(true)); + if (warnMsgs != null) + warnMsgs.put(key, ""); //$NON-NLS-1$ + if (warnStatus != null) + warnStatus.put(key, new Boolean(true)); + } + + public void setStatus(Integer key, boolean ok, String msg) { + errMsgs.put(key, msg); + errStatus.put(key, new Boolean(ok)); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPActivityBridgeHelperImpl.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPActivityBridgeHelperImpl.java new file mode 100644 index 000000000..a8440ebed --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPActivityBridgeHelperImpl.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 4, 2004 + * + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.ui.IPluginContribution; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.activities.IActivityManager; +import org.eclipse.ui.activities.IIdentifier; +import org.eclipse.ui.activities.IWorkbenchActivitySupport; +import org.eclipse.ui.activities.WorkbenchActivityHelper; +import org.eclipse.wst.common.frameworks.internal.activities.WTPActivityBridgeHelper; + + +/** + * @author jsholl + * + */ +public class WTPActivityBridgeHelperImpl implements WTPActivityBridgeHelper { + + private IWorkbenchActivitySupport workbenchActivitySupport = null; + private IActivityManager activityManager = null; + + public WTPActivityBridgeHelperImpl() { + workbenchActivitySupport = PlatformUI.getWorkbench().getActivitySupport(); + activityManager = workbenchActivitySupport.getActivityManager(); + } + + public void enableActivity(String activityID, boolean enabled) { + Set enabledActivities = activityManager.getEnabledActivityIds(); + Set newEnabledActivities = null; + if (enabled && !enabledActivities.contains(activityID)) { + newEnabledActivities = new HashSet(); + newEnabledActivities.addAll(enabledActivities); + newEnabledActivities.add(activityID); + } + if (!enabled && enabledActivities.contains(activityID)) { + newEnabledActivities = new HashSet(); + newEnabledActivities.addAll(enabledActivities); + newEnabledActivities.remove(activityID); + } + if (null != newEnabledActivities) { + workbenchActivitySupport.setEnabledActivityIds(newEnabledActivities); + } + } + + public Set getEnabledActivityIds() { + return activityManager.getEnabledActivityIds(); + } + + public void setEnabledActivityIds(Set activityIDs) { + workbenchActivitySupport.setEnabledActivityIds(activityIDs); + } + + public Set getActivityIDsFromContribution(final String localID, final String pluginID) { + IIdentifier identifier = activityManager.getIdentifier(WorkbenchActivityHelper.createUnifiedId(new IPluginContribution() { + public String getLocalId() { + return localID; + } + + public String getPluginId() { + return pluginID; + } + })); + return identifier.getActivityIds(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPActivityHelper.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPActivityHelper.java new file mode 100644 index 000000000..37a0221a9 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPActivityHelper.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Apr 9, 2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.ui.IPluginContribution; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.activities.IIdentifier; +import org.eclipse.ui.activities.IWorkbenchActivitySupport; + +/** + * @author jsholl + * + * To change the template for this generated type comment go to Window - Preferences - Java - Code + * Generation - Code and Comments + */ +public class WTPActivityHelper { + + /** + * @return whether the UI is set up to filter contributions (has defined activity categories). + */ + public static final boolean isFiltering() { + return !PlatformUI.getWorkbench().getActivitySupport().getActivityManager().getDefinedActivityIds().isEmpty(); + } + + public static boolean allowUseOf(Object object) { + if (!isFiltering()) + return true; + if (object instanceof IPluginContribution) { + IPluginContribution contribution = (IPluginContribution) object; + if (contribution.getPluginId() != null) { + IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI.getWorkbench().getActivitySupport(); + IIdentifier identifier = workbenchActivitySupport.getActivityManager().getIdentifier(createUnifiedId(contribution)); + return identifier.isEnabled(); + } + } + return true; + } + + + public static final String createUnifiedId(IPluginContribution contribution) { + if (contribution.getPluginId() != null) + return contribution.getPluginId() + '/' + contribution.getLocalId(); + return contribution.getLocalId(); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPCommonUIResourceHandler.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPCommonUIResourceHandler.java new file mode 100644 index 000000000..00eb1f0c0 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPCommonUIResourceHandler.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 23, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * @author vijayb + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Style - Code Templates + */ +public class WTPCommonUIResourceHandler { + + private static ResourceBundle fgResourceBundle; + + /** + * Returns the resource bundle used by all classes in this Project + */ + public static ResourceBundle getResourceBundle() { + try { + return ResourceBundle.getBundle("wtpcommonui"); //$NON-NLS-1$ + } catch (MissingResourceException e) { + // does nothing - this method will return null and + // getString(String) will return the key + // it was called with + } + return null; + } + + public static String getString(String key) { + if (fgResourceBundle == null) { + fgResourceBundle = getResourceBundle(); + } + + if (fgResourceBundle != null) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!"; //$NON-NLS-2$//$NON-NLS-1$ + } + } + return "!" + key + "!"; //$NON-NLS-2$//$NON-NLS-1$ + } + + public static String getString(String key, Object[] args) { + + try { + return MessageFormat.format(getString(key), args); + } catch (IllegalArgumentException e) { + return getString(key); + } + + } + + public static String getString(String key, Object[] args, int x) { + return getString(key); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPDataModelSynchHelper.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPDataModelSynchHelper.java new file mode 100644 index 000000000..194806278 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPDataModelSynchHelper.java @@ -0,0 +1,679 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Nov 3, 2003 + * + * To change the template for this generated file go to Window>Preferences>Java>Code Generation>Code and + * Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelEvent; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelListener; +import org.eclipse.wst.common.frameworks.internal.operations.WTPPropertyDescriptor; + + +/** + * @author jsholl + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class WTPDataModelSynchHelper implements WTPOperationDataModelListener { + protected WTPOperationDataModel dataModel; + protected Map widgetToPropertyHash; + protected Map propertyToWidgetHash; + protected Map widgetToDepControls; + /** + * @deprecated + */ + private Map deprecatedConvertPropertyNames; //TODO delete this + /** + * @deprecated + */ + private HashSet deprecatedCombos; //TODO delete this + + protected String currentProperty; + protected Widget currentWidget; + protected boolean ignoreModifyEvent = false; + + private class ModifyTextListener implements ModifyListener { + public void modifyText(ModifyEvent e) { + if (ignoreModifyEvent) + return; + Text text = (Text) e.getSource(); + if (currentWidget == text) + return; + String propertyName = (String) widgetToPropertyHash.get(text); + setProperty(propertyName, text.getText()); + } + } + + private ModifyTextListener modifyTextListener; + private TimedModifyListener timedModifyListener; + + /** + * @deprecated + * @author jsholl + */ + private class ComboListenerDeprecated implements SelectionListener, ModifyListener { //TODO delete this + public void modifyText(ModifyEvent e) { + if (ignoreModifyEvent) + return; + Combo combo = (Combo) e.getSource(); + if (currentWidget == combo) + return; + String propertyName = (String) widgetToPropertyHash.get(combo); + setProperty(propertyName, combo.getText()); + } + + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.getSource(); + if (currentWidget == combo) + return; + String propertyName = (String) widgetToPropertyHash.get(combo); + if (combo.getSelectionIndex() >= 0) + setProperty(propertyName, combo.getItem(combo.getSelectionIndex())); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + } + + /** + * @deprecated + */ + private ComboListenerDeprecated comboListenerDeprecated; //TODO delete this + + private class ComboListener implements SelectionListener, ModifyListener { + public void modifyText(ModifyEvent e) { + if (ignoreModifyEvent) + return; + Combo combo = (Combo) e.getSource(); + if (currentWidget == combo) + return; + String propertyName = (String) widgetToPropertyHash.get(combo); + WTPPropertyDescriptor[] descriptors = dataModel.getValidPropertyDescriptors(propertyName); + String description = combo.getText(); + for (int i = 0; i < descriptors.length; i++) { + if (description.equals(descriptors[i].getPropertyDescription())) { + setProperty(propertyName, descriptors[i].getPropertyValue()); + return; + } + } + // setProperty(propertyName, combo.getText()); + } + + public void widgetSelected(SelectionEvent e) { + Combo combo = (Combo) e.getSource(); + if (currentWidget == combo) + return; + String propertyName = (String) widgetToPropertyHash.get(combo); + if (combo.getSelectionIndex() >= 0) { + WTPPropertyDescriptor[] descriptors = dataModel.getValidPropertyDescriptors(propertyName); + String description = combo.getItem(combo.getSelectionIndex()); + for (int i = 0; i < descriptors.length; i++) { + if (description.equals(descriptors[i].getPropertyDescription())) { + setProperty(propertyName, descriptors[i].getPropertyValue()); + return; + } + } + // setProperty(propertyName, combo.getItem(combo.getSelectionIndex())); + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + } + + private ComboListener comboListener; + + + private class CheckboxSelectionListener implements SelectionListener { + public void widgetSelected(SelectionEvent e) { + Button button = (Button) e.getSource(); + if (currentWidget == button) + return; + String propertyName = (String) widgetToPropertyHash.get(button); + setProperty(propertyName, new Boolean(button.getSelection())); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + } + + private CheckboxSelectionListener checkboxSelectionListener; + + public WTPDataModelSynchHelper(WTPOperationDataModel model) { + this.dataModel = model; + dataModel.addListener(this); + } + + + private CheckBoxViewerListener checkBoxViewerStateListener; + + private class CheckBoxViewerListener implements ICheckStateListener { + public void checkStateChanged(CheckStateChangedEvent event) { + StructuredViewer viewer = (StructuredViewer) event.getSource(); + CheckboxTableViewer checkBoxTableViewer; + CheckboxTreeViewer checkBoxTreeViewer; + Object[] items = null; + if (viewer instanceof CheckboxTableViewer) { + checkBoxTableViewer = (CheckboxTableViewer) viewer; + items = checkBoxTableViewer.getCheckedElements(); + } else if (viewer instanceof CheckboxTreeViewer) { + checkBoxTreeViewer = (CheckboxTreeViewer) viewer; + items = checkBoxTreeViewer.getCheckedElements(); + } + String propertyName = (String) widgetToPropertyHash.get(viewer.getControl()); + setPropertyItems(propertyName, items); + } + } + + public void propertyChanged(WTPOperationDataModelEvent event) { + String propertyName = event.getPropertyName(); + int flag = event.getFlag(); + if (currentProperty != null) { + String convertedProp = propertyName; + if (flag == WTPOperationDataModelListener.PROPERTY_CHG) + convertedProp = getConvertedProperty(propertyName); + if (currentProperty.equals(convertedProp)) + return; + } + if (flag == WTPOperationDataModelListener.ENABLE_CHG) + setEnablement(propertyName, ((Boolean) event.getNewValue()).booleanValue()); + else + synchUIWithModel(propertyName, flag); + } + + protected void setProperty(String propertyName, Object value) { + currentProperty = propertyName; + try { + dataModel.setProperty(propertyName, value); + } finally { + currentProperty = null; + } + } + + protected void setPropertyItems(String propertyName, Object[] items) { + currentProperty = propertyName; + try { + dataModel.setProperty(propertyName, items); + } finally { + currentProperty = null; + } + } + + /** + * Sets the UI to have the property value defined in the model + * + * @param propertyName + * @link WTPOperationDataModelListener for the flag values. + */ + public void synchUIWithModel(String propertyName, int flag) { + if (null != propertyToWidgetHash && propertyToWidgetHash.containsKey(propertyName)) { + try { + dataModel.setIgnorePropertyChanges(true); + currentWidget = (Widget) propertyToWidgetHash.get(propertyName); + if (currentWidget != null) { + ignoreModifyEvent = true; + try { + if (currentWidget instanceof Text) + setWidgetValue(propertyName, flag, (Text) currentWidget); + else if (currentWidget instanceof Combo){ + if(null != deprecatedCombos && deprecatedCombos.contains(currentWidget)){ + setWidgetValueDeprecated(propertyName, flag, (Combo) currentWidget); + } else { + setWidgetValue(propertyName, flag, (Combo) currentWidget); + } + }else if (currentWidget instanceof Button) + setWidgetValue(propertyName, flag, (Button) currentWidget); + else if (currentWidget instanceof Label) + setWidgetValue(propertyName, flag, (Label) currentWidget); + else if (currentWidget instanceof List) + setWidgetValue(propertyName, flag, (List) currentWidget); + else if (currentWidget instanceof Table) + setWidgetValue(propertyName, flag, (Table) currentWidget); + else if (currentWidget instanceof Tree) + setWidgetValue(propertyName, flag, (Tree) currentWidget); + } finally { + ignoreModifyEvent = false; + } + setEnablement(propertyName); + } + } finally { + currentWidget = null; + dataModel.setIgnorePropertyChanges(false); + } + } + } + + /** + * @param control + */ + private void setEnablement(String propertyName) { + if (currentWidget == null) + return; + Boolean enabled = dataModel.isEnabled(propertyName); + if (enabled != null) + setEnablement((Control) currentWidget, enabled.booleanValue()); + } + + /** + * @param control + * @param enabled + */ + private void setEnablement(Control control, boolean enabled) { + if (control.isEnabled() != enabled) + control.setEnabled(enabled); + setDependentControlEnablement(control, enabled); + } + + private void setEnablement(String propertyName, boolean enabled) { + if (propertyToWidgetHash != null) { + Control control = (Control) propertyToWidgetHash.get(propertyName); + if (control != null) { + setEnablement(control, enabled); + } + } + } + + /** + * @param control + * @param enabled + */ + private void setDependentControlEnablement(Control control, boolean enabled) { + if (widgetToDepControls != null) { + Control[] dependents = (Control[]) widgetToDepControls.get(control); + if (dependents != null) { + Control dep = null; + for (int i = 0; i < dependents.length; i++) { + dep = dependents[i]; + if (dep.isEnabled() != enabled) + dep.setEnabled(enabled); + } + } + } + } + + protected void setWidgetValue(String propertyName, int flag, Button button) { + if ((button.getStyle() & SWT.CHECK) == SWT.CHECK || (button.getStyle() & SWT.RADIO) == SWT.RADIO) { + boolean checked = dataModel.getBooleanProperty(propertyName); + if (button.getSelection() != checked) { + button.setSelection(checked); + } + } + } + + /** + * @deprecated + * @param propertyName + * @param flag + * @param combo + */ + private void setWidgetValueDeprecated(String propertyName, int flag, Combo combo) { + String prop = getConvertedProperty(propertyName); + if (flag == WTPOperationDataModelListener.VALID_VALUES_CHG || combo.getItemCount() == 0) { + // Display properties should only fire if the contents change. + String[] items = dataModel.getValidStringPropertyValues(prop); + combo.setItems(items); + } + String newText = dataModel.getStringProperty(prop); + int selIndex = combo.getSelectionIndex(); + if (selIndex < 0 || !newText.equals(combo.getItem(selIndex))) { + String[] items = combo.getItems(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals(newText)) { + combo.select(i); + return; + } + } + } + combo.setText(newText); + } + + protected void setWidgetValue(String propertyName, int flag, Combo combo) { + if (flag == WTPOperationDataModelListener.VALID_VALUES_CHG || combo.getItemCount() == 0) { + // Display properties should only fire if the contents change. + WTPPropertyDescriptor[] descriptors = dataModel.getValidPropertyDescriptors(propertyName); + String[] items = new String[descriptors.length]; + for (int i = 0; i < descriptors.length; i++) { + items[i] = descriptors[i].getPropertyDescription(); + } + combo.setItems(items); + } + String newText = dataModel.getPropertyDescriptor(propertyName).getPropertyDescription(); + int selIndex = combo.getSelectionIndex(); + if (selIndex < 0 || !newText.equals(combo.getItem(selIndex))) { + String[] items = combo.getItems(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals(newText)) { + combo.select(i); + return; + } + } + } + combo.setText(newText); + } + + /** + * @param propertyName + * @return + * @deprecated + */ + private String getConvertedProperty(String propertyName) { + if (deprecatedConvertPropertyNames != null) { + String prop = (String) deprecatedConvertPropertyNames.get(propertyName); + if (prop != null) + return prop; + } + return propertyName; + } + + protected void setWidgetValue(String propertyName, int flag, Text text) { + String newText = dataModel.getStringProperty(propertyName); + if (!newText.equals(text.getText())) { + text.setText(newText); + } + } + + protected void setWidgetValue(String propertyName, int flag, Table table) { + Object[] elements = (Object[]) dataModel.getProperty(propertyName); + if (elements == null || elements.length == 0) { + setTableItemsChecked(table.getItems(), false); + return; + } + java.util.List elementList = Arrays.asList(elements); + TableItem[] tableItems = table.getItems(); + for (int i = 0; i < tableItems.length; i++) { + TableItem item = tableItems[i]; + if (elementList.contains(item.getData())) + item.setChecked(true); + else + item.setChecked(false); + } + } + + protected void setTableItemsChecked(TableItem[] tableItems, boolean b) { + for (int i = 0; i < tableItems.length; i++) + tableItems[i].setChecked(b); + } + + protected void setWidgetValue(String propertyName, int flag, Tree tree) { + Object[] elements = (Object[]) dataModel.getProperty(propertyName); + if (elements == null) + return; + java.util.List elementList = Arrays.asList(elements); + TreeItem[] treeItems = tree.getItems(); + if (elementList.size() == 0) { + setTreeItemsGrey(treeItems, false); + return; + } + if (treeItems.length > 0) + setTreeItemChecked(treeItems, elementList); + } + + public void setTreeItemsGrey(TreeItem[] treeItems, boolean b) { + for (int i = 0; i < treeItems.length; i++) { + TreeItem item = treeItems[i]; + item.setGrayed(b); + setTreeItemsGrey(treeItems[i].getItems(), b); + } + } + + protected void setTreeItemChecked(TreeItem[] treeItems, java.util.List items) { + for (int i = 0; i < treeItems.length; i++) { + if (items.contains(treeItems[i].getData())) + treeItems[i].setChecked(true); + else + treeItems[i].setGrayed(true); + TreeItem[] childernItems = treeItems[i].getItems(); + if (childernItems.length > 0) { + treeItems[i].setExpanded(true); + setTreeItemChecked(childernItems, items); + } + } + } + + protected void setWidgetValue(String propertyName, int flag, Label label) { + String newText = dataModel.getStringProperty(propertyName); + if (!newText.equals(label.getText())) { + label.setText(newText); + } + } + + protected void setWidgetValue(String propertyName, int flag, List list) { + Object newContents = dataModel.getProperty(propertyName); + if (newContents == null) { + list.setItems(new String[0]); + return; + } + if (newContents instanceof java.util.List) { + java.util.List modelContents = (java.util.List) newContents; + String[] items = new String[modelContents.size()]; + for (int i = 0; i < modelContents.size(); i++) { + items[i] = modelContents.get(i).toString(); + } + list.setItems(items); + } else if (newContents instanceof String[]) { + list.setItems((String[]) newContents); + } + } + + public void synchAllUIWithModel() { + if (null != propertyToWidgetHash) { + Collection keys = propertyToWidgetHash.keySet(); + if (!keys.isEmpty()) { + Iterator propertyNames = keys.iterator(); + String propertyName = null; + while (propertyNames.hasNext()) { + propertyName = (String) propertyNames.next(); + synchUIWithModel(propertyName, WTPOperationDataModelListener.PROPERTY_CHG); + } + } + } + } + + protected void synchComposite(Widget widget, String propertyName, Control[] depControls) { + if (null == widgetToPropertyHash) + widgetToPropertyHash = new HashMap(); + if (propertyToWidgetHash == null) + propertyToWidgetHash = new HashMap(); + widgetToPropertyHash.put(widget, propertyName); + propertyToWidgetHash.put(propertyName, widget); + if (depControls != null) { + if (widgetToDepControls == null) + widgetToDepControls = new HashMap(); + widgetToDepControls.put(widget, depControls); + } + synchUIWithModel(propertyName, WTPOperationDataModelListener.PROPERTY_CHG); + } + + public void synchText(Text text, String propertyName, Control[] dependentControls) { + synchText(text, propertyName, false, dependentControls); + } + + public void synchText(Text text, String propertyName, boolean isTimeModified, Control[] dependentControls) { + synchComposite(text, propertyName, dependentControls); + if (isTimeModified) + text.addModifyListener(getTimedListener()); + else + text.addModifyListener(getModifyTextListener()); + } + + public void synchLabel(Label label, String propertyName, Control[] dependentControls) { + synchComposite(label, propertyName, dependentControls); + } + + /** + * Use this to synch the contents of the <code>list</code> to the List elements returned from + * the <code>propertyName</code>. + */ + public void synchList(List list, String propertyName, Control[] dependentControls) { + synchComposite(list, propertyName, dependentControls); + } + + /** + * @deprecated use syncCombo(Combo, String, Control[]) + * @param combo + * @param propertyName + * @param actualProperty + * @param dependentControls + */ + public void synchCombo(Combo combo, String propertyName, String actualProperty, Control[] dependentControls) { + if (actualProperty != null) { + if (propertyToWidgetHash == null) + propertyToWidgetHash = new Hashtable(); + propertyToWidgetHash.put(actualProperty, combo); + setConvertProperty(actualProperty, propertyName); + if (null == deprecatedCombos) { + deprecatedCombos = new HashSet(); + } + deprecatedCombos.add(combo); + } + synchComposite(combo, propertyName, dependentControls); + if (null == comboListenerDeprecated) { + comboListenerDeprecated = new ComboListenerDeprecated(); + } + combo.addSelectionListener(comboListenerDeprecated); + combo.addModifyListener(comboListenerDeprecated); + } + + public void synchCombo(Combo combo, String propertyName, Control[] dependentControls) { + synchComposite(combo, propertyName, dependentControls); + if (null == comboListener) { + comboListener = new ComboListener(); + } + combo.addSelectionListener(comboListener); + combo.addModifyListener(comboListener); + } + + + public void synchCheckbox(Button checkbox, String propertyName, Control[] dependentControls) { + synchComposite(checkbox, propertyName, dependentControls); + if (null == checkboxSelectionListener) { + checkboxSelectionListener = new CheckboxSelectionListener(); + } + checkbox.addSelectionListener(checkboxSelectionListener); + } + + public void synchCheckBoxTableViewer(CheckboxTableViewer tableViewer, String propertyName, Control[] dependentControls) { + synchComposite(tableViewer.getControl(), propertyName, dependentControls); + if (null == checkBoxViewerStateListener) { + checkBoxViewerStateListener = new CheckBoxViewerListener(); + } + tableViewer.addCheckStateListener(checkBoxViewerStateListener); + } + + public void synchCheckBoxTreeViewer(CheckboxTreeViewer treeViewer, String propertyName, Control[] dependentControls) { + treeViewer.expandAll(); + synchComposite(treeViewer.getControl(), propertyName, dependentControls); + if (null == checkBoxViewerStateListener) { + checkBoxViewerStateListener = new CheckBoxViewerListener(); + } + treeViewer.addCheckStateListener(checkBoxViewerStateListener); + } + + public void synchRadio(Button radio, String propertyName, Control[] dependentControls) { + // Uses checkbox syncher + synchCheckbox(radio, propertyName, dependentControls); + } + + /** + * This is necessary when a property is not actually persisted in the model but converted to + * another property. @param actualProperty @param convertProperty + * @deprecated + */ + private void setConvertProperty(String actualProperty, String convertProperty) { + if (deprecatedConvertPropertyNames == null) + deprecatedConvertPropertyNames = new HashMap(); + deprecatedConvertPropertyNames.put(actualProperty, convertProperty); + } + + private TimedModifyListener getTimedListener() { + if (timedModifyListener == null) + timedModifyListener = new TimedModifyListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Widget w = (Widget) e.getSource(); + if (currentWidget == w || w.isDisposed()) + return; + String propertyName = (String) widgetToPropertyHash.get(w); + setTextProperty(propertyName, (Text) w); + } + }) { + public void modifyText(ModifyEvent e) { + if (ignoreModifyEvent) + return; + super.modifyText(e); + } + }; + return timedModifyListener; + } + + protected void setTextProperty(String propertyName, Text text) { + setProperty(propertyName, text.getText()); + } + + private ModifyTextListener getModifyTextListener() { + if (null == modifyTextListener) + modifyTextListener = new ModifyTextListener(); + return modifyTextListener; + } + + public WTPOperationDataModel getDataModel() { + return dataModel; + } + + public void dispose() { + dataModel.removeListener(this); + checkboxSelectionListener = null; + deprecatedConvertPropertyNames = null; + deprecatedCombos = null; + currentWidget = null; + modifyTextListener = null; + propertyToWidgetHash = null; + timedModifyListener = null; + widgetToDepControls = null; + widgetToPropertyHash = null; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPGenericActionIds.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPGenericActionIds.java new file mode 100644 index 000000000..3a27e126d --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPGenericActionIds.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Jun 16, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Style - Code Templates + */ +public interface WTPGenericActionIds { + + String CUT = "com.ibm.wtp.generic.Cut"; //$NON-NLS-1$ + String COPY = "com.ibm.wtp.generic.Copy"; //$NON-NLS-1$ + String PASTE = "com.ibm.wtp.generic.Paste"; //$NON-NLS-1$ + String RENAME = "com.ibm.wtp.generic.Rename"; //$NON-NLS-1$ + String DELETE = "com.ibm.wtp.generic.Delete"; //$NON-NLS-1$ +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPOperationAction.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPOperationAction.java new file mode 100644 index 000000000..ed0f12e2e --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPOperationAction.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Apr 29, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.PlatformUI; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.MasterDescriptor; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.UIOperationExtensionRegistry; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.WTPOptionalOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.operations.ComposedOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; + +import com.ibm.wtp.common.logger.proxy.Logger; + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class WTPOperationAction extends Action implements IActionDelegate, IViewActionDelegate { + + private IStructuredSelection selection; + + private IViewPart viewPart; + + private IWorkbenchSite workbenchSite; + + public WTPOperationAction() { + } + + public WTPOperationAction(String id, String name) { + super(name); + init(id, null); + } + + public WTPOperationAction(String id, String name, ImageDescriptor imgDescriptor) { + super(name, imgDescriptor); + init(id, null); + } + + public WTPOperationAction(String id, String name, IWorkbenchSite site) { + super(name); + init(id, site); + } + + public WTPOperationAction(String id, String name, ImageDescriptor imgDescriptor, IWorkbenchSite site) { + super(name, imgDescriptor); + init(id, site); + } + + /** + * @param id + * @param site + */ + private void init(String id, IWorkbenchSite site) { + this.setId(id); + this.setWorkbenchSite(site); + } + + /** + * @param selection + * @return + */ + protected boolean updateSelection(IAction action, IStructuredSelection selection1) { + this.selection = selection1; + MasterDescriptor[] masters = UIOperationExtensionRegistry.INSTANCE.getExtendedUIOperations(action.getId(), selection); + action.setEnabled(masters.length > 0); + return masters.length > 0; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + run(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public final void run(IAction action) { + + if (action == null) + return; + + WTPOptionalOperationDataModel operationDataModel = WTPOptionalOperationDataModel.createDataModel(action.getId(), this.selection); + operationDataModel.setProperty(WTPOptionalOperationDataModel.IWORKBENCH_SITE, getWorkbenchSite()); + + executeCompoundOperation(operationDataModel); + } + + /** + * @return + */ + public IWorkbenchSite getWorkbenchSite() { + if (workbenchSite != null) + return workbenchSite; + if (viewPart != null) + return viewPart.getSite(); + return null; + } + + /** + * @param shell + * @param operationDataModel + * @param exec + */ + protected void executeCompoundOperation(WTPOptionalOperationDataModel operationDataModel) { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + try { + WTPOperation operation = operationDataModel.getDefaultOperation(); + operationDataModel.setOperationValidationEnabled(true); + final List runnables = ((ComposedOperation) operation).getRunnables(); + /* + * PlatformUI.getWorkbench().getProgressService().run(true, false, new + * IRunnableWithProgress() { + * + * + * (non-Javadoc) + * + * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) + * + * public void run(IProgressMonitor monitor) throws InvocationTargetException, + * InterruptedException { + */ + /* monitor.beginTask("Executing compound operation", runnables.size()); */ + SubProgressMonitor submonitor = null; + for (int i = 0; i < runnables.size(); i++) { + final WTPOperation op = (WTPOperation) runnables.get(i); + if (op != null) { + /* submonitor = new SubProgressMonitor(monitor, 3); */ + op.run(submonitor); + } + /* monitor.worked(1); */ + } + /* monitor.done(); */ + /* + * } }); + */ + /* operation.run(new NullProgressMonitor()); */ + status = operation.getStatus(); + if (!status.isOK()) { + ErrorDialog.openError(shell, WTPCommonUIResourceHandler.getString("WTPOperationAction_UI_0"), WTPCommonUIResourceHandler.getString("WTPOperationAction_UI_1"), status); //$NON-NLS-1$ //$NON-NLS-2$ + } + + } catch (Exception e) { + Logger.getLogger().logError(e); + status = new Status(IStatus.ERROR, WTPUIPlugin.PLUGIN_ID, 0, e.toString(), e); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, + * org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection1) { + if (selection1 instanceof IStructuredSelection) + setEnabled(updateSelection(action, (IStructuredSelection) selection1)); + else { + action.setEnabled(false); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init(IViewPart view) { + this.viewPart = view; + } + + /** + * @param workbenchSite + * The workbenchSite to set. + */ + public void setWorkbenchSite(IWorkbenchSite workbenchSite) { + this.workbenchSite = workbenchSite; + } + + protected IStatus status; + + /** + * @return Returns the status. + */ + public IStatus getStatus() { + return status; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPOptionalOperationAction.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPOptionalOperationAction.java new file mode 100644 index 000000000..a2d36d360 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPOptionalOperationAction.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Apr 29, 2004 + * + * TODO To change the template for this generated file go to Window - + * Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.PlatformUI; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.IOperationNode; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.WTPActionDialog; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.WTPOptionalOperationDataModel; + + +/** + * @author mdelder + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - + * Code Generation - Code and Comments + */ +public class WTPOptionalOperationAction extends WTPOperationAction { + + public WTPOptionalOperationAction() { + } + + + public WTPOptionalOperationAction(String id, String name) { + super(id, name); + } + + public WTPOptionalOperationAction(String id, String name, ImageDescriptor imgDescriptor) { + super(id, name, imgDescriptor); + } + + + public WTPOptionalOperationAction(String id, String name, IWorkbenchSite site) { + super(id, name, site); + } + + public WTPOptionalOperationAction(String id, String name, ImageDescriptor imgDescriptor, IWorkbenchSite site) { + super(id, name, imgDescriptor, site); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.common.frameworks.internal.ui.WTPOperationAction#executeCompoundOperation(org.eclipse.wst.common.frameworks.internal.operation.extension.ui.WTPOptionalOperationDataModel) + */ + protected void executeCompoundOperation(WTPOptionalOperationDataModel operationDataModel) { + if (operationDataModel != null) { + IOperationNode root = (IOperationNode) operationDataModel.getProperty(WTPOptionalOperationDataModel.OPERATION_TREE); + if (WTPOptionalOperationDataModel.getOptionalChildren(root).length > 0) { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + WTPActionDialog optionalDialog = new WTPActionDialog(shell, operationDataModel); + optionalDialog.setId(getId()); + if (optionalDialog.open() == Window.OK) + super.executeCompoundOperation(operationDataModel); + else + status = Status.CANCEL_STATUS; + } else + super.executeCompoundOperation(operationDataModel); + } + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPUIPlugin.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPUIPlugin.java new file mode 100644 index 000000000..c831bb7c3 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPUIPlugin.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.wst.common.frameworks.internal.operations.IHeadlessRunnableWithProgress; + +import com.ibm.wtp.common.logger.proxy.Logger; + +/** + * The main plugin class to be used in the desktop. + */ +public class WTPUIPlugin extends AbstractUIPlugin { + + public static final String PLUGIN_ID = "org.eclipse.wst.common.frameworks.internal.ui"; //$NON-NLS-1$ + public static final String EXTENDED_VIEWER_REGISTRY_EXTENSION_POINT = "extendedViewer"; //$NON-NLS-1$ + //The shared instance. + private static WTPUIPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + /** + * The constructor. + */ + public WTPUIPlugin(IPluginDescriptor descriptor) { + super(descriptor); + plugin = this; + try { + resourceBundle = ResourceBundle.getBundle("org.eclipse.wst.common.frameworks.internal.ui.WTPUIPluginResources"); //$NON-NLS-1$ + } catch (MissingResourceException x) { + resourceBundle = null; + } + } + + /** + * @param string + * @return + */ + public static IStatus createErrorStatus(String message) { + return createErrorStatus(message, null); + } + + /** + * @param string + * @return + */ + public static IStatus createErrorStatus(String message, Throwable exception) { + return new Status(IStatus.ERROR, PLUGIN_ID, -1, message, exception); + } + + /** + * Returns the shared instance. + */ + public static WTPUIPlugin getDefault() { + return plugin; + } + + public static Logger getLogger() { + return Logger.getLogger(PLUGIN_ID); + } + + /** + * Returns the workspace instance. + */ + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + /** + * Return the workbench + * + * This method is internal to the j2ee plugin and must not be called by any other plugins. + */ + + public static IWorkbench getPluginWorkbench() { + return getDefault().getWorkbench(); + + } + + public static IRunnableWithProgress getRunnableWithProgress(IHeadlessRunnableWithProgress aHeadlessRunnableWithProgress) { + return new RunnableWithProgressWrapper(aHeadlessRunnableWithProgress); + } + + /** + * Returns the string from the plugin's resource bundle, or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = WTPUIPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null ? bundle.getString(key) : key); + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizard.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizard.java new file mode 100644 index 000000000..a22012e17 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizard.java @@ -0,0 +1,214 @@ +/*************************************************************************************************** + * Copyright (c) 2003, 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 + **************************************************************************************************/ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.wst.common.frameworks.internal.operation.extensionui.IExtendedWizardPage; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclispe.wst.common.frameworks.internal.enablement.EnablementManager; + +import com.ibm.wtp.common.logger.proxy.Logger; + + +public abstract class WTPWizard extends Wizard { + protected WTPOperationDataModel model; + + public WTPWizard(WTPOperationDataModel model) { + this.model = model; + } + + public WTPWizard() { + this.model = createDefaultModel(); + } + + /** + * Return a new default WTPOperationDataModel. + * + * @return + */ + protected abstract WTPOperationDataModel createDefaultModel(); + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#canFinish() + */ + public boolean canFinish() { + if (super.canFinish()) + return model.isValid(); + return false; + } + + protected void resetAfterFinishError() { + IWizardPage[] pages = getPages(); + for (int i = 0; i < pages.length; i++) { + WTPWizardPage wtpPage = (WTPWizardPage) pages[i]; + wtpPage.validatePage(true); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.IWizard#performFinish() + */ + public final boolean performFinish() { + WTPOperation op = null; + boolean wasSuccessful = false; + try { + model.setProperty(WTPOperationDataModel.UI_OPERATION_HANLDER, new UIOperationHandler(getShell())); + if (prePerformFinish()) { + storeDefaultSettings(); + op = createOperation(); + if (!model.getBooleanProperty(WTPOperationDataModel.RUN_OPERATION)) { + model.setProperty(WTPOperationDataModel.CACHED_DELAYED_OPERATION, op); + wasSuccessful = isSuccessfulFinish(op); + return wasSuccessful; + } + if (op != null) { + IRunnableWithProgress runnable = WTPUIPlugin.getRunnableWithProgress(op); + try { + getContainer().run(runForked(), isCancelable(), runnable); + postPerformFinish(); + } catch (InvocationTargetException e) { + Logger.getLogger().logError(e); + ErrorDialog.openError(getShell(), WTPCommonUIResourceHandler.getString("WTPWizard_UI_0", new Object[]{getWindowTitle()}), WTPCommonUIResourceHandler.getString("WTPWizard_UI_1", new Object[]{getWindowTitle()}), e, 0, false); //$NON-NLS-1$ //$NON-NLS-2$ + wasSuccessful = false; + return wasSuccessful; + } catch (InterruptedException e) { + Logger.getLogger().logError(e); + wasSuccessful = false; + return wasSuccessful; + } + } + } + wasSuccessful = isSuccessfulFinish(op); + return wasSuccessful; + } finally { + if (!wasSuccessful) { + resetAfterFinishError(); + } + } + } + + /** + * @param op + * @return + */ + protected boolean isSuccessfulFinish(WTPOperation op) { + return op != null; + } + + /** + * Subclass can override to perform any tasks prior to running the operation. Return true to + * have the operation run and false to stop the execution of the operation. + * + * @return + */ + protected boolean prePerformFinish() { + return true; + } + + /** + * Subclasses should override to perform any actions necessary after performing Finish. + */ + protected void postPerformFinish() throws InvocationTargetException { + } + + protected void storeDefaultSettings() { + IWizardPage[] pages = getPages(); + for (int i = 0; i < pages.length; i++) + storeDefaultSettings(pages[i], i); + } + + /** + * Subclasses may override if they need to do something special when storing the default + * settings for a particular page. + * + * @param page + * @param pageIndex + */ + protected void storeDefaultSettings(IWizardPage page, int pageIndex) { + if (page instanceof WTPWizardPage) + ((WTPWizardPage) page).storeDefaultSettings(); + } + + /** + * Subclasses should override if the running operation is allowed to be cancelled. The default + * is false. + * + * @return + */ + protected boolean isCancelable() { + return false; + } + + /** + * Subclasses should override to return false if the running operation cannot be run forked. + * + * @return + */ + protected boolean runForked() { + return false; + } + + /** + * Return the operation that will perform the task suported by this wizard. + * + * @return IHeadlessRunnableWithProgress + */ + protected abstract WTPOperation createOperation(); + + /** + * @return Returns the model. + */ + public WTPOperationDataModel getModel() { + return model; + } + + public void dispose() { + super.dispose(); + if (null != model) { + model.dispose(); + } + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage) + */ + public IWizardPage getNextPage(IWizardPage page) { + IWizardPage nextPage = super.getNextPage(page); + + if (nextPage instanceof IExtendedWizardPage) { + IExtendedWizardPage extendedWizardPage = (IExtendedWizardPage) nextPage; + if (!EnablementManager.INSTANCE.getIdentifier(extendedWizardPage.getGroupID(), getModel().getTargetProject()).isEnabled()) + return getNextPage(nextPage); + } + return nextPage; + } + + public void addPage(IWizardPage page) { + if (model.isProperty(WTPWizardSkipPageDataModel.SKIP_PAGES) && null != page.getName()) { + List pagesToSkip = (List) model.getProperty(WTPWizardSkipPageDataModel.SKIP_PAGES); + if (null != pagesToSkip && pagesToSkip.contains(page.getName())) { + return; + } + } + super.addPage(page); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardPage.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardPage.java new file mode 100644 index 000000000..b1a4baa4d --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardPage.java @@ -0,0 +1,435 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. US + * Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP + * Schedule Contract with IBM Corp. + */ +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelEvent; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelListener; + + +public abstract class WTPWizardPage extends WizardPage implements Listener, WTPOperationDataModelListener { + protected static final int NEXT = 1; + protected static final int PREVIOUS = 2; + protected static final int COMPOSITE_BORDER = SWT.NULL; + private ValidationStatus status = new ValidationStatus(); + private boolean isValidating = false; + protected boolean isFirstTimeToPage = true; + protected WTPOperationDataModel model; + private Map validationMap; + private String[] validationPropertyNames; + protected WTPDataModelSynchHelper synchHelper; + private String infopopID; + + /** + * J2EEWizardPage constructor comment. + * + * @param pageName + * java.lang.String + */ + protected WTPWizardPage(WTPOperationDataModel model, String pageName) { + super(pageName); + this.model = model; + model.addListener(this); + synchHelper = initializeSynchHelper(model); + } + + /** + * @return + */ + public WTPDataModelSynchHelper initializeSynchHelper(WTPOperationDataModel dm) { + return new WTPDataModelSynchHelper(dm); + } + + /** + * J2EEWizardPage constructor comment. + * + * @param pageName + * java.lang.String + * @param title + * java.lang.String + * @param titleImage + * org.eclipse.jface.resource.ImageDescriptor + */ + protected WTPWizardPage(WTPOperationDataModel model, String pageName, String title, org.eclipse.jface.resource.ImageDescriptor titleImage) { + super(pageName, title, titleImage); + this.model = model; + model.addListener(this); + synchHelper = initializeSynchHelper(model); + } + + protected IPath convertPackageNameToPath(String qualifiedName) { + String name = qualifiedName.replace('.', '/'); + return new Path(name); + } + + /** + * Creates the top level control for this dialog page under the given parent composite. This + * method has been abstract and it uses the template pattern to get the correct items setup in + * the correct order. See the set of methods below that are called in this method. + * <p> + * Implementors are responsible for ensuring that the created control can be accessed via + * <code>getControl</code> + * </p> + * + * @param parent + * the parent composite + */ + public final void createControl(org.eclipse.swt.widgets.Composite parent) { + Composite top = createTopLevelComposite(parent); + setControl(top); + setupInfopop(top); + setDefaults(); + addListeners(); + initializeValidationProperties(); + } + + private void initializeValidationProperties() { + validationPropertyNames = getValidationPropertyNames(); + if (validationPropertyNames == null || validationPropertyNames.length == 0) + validationMap = Collections.EMPTY_MAP; + else { + validationMap = new HashMap(validationPropertyNames.length); + for (int i = 0; i < validationPropertyNames.length; i++) + validationMap.put(validationPropertyNames[i], new Integer(i)); + } + } + + /** + * Subclass should return the model property names that need to be validated on this page in the + * order that they should present their messages. + * + * @return + */ + protected abstract String[] getValidationPropertyNames(); + + /** + * Return true of the property validation status is OK. + * + * @param propertyKey + * @return + */ + protected boolean getPropertyOKStatus(String propertyKey) { + Integer validationKey = getValidationKey(propertyKey); + if (validationKey != null) + return getStatus(validationKey); + return true; + } + + /** + * @param propertyKey + * @return + */ + private Integer getValidationKey(String propertyKey) { + return (Integer) validationMap.get(propertyKey); + } + + /** + * Return the top level Composite for this page. + */ + protected abstract Composite createTopLevelComposite(Composite parent); + + /** + * Set up info pop hooks if set. + */ + protected void setupInfopop(Control parent) { + if (getInfopopID() != null) + WorkbenchHelp.setHelp(parent, getInfopopID()); + } + + /** + * Setup the default values for this page. Subclasses should override to provide appropriate + * defaults. + */ + protected void setDefaults() { + restoreDefaultSettings(); + } + + /** + * Subclasses should implement this method if they have default settings that have been stored + * and need to be restored. + * + * @see storeDefaultSettings() + */ + protected void restoreDefaultSettings() { + } + + /** + * Add Listeners to controls at this point to avoid unnecessary events. Subclasses should + * override to add listeners to its controls. + */ + protected void addListeners() { + } + + /** + * The page is being made current and visible. Subclasses may extend. + */ + protected void enter() { + try { + validatePage(showValidationErrorsOnEnter()); + } finally { + isFirstTimeToPage = false; + } + } + + /** + * The default behavior is to return true unless it is the first time entering this page in + * which case we check to see if there is a previous page and return true if there is not. + * Subclasses should override if they do not want this default behavior. + */ + protected boolean showValidationErrorsOnEnter() { + return !isFirstTimeToPage(); + } + + /** + * The default behavior is to return true unless it is the first time entering this page in + * which case we check to see if there is a previous page and return true if there is not. + * Subclasses should override if they do not want this default behavior. + * + * @deprecated - use showValidatoinErrorsOnEnter instead + */ + protected boolean shouldValidateOnEnter() { + return showValidationErrorsOnEnter(); + } + + /** + * Exiting the page. Subclasses may extend. + */ + protected void exit() { + } + + protected boolean getStatus(Integer key) { + return status.hasError(key); + } + + /** + * Sent when an event that the receiver has registered for occurs. If a subclass overrides this + * method, it must call super. + * + * @param event + * the event which occurred + */ + public void handleEvent(org.eclipse.swt.widgets.Event event) { + //validatePage(); + } + + /** + * Set the error message for this page based on the last error in the ValidationStatus. + */ + protected void setErrorMessage() { + String error = status.getLastErrMsg(); + if (error == null) { + if (getErrorMessage() != null) + setErrorMessage((String) null); + String warning = status.getLastWarningMsg(); + if (warning == null) { + if (getMessage() != null && getMessageType() == IMessageProvider.WARNING) + setMessage(null, IMessageProvider.WARNING); + } else if (!warning.equals(getMessage())) + setMessage(warning, IMessageProvider.WARNING); + } else if (!error.equals(getErrorMessage())) + setErrorMessage(error); + } + + protected void setErrorStatus(Integer key, String errorMessage) { + status.setErrorStatus(key, errorMessage); + } + + protected void setWarningStatus(Integer key, String warningMessage) { + status.setWarningStatus(key, warningMessage); + } + + protected void setOKStatus(Integer key) { + status.setOKStatus(key); + } + + /** + * The <code>DialogPage</code> implementation of this <code>IDialogPage</code> method sets + * the control to the given visibility state. Subclasses may extend. + */ + + public void setVisible(boolean visible) { + super.setVisible(visible); + if (visible) + enter(); + else + exit(); + } + + /** + * This should be called by the Wizard just prior to running the performFinish operation. + * Subclasses should override to store their default settings. + */ + public void storeDefaultSettings() { + } + + /** + * The page is now being validated. At this time, each control is validated and then the + * controls are updated based on the results in the ValidationStatus which was updated during + * <code>validateControls()</code>. Finally, it will display the last error message and it + * will set the page complete. Subclasses will not typically override this method. + */ + protected void validatePage() { + validatePage(true); + } + + protected void validatePage(boolean showMessage) { + if (!isValidating) { + isValidating = true; + try { + validateControlsBase(); + updateControls(); + if (showMessage) + setErrorMessage(); + setPageComplete(status.getLastErrMsg() == null); + } finally { + isValidating = false; + } + } + } + + /** + * Validate individual controls. Use validation keys to keep track of errors. + * + * @see setOKStatus(Integer) and setErrorMessage(Integer, String) + */ + protected final String validateControlsBase() { + if (!validationMap.isEmpty()) { + String propName; + for (int i = 0; i < validationPropertyNames.length; i++) { + propName = validationPropertyNames[i]; + Integer valKey = (Integer) validationMap.get(propName); + if (valKey != null) + validateProperty(propName, valKey); + if (!getStatus(valKey)) + return propName; + } + } + return null; + } + + /** + * @param propertyName + * @param validationkey + */ + private void validateProperty(String propertyName, Integer validationKey) { + setOKStatus(validationKey); + IStatus status1 = model.validateProperty(propertyName); + if (!status1.isOK()) { + String message = status1.isMultiStatus() ? status1.getChildren()[0].getMessage() : status1.getMessage(); + switch (status1.getSeverity()) { + case IStatus.ERROR : + setErrorStatus(validationKey, message); + break; + case IStatus.WARNING : + setWarningStatus(validationKey, message); + break; + } + } + } + + /** + * Update the enablement of controls after validation. Sublcasses should check the status of + * validation keys to determine enablement. + */ + protected void updateControls() { + } + + /** + * Gets the isFirstTimeToPage. + * + * @return Returns a boolean + */ + protected boolean isFirstTimeToPage() { + return isFirstTimeToPage; + } + + protected void setJavaStatusMessage(IStatus javaStatus, Integer statusKey, String message) { + if (javaStatus.getSeverity() == IStatus.WARNING) + setWarningStatus(statusKey, message); + else + setErrorStatus(statusKey, message); + } + + /** + * @param b + */ + public void setFirstTimeToPage(boolean b) { + isFirstTimeToPage = b; + } + + /* + * If a property changes that we want to validate, force validation on this page. + * + * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModelListener#propertyChanged(java.lang.String, + * java.lang.Object, java.lang.Object) + */ + public void propertyChanged(WTPOperationDataModelEvent event) { + String propertyName = event.getPropertyName(); + if (validationPropertyNames != null && (event.getFlag() == PROPERTY_CHG || (!isPageComplete() && event.getFlag() == VALID_VALUES_CHG))) { + for (int i = 0; i < validationPropertyNames.length; i++) { + if (validationPropertyNames[i].equals(propertyName)) { + validatePage(); + break; + } + } + } + } + + protected void addSpacers(Composite comp, int spacers) { + for (int i = 0; i < spacers; i++) + new Label(comp, SWT.NONE); + } + + /** + * @return Returns the model. + */ + protected WTPOperationDataModel getModel() { + return model; + } + + /** + * @return Returns the synchHelper. + */ + protected WTPDataModelSynchHelper getSynchHelper() { + return synchHelper; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#dispose() + */ + public void dispose() { + super.dispose(); + if (synchHelper != null) { + synchHelper.dispose(); + synchHelper = null; + } + } + + protected String getInfopopID() { + return infopopID; + } + + public void setInfopopID(String infopopID) { + this.infopopID = infopopID; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardSelectionPage.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardSelectionPage.java new file mode 100644 index 000000000..4382c0eff --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardSelectionPage.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on Jan 27, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.IWizardNode; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + +/** + * @author DABERG + * + * To change the template for this generated type comment go to Window>Preferences>Java>Code + * Generation>Code and Comments + */ +public abstract class WTPWizardSelectionPage extends WTPWizardPage { + /** + * @param model + * @param pageName + */ + public WTPWizardSelectionPage(WTPOperationDataModel model, String pageName) { + super(model, pageName); + } + + /** + * @param model + * @param pageName + * @param title + * @param titleImage + */ + public WTPWizardSelectionPage(WTPOperationDataModel model, String pageName, String title, ImageDescriptor titleImage) { + super(model, pageName, title, titleImage); + } + + /** + * The selected node; <code>null</code> if none. + */ + private IWizardNode selectedNode = null; + + /** + * List of wizard nodes that have cropped up in the past (element type: <code>IWizardNode</code>). + */ + private List selectedWizardNodes = new ArrayList(); + + /** + * Adds the given wizard node to the list of selected nodes if it is not already in the list. + * + * @param node + * the wizard node, or <code>null</code> + */ + private void addSelectedNode(IWizardNode node) { + if (node == null) + return; + + if (selectedWizardNodes.contains(node)) + return; + + selectedWizardNodes.add(node); + } + + /** + * The <code>WizardSelectionPage</code> implementation of this <code>IWizardPage</code> + * method returns <code>true</code> if there is a selected node. + */ + public boolean canFlipToNextPage() { + return isPageComplete() && selectedNode != null; + } + + /** + * The <code>WizardSelectionPage</code> implementation of an <code>IDialogPage</code> method + * disposes of all nested wizards. Subclasses may extend. + */ + public void dispose() { + super.dispose(); + // notify nested wizards + for (int i = 0; i < selectedWizardNodes.size(); i++) { + ((IWizardNode) selectedWizardNodes.get(i)).dispose(); + } + } + + /** + * The <code>WizardSelectionPage</code> implementation of this <code>IWizardPage</code> + * method returns the first page of the currently selected wizard if there is one. + */ + public IWizardPage getNextPage() { + if (selectedNode == null) + return null; + + boolean isCreated = selectedNode.isContentCreated(); + + IWizard wizard = selectedNode.getWizard(); + + if (wizard == null) { + setSelectedNode(null); + return null; + } + + if (!isCreated) + // Allow the wizard to create its pages + wizard.addPages(); + + return wizard.getStartingPage(); + } + + /** + * Returns the currently selected wizard node within this page. + * + * @return the wizard node, or <code>null</code> if no node is selected + */ + public IWizardNode getSelectedNode() { + return selectedNode; + } + + /** + * Sets or clears the currently selected wizard node within this page. + * + * @param node + * the wizard node, or <code>null</code> to clear + */ + protected void setSelectedNode(IWizardNode node) { + addSelectedNode(node); + selectedNode = node; + if (isCurrentPage()) + getContainer().updateButtons(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardSkipPageDataModel.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardSkipPageDataModel.java new file mode 100644 index 000000000..22532f422 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WTPWizardSkipPageDataModel.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2003, 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 + *******************************************************************************/ +/* + * Created on May 25, 2004 + * + */ +package org.eclipse.wst.common.frameworks.internal.ui; + +import java.util.Collections; + +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; +import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel; + + +/** + * @author jsholl + * + */ +public class WTPWizardSkipPageDataModel extends WTPOperationDataModel { + + /** + * A List of Strings identifying the page id's to skip + */ + public static final String SKIP_PAGES = "WTPWizardSkipPageDataModel.SKIP_PAGES"; //$NON-NLS-1$ + + public WTPOperation getDefaultOperation() { + return null; + } + + protected void initValidBaseProperties() { + super.initValidBaseProperties(); + addValidBaseProperty(SKIP_PAGES); + } + + protected Object getDefaultProperty(String propertyName) { + if (propertyName.equals(SKIP_PAGES)) { + return Collections.EMPTY_LIST; + } + return super.getDefaultProperty(propertyName); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WorkspaceModifyComposedOperation.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WorkspaceModifyComposedOperation.java new file mode 100644 index 000000000..82aea76b3 --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/WorkspaceModifyComposedOperation.java @@ -0,0 +1,78 @@ +package org.eclipse.wst.common.frameworks.internal.ui; + +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2001, 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + */ + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.jface.operation.IRunnableWithProgress; + +/** + * An operation which delegates its work to a runnable that modifies the workspace. + * <p> + * This class may be instantiated; it is not intended to be subclassed. + * </p> + */ +public class WorkspaceModifyComposedOperation extends org.eclipse.ui.actions.WorkspaceModifyOperation { + protected List fRunnables; + + public WorkspaceModifyComposedOperation(ISchedulingRule rule) { + super(rule); + } + + /** + * Creates a new operation which will delegate its work to the given runnable. + */ + public WorkspaceModifyComposedOperation() { + super(); + } + + public WorkspaceModifyComposedOperation(ISchedulingRule rule, List nestedRunnablesWithProgress) { + super(rule); + fRunnables = nestedRunnablesWithProgress; + } + + public WorkspaceModifyComposedOperation(List nestedRunnablesWithProgress) { + super(); + fRunnables = nestedRunnablesWithProgress; + } + + /** + * Creates a new operation which will delegate its work to the given runnable. + * + * @param content + * the runnable to delegate to when this operation is executed + */ + public WorkspaceModifyComposedOperation(IRunnableWithProgress nestedOp) { + super(); + getRunnables().add(nestedOp); + } + + public boolean addRunnable(IRunnableWithProgress nestedOp) { + return getRunnables().add(nestedOp); + } + + protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + int size = fRunnables.size(); + monitor.beginTask("", size);//$NON-NLS-1$ + for (int i = 0; i < fRunnables.size(); i++) { + IRunnableWithProgress op = (IRunnableWithProgress) fRunnables.get(i); + op.run(new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + } + } + + protected List getRunnables() { + if (fRunnables == null) + fRunnables = new ArrayList(3); + return fRunnables; + } +}
\ No newline at end of file |