fixed compile errors due to reliance on internal classes, and removed unused classes
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/OverlayIconManager.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/OverlayIconManager.java
deleted file mode 100644
index 24f6616..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/OverlayIconManager.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal;
-
-import org.eclipse.core.resources.*;
-//import org.eclipse.jface.resource.*;
-import org.eclipse.jface.viewers.*;
-//import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.Display;
-import java.util.*;
-
-/**
- * This class used to track the icon overlays that should be used to decorate the icons in a view.
- * Clients should implement the method 'locateObjectForOffset()' that will be used to associate a model object with each marker.
- * When markers are changed, a table of objects -> markers is maintained. When the time comes to display the object in a view
- * the client can call 'getOverlayImageForObject()' to determine the annotation image that should be used when displaying the object.
- */
-public abstract class OverlayIconManager
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- protected IResource resource;
- protected IWorkspace workspace;
- protected Hashtable hashtable = new Hashtable();
- protected ResourceChangeListener resourceChangeListener = new ResourceChangeListener();
- protected List viewerList = new Vector();
-
- // todo... get images for these other kinds of markers
- //
- protected static final Image taskOverlayImage = null; //B2BGUIPlugin.getInstance().getImage("icons/error-overlay.gif");
- protected static final Image bookmarkOverlayImage = null; //B2BGUIPlugin.getInstance().getImage("icons/error-overlay.gif");
- protected static final Image problemInfoOverlayImage = null; //B2BGUIPlugin.getInstance().getImage("icons/error-overlay.gif");
-// TODO protected static final Image problemWarningOverlayImage = B2BGUIPlugin.getInstance().getImage("icons/warning-overlay.gif");
- protected static final Image problemWarningOverlayImage = null;
-// TODO protected static final Image problemErrorOverlayImage = B2BGUIPlugin.getInstance().getImage("icons/error-overlay.gif");
- protected static final Image problemErrorOverlayImage = null;
-
- /**
- * Internal resource change listener.
- */
- class ResourceChangeListener implements IResourceChangeListener
- {
- protected boolean needsUpdate;
-
- public void resourceChanged(IResourceChangeEvent e)
- {
- //if (e.getResource() == resource)
- {
- if (!needsUpdate)
- {
- needsUpdate = true;
- Runnable delayedUpdate = new Runnable()
- {
- public void run()
- {
- doUpdate();
- }
- };
-
- // It seems like this current dislay is actually coming back null sometimes.
- // Without this test we get an occasional NPE logged (defect 187099).
- if (Display.getCurrent() != null)
- {
- Display.getCurrent().asyncExec(delayedUpdate);
- }
- }
- }
- }
-
- public void doUpdate()
- {
- needsUpdate = false;
- update();
- }
- };
-
-
- public OverlayIconManager()
- {
- }
-
-
- public void setResource(IResource newResource)
- {
- this.resource = newResource;
- setWorkspace(newResource != null ? newResource.getWorkspace() : null);
- }
-
-
- // I'm not sure why there can be more than 1 workspace.... do I misunderstand something?
- protected void setWorkspace(IWorkspace newWorkspace)
- {
- if (workspace != null && workspace != newWorkspace)
- {
- workspace.removeResourceChangeListener(resourceChangeListener);
- }
- if (newWorkspace != null)
- {
- newWorkspace.addResourceChangeListener(resourceChangeListener);
- }
- workspace = newWorkspace;
- }
-
-
- //
- public IResource getResource()
- {
- return resource;
- }
-
- public void addViewer(Viewer viewer)
- {
- viewerList.add(viewer);
- }
-
- public void removeViewer(Viewer viewer)
- {
- viewerList.remove(viewer);
- }
-
- protected void updateListeners()
- {
- for (Iterator i = viewerList.iterator(); i.hasNext(); )
- {
- Viewer viewer = (Viewer)i.next();
-
- // Make sure the viewer is not disposed before calling refresh on it
- if ( viewer.getControl() != null &&
- !viewer.getControl().isDisposed() )
- {
- viewer.refresh();
- }
- }
- }
-
- public void update()
- {
- // if resource is null, do nothing
- if (resource == null)
- return;
-
- try
- {
- hashtable = new Hashtable();
- IMarker[] markers = resource.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
- for (int i = 0 ; i < markers.length; i++)
- {
- IMarker marker = markers[i];
- Object object = locateObjectForMarker(marker);
- Object key = object != null ? getKeyForObject(object) : null;
- if (key != null)
- {
- hashtable.put(key, marker);
- }
- }
- }
- catch (Exception e)
- {
-// TODO B2BGUIPlugin.getPlugin().getMsgLogger().writeCurrentThread();
- }
- updateListeners();
- }
-
-
- protected abstract Object locateObjectForOffset(int offset);
-
- protected Object locateObjectForMarker(IMarker marker)
- {
- Object result = null;
- int offset = marker.getAttribute(IMarker.CHAR_START, -1);
- if (offset != -1)
- {
- result = locateObjectForOffset(offset);
- }
- return result;
- }
-
-
- protected Object getKeyForObject(Object object)
- {
- return object;
- }
-
-
- public Image getOverlayImageForObject(Object object)
- {
- Image result = null;
- try
- {
- IMarker marker = getMarkerForObject(object);
- if (marker != null)
- {
- if (marker.isSubtypeOf(IMarker.TASK))
- {
- result= taskOverlayImage;
- }
- else if (marker.isSubtypeOf(IMarker.BOOKMARK))
- {
- result = bookmarkOverlayImage;
- }
- else if (marker.isSubtypeOf(IMarker.PROBLEM))
- {
- switch (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO))
- {
- case IMarker.SEVERITY_INFO: { result = problemInfoOverlayImage; break; }
- case IMarker.SEVERITY_WARNING: { result = problemWarningOverlayImage; break; }
- case IMarker.SEVERITY_ERROR: { result = problemErrorOverlayImage; break; }
- }
- }
- }
- }
- catch (Exception e)
- {
- }
- return result;
- }
-
-
- public IMarker getMarkerForObject(Object object)
- {
- IMarker result = null;
- Object key = object != null ? getKeyForObject(object) : null;
- if (key != null)
- {
- result = (IMarker)hashtable.get(key);
- }
- return result;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/WindowUtility.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/WindowUtility.java
deleted file mode 100644
index 2c7127c..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/WindowUtility.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-
-public class WindowUtility
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- public static Object getSelection(ISelection selection)
- {
- if (selection == null)
- {
- return null;
- } // end of if ()
-
- Object result = null;
- if (selection instanceof IStructuredSelection)
- {
- IStructuredSelection es= (IStructuredSelection)selection;
- Iterator i= es.iterator();
- if (i.hasNext())
- {
- result= i.next();
- }
- }
- return result;
- }
-
- public static List getSelectionList(ISelection selection)
- {
- List result = null;
- if (selection != null)
- {
- if (selection instanceof IStructuredSelection)
- {
- IStructuredSelection es= (IStructuredSelection)selection;
- result = new Vector();
- for (Iterator i= es.iterator(); i.hasNext(); )
- {
- result.add(i.next());
- }
- }
- }
- return result;
- }
-
- public static void openErrorCreatingFile(Shell shell, IResource resource)
- {
- String title = null;
- String briefMessage = null;
- String reason = null;
- String details = null;
-
-// KCPort TODO
-// title = B2BGUIPlugin.getInstance().getString("_UI_ERROR_CREATING_FILE_TITLE");
-// briefMessage = B2BGUIPlugin.getInstance().getString("_UI_ERROR_CREATING_FILE_SHORT_DESC", resource.getName());
-// details = B2BGUIPlugin.getInstance().getString("_UI_ERROR_CREATING_FILE_LONG_DESC", resource.getLocation().toOSString());
-//
-// IResource parent = resource.getParent();
-// if (parent != null)
-// {
-// if (parent.isReadOnly())
-// {
-// reason = B2BGUIPlugin.getInstance().getString("_UI_PARENT_FOLDER_IS_READ_ONLY", parent.getName());
-// }
-// else
-// {
-// // on windows the isReadOnly() = false for read only shared directory... so we give a hint
-// reason = B2BGUIPlugin.getInstance().getString("_UI_UNKNOWN_ERROR_WITH_HINT", parent.getName());
-// }
-// }
-//
-// if (reason == null)
-// {
-// reason = B2BGUIPlugin.getInstance().getString("_UI_UNKNOWN_ERROR");
-// }
-
- openError(shell, title, briefMessage, reason, details);
- }
-
- public static void openError(Shell shell, String title, String briefMessage, String reason, String detailedMessage)
- {
- ErrorDialog.openError(shell, title, briefMessage, createStatus(reason, detailedMessage));
- }
-
- private static IStatus createStatus(String reason, String msg)
- {
-// KCPort TODO
-// String pluginId = B2BGUIPlugin.getInstance().getDescriptor().getUniqueIdentifier();
- String pluginId = "";
- MultiStatus multiStatus = new MultiStatus(pluginId, 0, reason, null);
- Status status = new Status(IStatus.ERROR, pluginId, 0, msg, null);
- multiStatus.add(status);
- return multiStatus;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/ActionHandlerListener.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/ActionHandlerListener.java
deleted file mode 100644
index 2a8f0d8..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/ActionHandlerListener.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.actionhandler;
-
-import java.util.ArrayList;
-
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.window.ApplicationWindow;
-import org.eclipse.swt.events.MenuEvent;
-import org.eclipse.swt.events.MenuListener;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IPartListener;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.internal.PartSite;
-import org.eclipse.wst.common.ui.internal.actionhandler.action.CopyAction;
-import org.eclipse.wst.common.ui.internal.actionhandler.action.CutAction;
-import org.eclipse.wst.common.ui.internal.actionhandler.action.EditAction;
-import org.eclipse.wst.common.ui.internal.actionhandler.action.PasteAction;
-
-
-
-public class ActionHandlerListener implements IPartListener, MenuListener
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
-
- /**
- * Constructor for ActionHandlerListener.
- */
- public ActionHandlerListener()
- {
- super();
- createEditActions();
- }
-
- /**
- * Method connectPart. This call registers your part to the actionhandler listener
- * if it hasn't been registered already and hooks up the generic cut/copy/paste action handlers.
- * Invoke this method from the init() routine of your #IViewPart or #IEditorPart if you do not
- * have any custom cut/copy/paste action handlers.
- *
- * If you have a customized cut/copy/paste action handlers, invoke this method after you
- * have finished your custom processing to add/remove your actionhandlers.
- *
- * @param part - the workbench part that you would like to connect the generic cut/copy/paste handlers
- */
- static public void connectPart(IWorkbenchPart part)
- {
- getInstance().connectWorkbenchPart(part);
- }
-
- static protected ActionHandlerListener actionHandlerListener;
- static protected ActionHandlerListener getInstance()
- {
- if (actionHandlerListener == null)
- {
- actionHandlerListener = new ActionHandlerListener();
- }
- return actionHandlerListener;
- }
-
-
-
- protected ArrayList workbenchWindows = new ArrayList();
- public void listenToWorkbenchWindow(IWorkbenchWindow workbenchWindow)
- {
- if (!workbenchWindows.contains(workbenchWindow))
- {
- workbenchWindows.add(workbenchWindow);
- workbenchWindow.getPartService().addPartListener(this);
- MenuManager editMenu = (MenuManager) ((ApplicationWindow)workbenchWindow).getMenuBarManager().findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
- if (editMenu != null)
- editMenu.getMenu().addMenuListener(this);
- }
- }
-
- protected void createEditActions()
- {
- cut = new CutAction();
- copy = new CopyAction();
- paste = new PasteAction();
- }
-
- protected IActionBars getActionBars(IWorkbenchPart part)
- {
- IActionBars actionBars = null;
- if (part != null)
- {
- IWorkbenchPartSite partSite = part.getSite();
- if (partSite instanceof PartSite)
- {
- actionBars = ((PartSite)partSite).getActionBars();
- }
- }
- return actionBars;
- }
-
- /**
- * Method connectWorkbenchPart. Ensure we are already listening to the workbenchwindow,
- * register the part's id and then connect the cut/copy/paste actions
- * @param part
- */
- public void connectWorkbenchPart(IWorkbenchPart part)
- {
- IWorkbenchWindow wbw = part.getSite().getWorkbenchWindow();
- listenToWorkbenchWindow(wbw);
- registerPartId(part);
- connectCutCopyPasteActions(part);
- }
-
- /**
- * Method isRegisteredPart. Returns whether the part has already been
- * registered as being a candidate for the generic cut/copy/paste actions.
- *
- * @param part
- * @return boolean
- */
- public boolean isRegisteredPart(IWorkbenchPart part)
- {
- String partId = part.getSite().getId();
- return registeredParts.contains(partId);
- }
-
- protected ArrayList registeredParts = new ArrayList();
- protected void registerPartId(IWorkbenchPart part)
- {
- if (!isRegisteredPart(part))
- {
- String partId = part.getSite().getId();
- registeredParts.add(partId);
- }
- }
-
- /**
- * Method connectCutCopyPasteActions. Connect the cut/copy/paste actions
- * to the workbench part.
- *
- * @param part
- */
- public void connectCutCopyPasteActions(IWorkbenchPart part)
- {
- IActionBars actionBars = getActionBars(part);
- if (actionBars != null)
- {
- part.getSite().getKeyBindingService().registerAction(cut);
- part.getSite().getKeyBindingService().registerAction(copy);
- part.getSite().getKeyBindingService().registerAction(paste);
- //connectCutCopyPasteActions(actionBars);
- }
- }
-
-
- /**
- * Method connectCutCopyPasteActions. Only set the actionhandlers if
- * there isn't one active for the appropriate action.
- *
- * @param actionBars
- */
- public void connectCutCopyPasteActions(IActionBars actionBars)
- {
- if (actionBars.getGlobalActionHandler(ActionFactory.CUT.getId()) == null)
- {
- actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), cut);
- }
- if (actionBars.getGlobalActionHandler(ActionFactory.COPY.getId()) == null)
- {
- actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copy);
- }
- if (actionBars.getGlobalActionHandler(ActionFactory.PASTE.getId()) == null)
- {
- actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), paste);
- }
- enableActions();
- actionBars.updateActionBars();
- }
-
- protected IWorkbenchPart getWorkbenchPart()
- {
- IWorkbenchWindow wbw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (wbw == null)
- return null;
-
- IWorkbenchPage wbp = wbw.getActivePage();
- if (wbp == null)
- return null;
-
- return wbp.getActivePart();
- }
-
- protected void updateActions()
- {
- IWorkbenchPart part = getWorkbenchPart();
- if (part != null &&
- isRegisteredPart(part))
- {
- IActionBars actionBars = getActionBars(part);
-
- Control focusControl = cut.getFocusControl();
- boolean enable = true;
- if (isValidFocusControl() &&
- actionBars != null)
- {
- String clipboardText = paste.getClipboardText();
- String selectionText = copy.getSelectionText();
- boolean isReadOnly = paste.isReadOnlyFocusControl();
- boolean clipboardNotEmpty = clipboardText != null && !clipboardText.equals("");
- boolean textSelected = selectionText != null && !selectionText.equals("");
-
- cut.setEnabled(!isReadOnly && textSelected);
- copy.setEnabled(textSelected && !(focusControl instanceof Combo && isReadOnly));
- paste.setEnabled(!isReadOnly && clipboardNotEmpty);
- }
- else
- {
- cut.setEnabled(false);
- copy.setEnabled(false);
- paste.setEnabled(false);
- }
- actionBars.updateActionBars();
- }
- }
-
- protected boolean isValidFocusControl()
- {
- // delgate to one of the edit actions
- return cut.isValidFocusControl();
- }
-
- protected void enableActions()
- {
- cut.setEnabled(true);
- copy.setEnabled(true);
- paste.setEnabled(true);
- }
-
- /**
- * Connect the cut/copy/paste actions if a registered part is activated.
- *
- * @see IPartListener#partActivated(IWorkbenchPart)
- */
- public void partActivated(IWorkbenchPart part)
- {
- if (isRegisteredPart(part))
- {
-// System.out.println("registered part activated" + part);
- connectCutCopyPasteActions(part);
- }
- }
-
- protected EditAction cut,copy,paste;
-
- /**
- * @see IPartListener#partBroughtToTop(IWorkbenchPart)
- */
- public void partBroughtToTop(IWorkbenchPart part)
- {
- }
- /**
- * @see IPartListener#partClosed(IWorkbenchPart)
- */
- public void partClosed(IWorkbenchPart part)
- {
- }
- /**
- * @see IPartListener#partDeactivated(IWorkbenchPart)
- */
- public void partDeactivated(IWorkbenchPart part)
- {
- }
- /**
- * @see IPartListener#partOpened(IWorkbenchPart)
- */
- public void partOpened(IWorkbenchPart part)
- {
- }
-
-
- /**
- * If the menu is hidden on a registered part, then renable all actions. This
- * takes away the need for us to monitor the control traversal. If the individual
- * action isn't applicable when it is invoked, the action becomes a no op.
- * @see MenuListener#menuHidden(MenuEvent)
- */
- public void menuHidden(MenuEvent e)
- {
- IWorkbenchPart part = getWorkbenchPart();
- if (part != null &&
- isRegisteredPart(part))
- {
- enableActions();
-
- IActionBars actionbars = getActionBars(part);
- actionbars.updateActionBars();
- }
- }
-
- /**
- * Update the cut/copy/paste enablement (if a registered part is active) just
- * before showing the edit menu.
- *
- * @see MenuListener#menuShown(MenuEvent)
- */
- public void menuShown(MenuEvent e)
- {
- updateActions();
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/CopyAction.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/CopyAction.java
deleted file mode 100644
index 2e7a488..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/CopyAction.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.actionhandler.action;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
-
-public class CopyAction extends EditAction
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.action.IAction#getActionDefinitionId()
- */
- public String getActionDefinitionId()
- {
- return IWorkbenchActionDefinitionIds.COPY;
- }
-
- public void run()
- {
- Control control = getFocusControl();
- if (control instanceof Text)
- {
- ((Text)control).copy();
- }
- else if (control instanceof StyledText)
- {
- ((StyledText)control).copy();
- }
- else if (control instanceof Combo)
- {
- ((Combo)control).copy();
- }
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/CutAction.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/CutAction.java
deleted file mode 100644
index 439e801..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/CutAction.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.actionhandler.action;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
-
-public class CutAction extends EditAction
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.action.IAction#getActionDefinitionId()
- */
- public String getActionDefinitionId()
- {
- return IWorkbenchActionDefinitionIds.CUT;
- }
-
- public void run()
- {
- Control control = getFocusControl();
- if (control instanceof Text)
- {
- ((Text)control).cut();
- }
- if (control instanceof StyledText)
- {
- ((StyledText)control).cut();
- }
- if (control instanceof Combo)
- {
- ((Combo)control).cut();
- }
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/EditAction.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/EditAction.java
deleted file mode 100644
index 9918d87..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/EditAction.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.actionhandler.action;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Text;
-
-public class EditAction extends Action
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- public Control getFocusControl()
- {
- return Display.getCurrent().getFocusControl();
- }
-
- public String getClipboardText()
- {
- Control focusControl = getFocusControl();
- if (focusControl != null)
- {
- Clipboard clipboard = new Clipboard(getFocusControl().getDisplay());
- TextTransfer textTransfer = TextTransfer.getInstance();
- String availableText = (String) clipboard.getContents(textTransfer);
- clipboard.dispose();
- return availableText;
- }
- return null;
-// String string = "";
-// if (OS.OpenClipboard (0)) {
-// int hMem = OS.GetClipboardData (OS.IsUnicode ? OS.CF_UNICODETEXT : OS.CF_TEXT);
-// if (hMem != 0) {
-// int byteCount = OS.GlobalSize (hMem);
-// int ptr = OS.GlobalLock (hMem);
-// if (ptr != 0) {
-// /* Use the character encoding for the default locale */
-// TCHAR buffer = new TCHAR (0, byteCount / TCHAR.sizeof);
-// OS.MoveMemory (buffer, ptr, byteCount);
-// string = buffer.toString (0, buffer.strlen ());
-// OS.GlobalUnlock (hMem);
-// }
-// }
-// OS.CloseClipboard ();
-// }
-// return string;
- }
-
- public String getSelectionText()
- {
- Control control = getFocusControl();
- if (control instanceof Text)
- {
- return ((Text)control).getSelectionText();
- }
- if (control instanceof StyledText)
- {
- return ((StyledText)control).getSelectionText();
- }
- if (control instanceof Combo)
- {
- Combo combo = (Combo)control;
- Point selection = combo.getSelection();
- return combo.getText().substring(selection.x, selection.y);
- }
- return "";
- }
-
- public boolean isReadOnlyFocusControl()
- {
- Control control = getFocusControl();
- if (control instanceof Text)
- {
- return !((Text)control).getEditable();
- }
- if (control instanceof StyledText)
- {
- return !((StyledText)control).getEditable();
- }
- if (control instanceof Combo)
- {
- Combo combo = (Combo)control;
- return (combo.getStyle() & SWT.READ_ONLY) == SWT.READ_ONLY;
- }
- return false;
- }
-
- public boolean isValidFocusControl()
- {
- Control control = getFocusControl();
- return (control instanceof Text ||
- control instanceof StyledText ||
- control instanceof Combo);
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/PasteAction.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/PasteAction.java
deleted file mode 100644
index 38a25a5..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/actionhandler/action/PasteAction.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.actionhandler.action;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
-
-public class PasteAction extends EditAction
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.action.IAction#getActionDefinitionId()
- */
- public String getActionDefinitionId()
- {
- return IWorkbenchActionDefinitionIds.PASTE;
- }
-
- public void run()
- {
- Control control = getFocusControl();
- if (control instanceof Text)
- {
- ((Text)control).paste();
- }
- if (control instanceof StyledText)
- {
- ((StyledText)control).paste();
- }
- if (control instanceof Combo)
- {
- ((Combo)control).paste();
- }
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resource/ResourceDeleteListener.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resource/ResourceDeleteListener.java
deleted file mode 100644
index 97bac99..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resource/ResourceDeleteListener.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.resource;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.wst.common.ui.internal.UIPlugin;
-
-
-public class ResourceDeleteListener implements IResourceChangeListener, IResourceDeltaVisitor
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- protected ArrayList recognizedEditorParts = new ArrayList();
-
- public void addEditorPartClass(Class editorPartClass)
- {
- recognizedEditorParts.add(editorPartClass);
- }
-
- public void resourceChanged(IResourceChangeEvent event)
- {
- IResourceDelta resourceDelta = event.getDelta();
-
- try
- {
- if (resourceDelta != null)
- {
- resourceDelta.accept(this);
- }
- }
- catch (Exception e)
- {
-// B2BGUIPlugin.getPlugin().getMsgLogger().write("Exception caught during resource change" + e);
-// B2BGUIPlugin.getPlugin().getMsgLogger().writeCurrentThread();
- }
- }
-
- public boolean visit(IResourceDelta delta)
- {
- if (delta.getKind() == IResourceDelta.REMOVED)
- {
- // handle removed resource
- //closeEditors(delta.getResource());
- /*
- * defect 235374
- * Without ayncExec, RuntimeException is raised:
- * "The resource tree is locked for modifications."
- * from Resource.refreshLocal().
- */
- Display.getDefault().asyncExec
- (new CloseEditors(recognizedEditorParts,delta.getResource()));
- }
- return true;
- }
-
- public static class CloseEditors implements Runnable
- {
- private IResource resource;
- private ArrayList recognizedEditorParts;
-
- public CloseEditors(ArrayList editorParts, IResource res)
- {
- recognizedEditorParts = editorParts;
- resource = res;
- }
-
- public void run()
- {
- // close all associated editors that are editing this resource,
- // if it is one of the recognizedEditorParts
- IWorkbenchWindow windows[] =
- UIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
-
- for (int i = 0; i < windows.length; i++)
- {
- IWorkbenchPage pages[] = windows[i].getPages();
-
- for (int j = 0; j < pages.length; j++ )
- {
- IEditorPart editors[] = pages[j].getEditors();
- for (int k = 0; k < editors.length; k++)
- {
- IEditorPart editor = editors[k];
- IEditorInput editorInput = editor.getEditorInput();
-
- if (editorInput instanceof IFileEditorInput)
- {
- if (((IFileEditorInput)editorInput).getFile().equals(resource) &&
- recognizedEditorParts.contains(editor.getClass()))
- {
- IWorkbenchPage page = pages[j];
- page.closeEditor(editor, false);
- }
- }
- }
- }
- }
- }
- }
-
- /*
- private void closeEditors(IResource deletedResource)
- {
- // close all associated editors that are editing this resource,
- // if it is one of the recognizedEditorParts
- IWorkbenchWindow windows[] = B2BGUIPlugin.getInstance().getWorkbench().getWorkbenchWindows();
-
- for (int i = 0; i < windows.length; i++)
- {
- IWorkbenchPage pages[] = windows[i].getPages();
-
- for (int j = 0; j < pages.length; j++ )
- {
- IEditorPart editors[] = pages[j].getEditors();
- for (int k = 0; k < editors.length; k++)
- {
- IEditorPart editor = editors[k];
- IEditorInput editorInput = editor.getEditorInput();
-
- if (editorInput instanceof IFileEditorInput)
- {
- if (((IFileEditorInput)editorInput).getFile().equals(deletedResource) &&
- recognizedEditorParts.contains(editor.getClass()))
- {
- IWorkbenchPage page = pages[j];
- org.eclipse.swt.widgets.
- Display.getDefault().asyncExec(new CloseEditor(page, editor));
- }
- }
- }
- }
- }
- }
- */
-
- public static class CloseEditor implements Runnable
- {
- protected IWorkbenchPage page;
- protected IEditorPart editor;
- public CloseEditor(IWorkbenchPage page, IEditorPart editor)
- {
- this.page = page;
- this.editor = editor;
- }
- public void run()
- {
- page.closeEditor(editor, false);
- }
- }
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/ChangeHelper.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/ChangeHelper.java
deleted file mode 100644
index 46a6802..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/ChangeHelper.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.resources;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.wst.common.ui.internal.UIPlugin;
-
-
-public class ChangeHelper
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- protected IEditorPart editor;
-
- public ChangeHelper(IEditorPart editor)
- {
- this.editor = editor;
- }
-
- boolean handlingEditorInput = false;
-
- public void handleEditorInputChanged()
- {
- if (handlingEditorInput)
- return;
-
- handlingEditorInput = true;
-
- if (isDeleted(editor.getEditorInput()))
- {
- // if saveas is allowed, give the user an opportunity to
- // save the existing contents to another file
- if (editor.isDirty() && editor.isSaveAsAllowed())
- {
- boolean isDone = false;
- while (isDone == false)
- {
- String[] buttons= { UIPlugin.getResourceString("_UI_SAVE_BUTTON"),
- UIPlugin.getResourceString("_UI_CLOSE_BUTTON") };
-
- final MessageDialog msg = new MessageDialog(editor.getSite().getShell(),
- UIPlugin.getResourceString("_UI_FILE_CHANGED_TITLE"),
- null,
- UIPlugin.getResourceString("_UI_FILE_DELETED_SAVE_CHANGES"),
- MessageDialog.QUESTION,
- buttons,
- 0);
-
- int rc = msg.open();
- if (rc == 0)
- {
- editor.doSaveAs();
- }
- else
- {
- close(false);
- break;
- }
- if (!editor.isDirty())//!isDeleted(editor.getEditorInput()))
- {
- isDone = true;
- }
- }
- // refresh it so it gets removed from the workspace
-// WorkbenchUtility.refreshLocalWorkspaceFile(((IFileEditorInput)editor.getEditorInput()).getFile(), new NullProgressMonitor());
- }
- else
- {
- // otherwise time to shutdown the editor.
-// MessageDialog.openConfirm(editor.getSite().getShell(), B2BGUIPlugin.getGUIString("_UI_FILE_CHANGED_TITLE"), B2BGUIPlugin.getGUIString("_UI_FILE_DELETED_EDITOR_CLOSED"));
- close(false);
- }
- }
- else
- {
- // The file has just had its contents modified
- if (editor instanceof IExternalChangeEditorListener)
- {
-
- boolean rc = MessageDialog.openQuestion(editor.getSite().getShell(), UIPlugin.getResourceString("_UI_FILE_CHANGED_TITLE"), UIPlugin.getResourceString("_UI_FILE_CHANGED_LOAD_CHANGES"));
- if (rc == true)
- {
- ((IExternalChangeEditorListener)editor).reload();
- }
- }
- }
- handlingEditorInput = false;
- }
-
- // close the editor
- public void close(final boolean save)
- {
- Display display= editor.getSite().getShell().getDisplay();
- display.asyncExec(new Runnable()
- {
- public void run()
- {
- editor.getSite().getPage().closeEditor(editor, save);
- }
- });
- }
-
- /*
- * check if file is deleted
- */
- public boolean isDeleted(Object element)
- {
- if (element instanceof IFileEditorInput)
- {
- IFileEditorInput input= (IFileEditorInput) element;
-
- IPath path= input.getFile().getLocation();
- if (path == null)
- {
- return true;
- }
- return !path.toFile().exists();
- }
- return false;
- }
-}// ChangeHelper
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/IExternalChangeEditorListener.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/IExternalChangeEditorListener.java
deleted file mode 100644
index 5474096..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/IExternalChangeEditorListener.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.resources;
-
-import org.eclipse.core.runtime.IPath;
-
-public interface IExternalChangeEditorListener
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- public void handleEditorInputChanged();
- public void handleEditorPathChanged(IPath newPath);
- public void reload();
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/IValidateEditEditor.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/IValidateEditEditor.java
deleted file mode 100644
index d24fd7d..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/IValidateEditEditor.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.resources;
-
-public interface IValidateEditEditor
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2002.";
- public void undoChange();
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/PropertyResourceChangeListener.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/PropertyResourceChangeListener.java
deleted file mode 100644
index be15730..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/PropertyResourceChangeListener.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.resources;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.wst.common.ui.internal.UIPlugin;
-
-
-public class PropertyResourceChangeListener extends ResourceChangeListener implements IPropertyListener
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2002.";
- public PropertyResourceChangeListener(IEditorPart editPart)
- {
- super(editPart);
- editPart.addPropertyListener(this);
- }
-
- boolean dirtyState = false;
- IFile[] iFileList = null;
- IEditorPart editorPart = null;
- Runnable currentRunnable = null;
- boolean inValidateEditCall = false;
-
- public void propertyChanged(Object source, int propId)
- {
- if (propId == IEditorPart.PROP_DIRTY)
- {
- if ((source instanceof IEditorPart) && (currentRunnable == null))
- {
- editorPart = (IEditorPart)source;
- if (editorPart.isDirty() && (editorPart.getEditorInput() instanceof IFileEditorInput))
- {
- IFileEditorInput editorInput = (IFileEditorInput)(editorPart.getEditorInput());
- // Only call validateEdit if the file is read only
- if (editorInput.getFile().isReadOnly())
- {
- iFileList = new IFile[1];
- iFileList[0] = editorInput.getFile();
-
- currentRunnable = new Runnable()
- {
- public void run()
- {
- inValidateEditCall = true;
- IStatus status = ResourcesPlugin.getWorkspace().validateEdit(iFileList, editorPart.getSite().getShell());
- if (status.getCode() != IStatus.OK)
- {
- ((IValidateEditEditor)editorPart).undoChange();
- setDirtyState(editorPart.isDirty());
-
- if (status.getCode() == IStatus.ERROR)
- MessageDialog.openError(Display.getCurrent().getActiveShell() ,
- UIPlugin.getResourceString("_UI_ERROR_VALIDATE_EDIT_FAIL_ONE_FILE"),
- status.getMessage());
- }
- else
- {
- checkChanged(editorPart);
- }
-
- inValidateEditCall = false;
- currentRunnable = null;
- }
- };
-
- // we need to ensure that this is run via 'asyncExec' since these
- // notifications can come from a non-ui thread
- if (Display.getCurrent() != null)
- Display.getCurrent().timerExec(100,currentRunnable);
- else
- Display.getDefault().timerExec(100,currentRunnable);
- }
- }
- }
- }
- }
-
-public boolean inValidateEditCall()
-{
- return inValidateEditCall;
-}
-
-/**
- * Gets the dirtyState.
- * @return Returns a boolean
- */
-public boolean getDirtyState() {
- return dirtyState;
-}
-
-/**
- * Sets the dirtyState.
- * @param dirtyState The dirtyState to set
- */
-public void setDirtyState(boolean dirtyState) {
- this.dirtyState = dirtyState;
-}
-
-}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/ResourceChangeListener.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/ResourceChangeListener.java
deleted file mode 100644
index 18b64d4..0000000
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/internal/resources/ResourceChangeListener.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
-package org.eclipse.wst.common.ui.internal.resources;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IPartListener;
-import org.eclipse.ui.IWorkbenchPart;
-
-public class ResourceChangeListener implements IPartListener, IResourceChangeListener, IResourceDeltaVisitor
-{
- public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
- protected ArrayList recognizedEditorParts = new ArrayList();
- protected IEditorPart editor;
- protected long fileTimestamp;
-
- public ResourceChangeListener(IEditorPart editPart)
- {
- editor = editPart;
- // add a part activate listener
- editor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
- // add resource change listener
- getFile().getWorkspace().addResourceChangeListener(this);
- setTimestamp();
- }
-
- protected void setTimestamp()
- {
- fileTimestamp = computeModificationStamp(getFile());
- }
-
- /**
- * Computes the initial modification stamp for the given resource.
- *
- * @param resource the resource
- * @return the modification stamp
- */
- protected long computeModificationStamp(IResource resource) {
- long modificationStamp= resource.getModificationStamp();
-
- IPath path= resource.getLocation();
- if (path == null)
- return modificationStamp;
-
- modificationStamp= path.toFile().lastModified();
- return modificationStamp;
- }
-
- protected IFile getFile()
- {
- IFileEditorInput fileInput = (IFileEditorInput) editor.getEditorInput();
- return fileInput.getFile();
- }
-
- protected void checkChanged(final IEditorPart editorPart)
- {
- if (!getFile().exists() ||
- fileTimestamp != computeModificationStamp(getFile()))
- {
- if (editorPart instanceof IExternalChangeEditorListener)
- {
- editorPart.getSite().getShell().getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- ((IExternalChangeEditorListener)editorPart).handleEditorInputChanged();
- setTimestamp();
- }
- });
- }
- }
- }
-
- /**
- * @see IPartListener#partActivated(IWorkbenchPart)
- */
- public void partActivated(IWorkbenchPart part)
- {
- if (part == editor)
- checkChanged(editor);
- }
-
- /**
- * @see IPartListener#partBroughtToTop(IWorkbenchPart)
- */
- public void partBroughtToTop(IWorkbenchPart arg0) {
-// if (arg0 == editor)
-// B2BGUIPlugin.getPlugin().getMsgLogger().write("part brought to top");
- }
-
- /**
- * @see IPartListener#partClosed(IWorkbenchPart)
- */
- public void partClosed(IWorkbenchPart part) {
- if (part == editor)
- {
- // add a part activate listener
- editor.getSite().getWorkbenchWindow().getPartService().removePartListener(this);
- // add resource change listener
- getFile().getWorkspace().removeResourceChangeListener(this);
-// B2BGUIPlugin.getPlugin().getMsgLogger().write("part closed");
- }
- }
-
- /**
- * @see IPartListener#partDeactivated(IWorkbenchPart)
- */
- public void partDeactivated(IWorkbenchPart part) {}
-
- /**
- * @see IPartListener#partOpened(IWorkbenchPart)
- */
- public void partOpened(IWorkbenchPart part) {}
-
- // IResourceChangeListener interface
- public void resourceChanged(IResourceChangeEvent event)
- {
- IResourceDelta resourceDelta = event.getDelta();
-
- try
- {
- if (resourceDelta != null)
- {
- resourceDelta.accept(this);
- }
- }
- catch (Exception e)
- {
-// B2BGUIPlugin.getPlugin().getMsgLogger().write("Exception caught during resource change" + e);
-// B2BGUIPlugin.getPlugin().getMsgLogger().writeCurrentThread();
- }
- }
-
- // IResourceDeltaVisitor
- public boolean visit(IResourceDelta delta)
- {
- if (delta.getResource().equals(getFile()))
- {
- switch (delta.getKind())
- {
- case IResourceDelta.CHANGED:
- setTimestamp();
- break;
- case IResourceDelta.REMOVED:
- if ((IResourceDelta.MOVED_TO & delta.getFlags()) != 0)
- {
- final IPath movedToPath = delta.getMovedToPath();
-
- editor.getSite().getShell().getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- // if the resource has moved or been renamed, let the editor do some work now
- ((IExternalChangeEditorListener)editor).handleEditorPathChanged(movedToPath);
- setTimestamp();
- }
- });
- }
- else
- {
- editor.getSite().getShell().getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- // if the resource is deleted, let the editor do some work now
- ((IExternalChangeEditorListener)editor).handleEditorInputChanged();
- setTimestamp();
- }
- });
-
- }
- break;
-
- default:
- break;
- }
- }
- return true;
- }
-}
-