Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon')
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/AbstractOpenOn.java271
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/ExternalFileEditorInput.java116
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/IOpenOn.java46
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenFileHyperlinkTracker.java660
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnAction.java74
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnBuilder.java267
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnDefinition.java157
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnProvider.java143
8 files changed, 0 insertions, 1734 deletions
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/AbstractOpenOn.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/AbstractOpenOn.java
deleted file mode 100644
index 1d59c406dc..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/AbstractOpenOn.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import java.io.File;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.swt.program.Program;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.util.URIResolver;
-import org.eclipse.wst.sse.ui.internal.Logger;
-import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
-import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil;
-
-
-/**
- * This action class retrieves the link/file selected by the cursor and
- * attempts to open the link/file in the default editor or web browser
- *
- * @deprecated Use base support for hyperlink navigation
- */
-abstract public class AbstractOpenOn implements IOpenOn {
- protected final String CANNOT_OPEN = SSEUIMessages.AbstractOpenOn_0; //$NON-NLS-1$
- // document currently associated with open
- private IDocument fDocument;
- protected final String FILE_PROTOCOL = "file:/";//$NON-NLS-1$
- private final String HTTP_PROTOCOL = "http://";//$NON-NLS-1$
-
- abstract protected IRegion doGetOpenOnRegion(int offset);
-
- abstract protected void doOpenOn(IRegion region);
-
- /**
- * Returns the current document associated with open on
- *
- * @return IDocument
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /**
- * Determines the editor associated with the given file name
- *
- * @param filename
- * @return editor id of the editor associated with the given file name
- */
- private String getEditorId(String filename) {
- IWorkbench workbench = PlatformUI.getWorkbench();
- IEditorRegistry editorRegistry = workbench.getEditorRegistry();
- IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(filename);
- if (descriptor != null)
- return descriptor.getId();
- return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
- }
-
- /**
- * Returns an IFile from the given uri if possible, null if cannot find
- * file from uri.
- *
- * @param fileString
- * file system path
- * @return returns IFile if fileString exists in the workspace
- */
- protected IFile getFile(String fileString) {
- IStructuredModel model = null;
- IFile file = null;
- try {
- model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- if (model != null) {
- // use the base location to obtain the in-workspace IFile
- IFile modelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(model.getBaseLocation()));
- if (modelFile != null) {
- // find the referenced file's location on disk
- URIResolver resolver = model.getResolver();
- if (resolver != null) {
- String filesystemLocation = resolver.getLocationByURI(fileString);
- if (filesystemLocation != null) {
- IFile[] workspaceFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(filesystemLocation));
- // favor a workspace file in the same project
- for (int i = 0; i < workspaceFiles.length && file == null; i++) {
- if (workspaceFiles[i].getProject().equals(modelFile.getProject())) {
- file = workspaceFiles[i];
- }
- }
- // if none were in the same project, just pick one
- if (file == null && workspaceFiles.length > 0) {
- file = workspaceFiles[0];
- }
- }
- }
- }
- }
- }
- catch (Exception e) {
- Logger.log(Logger.WARNING, e.getMessage());
- }
- finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- if (file == null && fileString.startsWith("/")) { //$NON-NLS-1$
- file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileString));
- }
- return file;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.IOpenOn#getOpenOnRegion(org.eclipse.jface.text.IDocument,
- * int)
- */
- public IRegion getOpenOnRegion(IDocument doc, int offset) {
- IRegion region;
- // set the document for this action
- setDocument(doc);
- region = doGetOpenOnRegion(offset);
- // reset the document back to null for this action
- setDocument(null);
- return region;
- }
-
- /**
- * Try to open the external file, fileString in its default editor
- *
- * @param fileString
- * @return IEditorPart editor opened or null if editor could not be opened
- */
- protected IEditorPart openExternalFile(String fileString) {
- // file does not exist in workspace so try to open using system editor
- File file = new File(fileString);
- // try to open existing external file if it exists
- if (file.exists()) {
- IEditorInput input = new ExternalFileEditorInput(file);
- String editorId = getEditorId(fileString);
-
- try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- return page.openEditor(input, editorId, true);
- }
- catch (PartInitException pie) {
- Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie);
- }
- }
- return null;
- }
-
- /**
- * Notifies user that open on selection action could not successfully open
- * the selection (writes message on status bar and beeps)
- */
- protected void openFileFailed() {
- PlatformStatusLineUtil.displayErrorMessage(CANNOT_OPEN);
- PlatformStatusLineUtil.addOneTimeClearListener();
- }
-
- /**
- * Opens the IFile, input in its default editor, if possible, and returns
- * the editor opened. Possible reasons for failure: input cannot be found,
- * input does not exist in workbench, editor cannot be opened.
- *
- * @return IEditorPart editor opened or null if input == null or does not
- * exist, external editor was opened, editor could not be opened
- */
- protected IEditorPart openFileInEditor(IFile input) {
- if (input != null && input.exists()) {
- try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- return IDE.openEditor(page, input, true);
- }
- catch (PartInitException pie) {
- Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie);
- }
- }
- return null;
- }
-
- // on
-
- /**
- * Opens the appropriate editor for fileString
- *
- * @param fileString
- */
- protected void openFileInEditor(String fileString) {
- IEditorPart editor = null;
- if (fileString != null) {
- // open web browser if this is a web address
- String temp = fileString.toLowerCase();
- if (temp.startsWith(HTTP_PROTOCOL)) {
- Program.launch(fileString); // launches web browser/executable
- // associated with uri
- return;
- }
- // chop off the file protocol
- if (temp.startsWith(FILE_PROTOCOL)) {
- fileString = fileString.substring(FILE_PROTOCOL.length());
- }
-
- // try to locate the file in the workspace and return an IFile if
- // found
- IFile file = getFile(fileString);
- if (file != null) {
- // file exists in workspace
- editor = openFileInEditor(file);
- }
- else {
- // file does not exist in workspace
- editor = openExternalFile(fileString);
- }
- }
- // no editor was opened
- if (editor == null) {
- openFileFailed();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.IOpenOn#openOn(org.eclipse.jface.text.IDocument,
- * org.eclipse.jface.text.IRegion)
- */
- public void openOn(IDocument doc, IRegion region) {
- // set the document for this action
- setDocument(doc);
- // if no region was given this action fails
- if (region == null)
- openFileFailed();
- else
- doOpenOn(region);
- // reset the document back to null for this action
- setDocument(null);
- }
-
- /**
- * Sets current document associated with open on
- *
- * @param document
- */
- public void setDocument(IDocument document) {
- fDocument = document;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/ExternalFileEditorInput.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/ExternalFileEditorInput.java
deleted file mode 100644
index 58eb65861f..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/ExternalFileEditorInput.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import java.io.File;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-import org.eclipse.ui.editors.text.ILocationProvider;
-
-/**
- * EditorInput for external files. Copied from
- * org.eclipse.ui.internal.editors.text.JavaFileEditorInput
- *
- * @deprecated Use base support for hyperlink navigation
- */
-public class ExternalFileEditorInput implements IEditorInput, ILocationProvider {
-
- private File fFile;
-
- public ExternalFileEditorInput(File file) {
- super();
- fFile = file;
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object o) {
- if (o == this)
- return true;
-
- if (o instanceof ExternalFileEditorInput) {
- ExternalFileEditorInput input = (ExternalFileEditorInput) o;
- return fFile.equals(input.fFile);
- }
-
- return false;
- }
-
- /*
- * @see org.eclipse.ui.IEditorInput#exists()
- */
- public boolean exists() {
- return fFile.exists();
- }
-
- /*
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter(Class adapter) {
- if (ILocationProvider.class.equals(adapter))
- return this;
- return Platform.getAdapterManager().getAdapter(this, adapter);
- }
-
- /*
- * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
- */
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- /*
- * @see org.eclipse.ui.IEditorInput#getName()
- */
- public String getName() {
- return fFile.getName();
- }
-
- /*
- * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
- */
- public IPath getPath(Object element) {
- if (element instanceof ExternalFileEditorInput) {
- ExternalFileEditorInput input = (ExternalFileEditorInput) element;
- return new Path(input.fFile.getAbsolutePath());
- }
- return null;
- }
-
- /*
- * @see org.eclipse.ui.IEditorInput#getPersistable()
- */
- public IPersistableElement getPersistable() {
- return null;
- }
-
- /*
- * @see org.eclipse.ui.IEditorInput#getToolTipText()
- */
- public String getToolTipText() {
- return fFile.getAbsolutePath();
- }
-
- /*
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return fFile.hashCode();
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/IOpenOn.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/IOpenOn.java
deleted file mode 100644
index ec4b292ffe..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/IOpenOn.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-
-/**
- * Interface for Open On... navigation
- *
- * @author amywu
- */
-public interface IOpenOn {
- /**
- * Returns the entire region relevant to the current offset where an
- * openable source region is found. null if offset does not contain an
- * openable source.
- *
- * @param document
- * IDocument
- * @param offset
- * int
- * @return IRegion entire region of openable source
- */
- public IRegion getOpenOnRegion(IDocument document, int offset);
-
- /**
- * Opens the file/source relevant to region if possible.
- *
- * @param viewer
- * ITextViewer
- * @param region
- * Region to examine
- */
- public void openOn(IDocument document, IRegion region);
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenFileHyperlinkTracker.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenFileHyperlinkTracker.java
deleted file mode 100644
index e4e8659b03..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenFileHyperlinkTracker.java
+++ /dev/null
@@ -1,660 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import com.ibm.icu.util.StringTokenizer;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.wst.sse.ui.internal.Logger;
-import org.eclipse.wst.sse.ui.internal.util.EditorUtility;
-
-
-/**
- * @deprecated Use org.eclipse.jface.text.hyperlink.HyperlinkManager
- */
-public class OpenFileHyperlinkTracker implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener, IPropertyChangeListener, IDocumentListener, ITextInputListener {
-
- /** The session is active. */
- private boolean fActive;
-
- /** The currently active style range. */
- private IRegion fActiveRegion;
- /** Preference key for browser-like links to be enabled */
- private String fBrowserLikeLinksKeyModifierKey;
-
- /** The link color. */
- private Color fColor;
- /** The hand cursor. */
- private Cursor fCursor;
- /** The key modifier mask. */
- private int fKeyModifierMask;
- /** Preference key for hyperlink underline color */
- private String fLinkColorKey;
- /** The preference store */
- private IPreferenceStore fPreferenceStore;
- /** The currently active style range as position. */
- private Position fRememberedPosition;
-
- /** The text viewer this hyperlink tracker is associated with */
- private ITextViewer fTextViewer;
-
- /**
- *
- */
- public OpenFileHyperlinkTracker(ITextViewer textViewer) {
- fTextViewer = textViewer;
- }
-
- private void activateCursor(ITextViewer viewer) {
- StyledText text = viewer.getTextWidget();
- if (text == null || text.isDisposed())
- return;
- Display display = text.getDisplay();
- if (fCursor == null)
- fCursor = new Cursor(display, SWT.CURSOR_HAND);
- text.setCursor(fCursor);
- }
-
- private int computeStateMask(String modifiers) {
- if (modifiers == null)
- return -1;
-
- if (modifiers.length() == 0)
- return SWT.NONE;
-
- int stateMask = 0;
- StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
- while (modifierTokenizer.hasMoreTokens()) {
- int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
- if (modifier == 0 || (stateMask & modifier) == modifier)
- return -1;
- stateMask = stateMask | modifier;
- }
- return stateMask;
- }
-
- /**
- * Creates a color from the information stored in the given preference
- * store. Returns <code>null</code> if there is no such information
- * available.
- */
- private Color createColor(IPreferenceStore store, String key, Display display) {
-
- RGB rgb = null;
-
- if (store.contains(key)) {
-
- if (store.isDefault(key))
- rgb = PreferenceConverter.getDefaultColor(store, key);
- else
- rgb = PreferenceConverter.getColor(store, key);
- }
-
- return EditorUtility.getColor(rgb);
- }
-
- public void deactivate() {
- deactivate(false);
- }
-
- public void deactivate(boolean redrawAll) {
- if (!fActive)
- return;
-
- repairRepresentation(redrawAll);
- fActive = false;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- if (fActive && fActiveRegion != null) {
- fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
- try {
- event.getDocument().addPosition(fRememberedPosition);
- } catch (BadLocationException x) {
- fRememberedPosition = null;
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- if (fRememberedPosition != null) {
- if (!fRememberedPosition.isDeleted()) {
-
- event.getDocument().removePosition(fRememberedPosition);
- fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
- fRememberedPosition = null;
-
- ITextViewer viewer = getTextViewer();
- if (viewer != null) {
- StyledText widget = viewer.getTextWidget();
- if (widget != null && !widget.isDisposed()) {
- widget.getDisplay().asyncExec(new Runnable() {
- public void run() {
- deactivate();
- }
- });
- }
- }
-
- } else {
- fActiveRegion = null;
- fRememberedPosition = null;
- deactivate();
- }
- }
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
- */
- public void focusLost(FocusEvent event) {
- deactivate();
- }
-
- private int getCurrentTextOffset() {
- try {
- StyledText text = getTextViewer().getTextWidget();
- if (text == null || text.isDisposed())
- return -1;
-
- Display display = text.getDisplay();
- Point absolutePosition = display.getCursorLocation();
- Point relativePosition = text.toControl(absolutePosition);
-
- int widgetOffset = text.getOffsetAtLocation(relativePosition);
- if (getTextViewer() instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension = (ITextViewerExtension5) getTextViewer();
- return extension.widgetOffset2ModelOffset(widgetOffset);
- } else {
- return widgetOffset + getTextViewer().getVisibleRegion().getOffset();
- }
-
- } catch (IllegalArgumentException e) {
- return -1;
- }
- }
-
- private Point getMaximumLocation(StyledText text, int offset, int length) {
- Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
-
- for (int i = 0; i <= length; i++) {
- Point location = text.getLocationAtOffset(offset + i);
-
- if (location.x > maxLocation.x)
- maxLocation.x = location.x;
- if (location.y > maxLocation.y)
- maxLocation.y = location.y;
- }
-
- return maxLocation;
- }
-
- private Point getMinimumLocation(StyledText text, int offset, int length) {
- Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
-
- for (int i = 0; i <= length; i++) {
- Point location = text.getLocationAtOffset(offset + i);
-
- if (location.x < minLocation.x)
- minLocation.x = location.x;
- if (location.y < minLocation.y)
- minLocation.y = location.y;
- }
-
- return minLocation;
- }
-
- private IPreferenceStore getNewPreferenceStore() {
- return fPreferenceStore;
- }
-
- private ITextViewer getTextViewer() {
- return fTextViewer;
- }
-
- private void highlightRegion(ITextViewer viewer, IRegion region) {
-
- if (region.equals(fActiveRegion))
- return;
-
- repairRepresentation();
-
- StyledText text = viewer.getTextWidget();
- if (text == null || text.isDisposed())
- return;
-
-
- // Underline
- int offset = 0;
- int length = 0;
- if (viewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
- IRegion widgetRange = extension.modelRange2WidgetRange(new Region(region.getOffset(), region.getLength()));
- if (widgetRange == null)
- return;
-
- offset = widgetRange.getOffset();
- length = widgetRange.getLength();
-
- } else {
- offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
- length = region.getLength();
- }
- // need clearBackground to be true for paint event to be fired
- text.redrawRange(offset, length, true);
-
- fActiveRegion = region;
- }
-
- private boolean includes(IRegion region, IRegion position) {
- return position.getOffset() >= region.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
- }
-
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
- * org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- if (oldInput == null)
- return;
- deactivate();
- oldInput.removeDocumentListener(this);
- }
-
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
- * org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
- if (newInput == null)
- return;
- newInput.addDocumentListener(this);
- }
-
- public void install(IPreferenceStore store) {
- fPreferenceStore = store;
- ITextViewer textViewer = getTextViewer();
- if (textViewer == null)
- return;
-
- StyledText text = textViewer.getTextWidget();
- if (text == null || text.isDisposed())
- return;
-
- updateColor(textViewer);
-
- textViewer.addTextInputListener(this);
-
- IDocument document = textViewer.getDocument();
- if (document != null)
- document.addDocumentListener(this);
-
- text.addKeyListener(this);
- text.addMouseListener(this);
- text.addMouseMoveListener(this);
- text.addFocusListener(this);
- text.addPaintListener(this);
-
- updateKeyModifierMask();
-
- fPreferenceStore.addPropertyChangeListener(this);
- }
-
- /*
- * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
- */
- public void keyPressed(KeyEvent event) {
-
- if (fActive) {
- deactivate();
- return;
- }
-
- if (event.keyCode != fKeyModifierMask) {
- deactivate();
- return;
- }
-
- fActive = true;
-
- // removed for #25871
- //
- // ISourceViewer viewer= getSourceViewer();
- // if (viewer == null)
- // return;
- //
- // IRegion region= getCurrentTextRegion(viewer);
- // if (region == null)
- // return;
- //
- // highlightRegion(viewer, region);
- // activateCursor(viewer);
- }
-
- /*
- * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
- */
- public void keyReleased(KeyEvent event) {
-
- if (!fActive)
- return;
-
- deactivate();
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDown(MouseEvent event) {
-
- if (!fActive)
- return;
-
- if (event.stateMask != fKeyModifierMask) {
- deactivate();
- return;
- }
-
- if (event.button != 1) {
- deactivate();
- return;
- }
- }
-
- /*
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseMove(MouseEvent event) {
-
- if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
- deactivate();
- return;
- }
-
- if (!fActive) {
- if (event.stateMask != fKeyModifierMask)
- return;
- // modifier was already pressed
- fActive = true;
- }
-
- ITextViewer viewer = getTextViewer();
- if (viewer == null) {
- deactivate();
- return;
- }
-
- StyledText text = viewer.getTextWidget();
- if (text == null || text.isDisposed()) {
- deactivate();
- return;
- }
-
- if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
- deactivate();
- return;
- }
-
- IRegion region = null;
- int offset = getCurrentTextOffset();
- IOpenOn openOn = OpenOnProvider.getInstance().getOpenOn(getTextViewer().getDocument(), offset);
- if (openOn != null) {
- region = openOn.getOpenOnRegion(getTextViewer().getDocument(), offset);
- }
- if (region == null || region.getLength() == 0) {
- repairRepresentation();
- return;
- }
-
- highlightRegion(viewer, region);
- activateCursor(viewer);
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
-
- if (!fActive)
- return;
-
- if (e.button != 1) {
- deactivate();
- return;
- }
-
- boolean wasActive = fCursor != null;
- IRegion previousRegion = fActiveRegion;
-
- deactivate();
-
- if (wasActive) {
- IOpenOn openOn = OpenOnProvider.getInstance().getOpenOn(getTextViewer().getDocument(), previousRegion.getOffset());
- if (openOn != null) {
- openOn.openOn(getTextViewer().getDocument(), previousRegion);
- }
- }
- }
-
- /*
- * @see PaintListener#paintControl(PaintEvent)
- */
- public void paintControl(PaintEvent event) {
- if (fActiveRegion == null)
- return;
-
- ITextViewer viewer = getTextViewer();
- if (viewer == null)
- return;
-
- StyledText text = viewer.getTextWidget();
- if (text == null || text.isDisposed())
- return;
-
-
- int offset = 0;
- int length = 0;
-
- if (viewer instanceof ITextViewerExtension5) {
-
- ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
- IRegion widgetRange = extension.modelRange2WidgetRange(fActiveRegion);
- if (widgetRange == null)
- return;
-
- offset = widgetRange.getOffset();
- length = widgetRange.getLength();
-
- } else {
-
- IRegion region = viewer.getVisibleRegion();
- if (!includes(region, fActiveRegion))
- return;
-
- offset = fActiveRegion.getOffset() - region.getOffset();
- length = fActiveRegion.getLength();
- }
-
- // support for bidi
- Point minLocation = getMinimumLocation(text, offset, length);
- Point maxLocation = getMaximumLocation(text, offset, length);
-
- int x1 = minLocation.x;
- int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
- int y = minLocation.y + text.getLineHeight() - 1;
-
- GC gc = event.gc;
- if (fColor != null && !fColor.isDisposed())
- gc.setForeground(fColor);
- gc.drawLine(x1, y, x2, y);
- }
-
- /*
- * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- if (event.getProperty().equals(fLinkColorKey)) {
- ITextViewer viewer = getTextViewer();
- if (viewer != null)
- updateColor(viewer);
- } else if (event.getProperty().equals(fBrowserLikeLinksKeyModifierKey)) {
- updateKeyModifierMask();
- }
- }
-
- private void repairRepresentation() {
- repairRepresentation(false);
- }
-
- private void repairRepresentation(boolean redrawAll) {
-
- if (fActiveRegion == null)
- return;
-
- int offset = fActiveRegion.getOffset();
- int length = fActiveRegion.getLength();
- fActiveRegion = null;
-
- ITextViewer viewer = getTextViewer();
- if (viewer != null) {
-
- resetCursor(viewer);
-
- // Remove underline
- if (viewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
- offset = extension.modelOffset2WidgetOffset(offset);
- } else {
- offset -= viewer.getVisibleRegion().getOffset();
- }
- try {
- StyledText text = viewer.getTextWidget();
-
- // need clearBackground to be true for paint event to be fired
- text.redrawRange(offset, length, true);
- } catch (IllegalArgumentException x) {
- Logger.logException(x);
- }
- }
- }
-
- private void resetCursor(ITextViewer viewer) {
- StyledText text = viewer.getTextWidget();
- if (text != null && !text.isDisposed())
- text.setCursor(null);
-
- if (fCursor != null) {
- fCursor.dispose();
- fCursor = null;
- }
- }
-
- public void setHyperlinkPreferenceKeys(String linkColorKey, String browserLikeLinksKeyModifierKey) {
- fLinkColorKey = linkColorKey;
- fBrowserLikeLinksKeyModifierKey = browserLikeLinksKeyModifierKey;
- }
-
- public void uninstall() {
- if (fCursor != null) {
- fCursor.dispose();
- fCursor = null;
- }
-
- ITextViewer textViewer = getTextViewer();
- if (textViewer == null)
- return;
-
- textViewer.removeTextInputListener(this);
-
- IDocument document = textViewer.getDocument();
- if (document != null)
- document.removeDocumentListener(this);
-
- IPreferenceStore preferenceStore = getNewPreferenceStore();
- if (preferenceStore != null)
- preferenceStore.removePropertyChangeListener(this);
-
- StyledText text = textViewer.getTextWidget();
- if (text == null || text.isDisposed())
- return;
-
- text.removeKeyListener(this);
- text.removeMouseListener(this);
- text.removeMouseMoveListener(this);
- text.removeFocusListener(this);
- text.removePaintListener(this);
- }
-
- private void updateColor(ITextViewer viewer) {
- StyledText text = viewer.getTextWidget();
- if (text == null || text.isDisposed())
- return;
-
- Display display = text.getDisplay();
- fColor = createColor(getNewPreferenceStore(), fLinkColorKey, display);
- }
-
- private void updateKeyModifierMask() {
- String modifiers = getNewPreferenceStore().getString(fBrowserLikeLinksKeyModifierKey);
- fKeyModifierMask = computeStateMask(modifiers);
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnAction.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnAction.java
deleted file mode 100644
index 44487875fa..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnAction.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import java.util.ResourceBundle;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.TextEditorAction;
-import org.eclipse.wst.sse.ui.internal.IExtendedSimpleEditor;
-import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
-
-
-/**
- * Determines the appropriate IOpenFileAction to call based on current
- * partition.
- *
- * @deprecated Use base support for hyperlink navigation
- */
-public class OpenOnAction extends TextEditorAction {
- public OpenOnAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
- super(bundle, prefix, editor);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.IAction#run()
- */
- public void run() {
- BusyIndicator.showWhile(getTextEditor().getEditorSite().getShell().getDisplay(), new Runnable() {
- public void run() {
- ITextEditor editor = getTextEditor();
-
- // figure out current offset
- int offset = -1;
- ISourceEditingTextTools textTools = (ISourceEditingTextTools) getTextEditor().getAdapter(ISourceEditingTextTools.class);
- if (textTools != null) {
- offset = textTools.getCaretOffset();
- }
- else if (editor instanceof IExtendedSimpleEditor) {
- offset = ((IExtendedSimpleEditor) editor).getCaretPosition();
- }
- else {
- if (editor.getSelectionProvider() != null) {
- ISelection sel = editor.getSelectionProvider().getSelection();
- if (sel instanceof ITextSelection) {
- offset = ((ITextSelection) sel).getOffset();
- }
- }
- }
- IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
- IOpenOn openOn = OpenOnProvider.getInstance().getOpenOn(document, offset);
- if (openOn != null) {
- openOn.openOn(document, new Region(offset, 0));
- }
- }
- });
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnBuilder.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnBuilder.java
deleted file mode 100644
index b62de63f8f..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnBuilder.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.wst.sse.ui.internal.extension.RegistryReader;
-
-
-/**
- * Reads extensions for open on extension point,
- * org.eclipse.wst.sse.ui.extensions.openon
- *
- * @deprecated Use base support for hyperlink navigation
- */
-public class OpenOnBuilder extends RegistryReader {
- public static final String ATT_CLASS = "class"; //$NON-NLS-1$
-
- public static final String ATT_ID = "id"; //$NON-NLS-1$
-
- private static OpenOnBuilder fInstance;
- // extension point ID
- public static final String PL_OPENON = "openon"; //$NON-NLS-1$
-
- public static final String PLUGIN_ID = "org.eclipse.wst.sse.ui"; //$NON-NLS-1$
- public static final String TAG_CONTENT_TYPE_IDENTIFIER = "contenttypeidentifier"; //$NON-NLS-1$
-
- public static final String TAG_OPENON = "openon"; //$NON-NLS-1$
- public static final String TAG_PARTITION_TYPE = "partitiontype"; //$NON-NLS-1$
-
- /**
- * returns singleton instance of OpenOnBuilder
- *
- * @return OpenOnBuilder
- */
- public synchronized static OpenOnBuilder getInstance() {
- if (fInstance == null) {
- fInstance = new OpenOnBuilder();
- }
- return fInstance;
- }
-
- private String fCurrentContentType;
- private OpenOnDefinition fCurrentOpenOnDefinition = null;
-
- private List fOpenOnDefs = null;
-
- protected String targetContributionTag;
-
- /**
- * Returns the name of the part ID attribute that is expected in the
- * target extension.
- *
- * @param element
- * @return String
- */
- protected String getId(IConfigurationElement element) {
- String value = element.getAttribute(ATT_ID);
- return value;
- }
-
- protected String getOpenOnClass(IConfigurationElement element) {
- String value = element.getAttribute(ATT_CLASS);
- return value;
- }
-
- /**
- * Returns all the open on definition objects
- *
- * @return
- */
- public OpenOnDefinition[] getOpenOnDefinitions() {
- initCache();
- return (OpenOnDefinition[]) fOpenOnDefs.toArray(new OpenOnDefinition[fOpenOnDefs.size()]);
- }
-
- /**
- * Returns all the open on definition objects valid for
- * contentType/partitionType
- *
- * @param contentType
- * @param partitionType
- * @return if either contentType or partitionType is null, null is
- * returned
- */
- public OpenOnDefinition[] getOpenOnDefinitions(String contentType, String partitionType) {
- if (contentType == null || partitionType == null) {
- // should not be able to define an openon without a content type
- // but if it were possible then would need to search all openon
- // definitions for
- // definitions with empty contentType list
- return null;
- }
-
- // entire list of openon definition objects
- OpenOnDefinition[] allDefs = getOpenOnDefinitions();
- // current list of open on definitions valid for
- // contentType/partitionType
- List defs = new ArrayList();
- // default definitions that should be added to end of list of open on
- // definitions
- List lastDefs = new ArrayList();
-
- for (int i = 0; i < allDefs.length; ++i) {
- // for each one check if it contains contentType
- List partitions = (List) allDefs[i].getContentTypes().get(contentType);
- if (partitions != null) {
- // this openon definition is valid for all partition types for
- // this content type
- if (partitions.isEmpty()) {
- // this will be added to end of list because this is
- // considered a default openon
- lastDefs.add(allDefs[i]);
- } else {
- // examine the partition types of this openon
- int j = 0; // current index in list of partitions
- boolean added = false; // openon has been added to list
- while (j < partitions.size() && !added) {
- // this openon definition applies to partitionType so
- // add to list of valid openons
- if (partitionType.equals(partitions.get(j))) {
- defs.add(allDefs[i]);
- added = true;
- } else {
- // continue checking to see if this openon
- // definition is valid for current partitionType
- ++j;
- }
- }
- }
- }
- }
- // append the default openon definitions
- defs.addAll(lastDefs);
-
- // return the list
- return (OpenOnDefinition[]) defs.toArray(new OpenOnDefinition[defs.size()]);
- }
-
- private void initCache() {
- if (fOpenOnDefs == null) {
- fOpenOnDefs = new ArrayList(0);
- readContributions(TAG_OPENON, PL_OPENON);
- }
- }
-
- /**
- * Processes element which should be a configuration element specifying a
- * content type for the current open on tag. Assumes that there is a valid
- * current open on definition object.
- *
- * @param element
- * contenttypeidentifier configuration element
- */
- private void processContentTypeTag(IConfigurationElement element) {
- // add to current openOnDefinition
- String theId = getId(element);
-
- if (theId != null) {
- fCurrentContentType = theId;
- fCurrentOpenOnDefinition.addContentTypeId(fCurrentContentType);
- } else {
- fCurrentContentType = null;
- }
- }
-
- /**
- * Processes element which should be a configuration element specifying an
- * open on object. Creates a new open on definition object and adds it to
- * the list of open on definition objects
- *
- * @param element
- * openon configuration element
- */
- private void processOpenOnTag(IConfigurationElement element) {
- String theId = getId(element);
- String theClass = getOpenOnClass(element);
-
- if (theId != null && theClass != null) {
- // start building new OpenOnDefinition
- fCurrentOpenOnDefinition = new OpenOnDefinition(theId, theClass, element);
- fOpenOnDefs.add(fCurrentOpenOnDefinition);
- } else {
- fCurrentOpenOnDefinition = null;
- }
- }
-
- /**
- * Processes element which should be a configuration element specifying a
- * partition type for the current open on/content type tag. Assumes that
- * there is a valid current open on/content type tag.
- *
- * @param element
- * partitiontype configuration element
- */
- private void processPartitionTypeTag(IConfigurationElement element) {
- // add to current openOnDefinition/contentType
- String theId = getId(element);
-
- if (theId != null) {
- fCurrentOpenOnDefinition.addPartitionType(fCurrentContentType, theId);
- }
- }
-
- /**
- * Reads the contributions from the registry for the provided workbench
- * part and the provided extension point ID.
- *
- * @param tag
- * @param extensionPoint
- */
- protected void readContributions(String tag, String extensionPoint) {
- targetContributionTag = tag;
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- readRegistry(registry, PLUGIN_ID, extensionPoint);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.internal.extension.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
- */
- protected boolean readElement(IConfigurationElement element) {
- String tag = element.getName();
-
- if (tag.equals(targetContributionTag)) {
- processOpenOnTag(element);
-
- // make sure processing of current open on tag resulted in a
- // current open on definition
- // before continue reading the children
- if (fCurrentOpenOnDefinition != null) {
- readElementChildren(element);
- }
- return true;
- } else if (tag.equals(TAG_CONTENT_TYPE_IDENTIFIER)) {
- processContentTypeTag(element);
-
- // make sure processing of current content type resulted in a
- // valid content type
- // before reading the children
- if (fCurrentContentType != null) {
- readElementChildren(element);
- }
- return true;
- } else if (tag.equals(TAG_PARTITION_TYPE)) {
- processPartitionTypeTag(element);
- return true;
- }
-
- return false;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnDefinition.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnDefinition.java
deleted file mode 100644
index e69159e95f..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnDefinition.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.wst.sse.ui.internal.Logger;
-import org.osgi.framework.Bundle;
-
-
-/**
- * Open on definition object
- *
- * @deprecated Use base support for hyperlink navigation
- */
-public class OpenOnDefinition {
- private String fClassName = null;
-
- private IConfigurationElement fConfigurationElement = null;
-
- // a hash map of content type Ids (String) that points to lists of
- // parition types (List of Strings)
- // contentTypeId -> List(paritionType, paritionType, partitionType, ...)
- // contentTypeId2 -> List(partitionType, partitionType, ...)
- // ...
- private HashMap fContentTypes = null;
- private String fId = null;
-
- /**
- * @param id
- * @param class1
- * @param configurationElement
- */
- public OpenOnDefinition(String id, String class1, IConfigurationElement configurationElement) {
- super();
- fId = id;
- fClassName = class1;
- fConfigurationElement = configurationElement;
- fContentTypes = new HashMap();
- }
-
- public void addContentTypeId(String contentTypeId) {
- if (!fContentTypes.containsKey(contentTypeId))
- fContentTypes.put(contentTypeId, new ArrayList());
- }
-
- public void addPartitionType(String contentTypeId, String partitionType) {
- if (!fContentTypes.containsKey(contentTypeId))
- fContentTypes.put(contentTypeId, new ArrayList());
-
- List partitionList = (List) fContentTypes.get(contentTypeId);
- partitionList.add(partitionType);
- }
-
- /**
- * Creates an extension. If the extension plugin has not been loaded a
- * busy cursor will be activated during the duration of the load.
- *
- * @param propertyName
- * @return Object
- */
- private Object createExtension(String propertyName) {
- // If plugin has been loaded create extension.
- // Otherwise, show busy cursor then create extension.
- final IConfigurationElement element = getConfigurationElement();
- final String name = propertyName;
-
- final Object[] result = new Object[1];
- String pluginId = element.getDeclaringExtension().getNamespace();
- Bundle bundle = Platform.getBundle(pluginId);
- if (bundle.getState() == Bundle.ACTIVE) {
- try {
- return element.createExecutableExtension(name);
- } catch (CoreException e) {
- handleCreateExecutableException(result, e);
- }
- } else {
- BusyIndicator.showWhile(null, new Runnable() {
- public void run() {
- try {
- result[0] = element.createExecutableExtension(name);
- } catch (Exception e) {
- handleCreateExecutableException(result, e);
- }
- }
- });
- }
- return result[0];
- }
-
- /**
- * @return IOpenOn for this definition
- */
- public IOpenOn createOpenOn() {
- IOpenOn openOn = null;
-
- if (getClassName() != null) {
- openOn = (IOpenOn) createExtension(OpenOnBuilder.ATT_CLASS);
- }
-
- return openOn;
- }
-
- /**
- * @return Returns the fClass.
- */
- public String getClassName() {
- return fClassName;
- }
-
- /**
- * @return Returns the fConfigurationElement.
- */
- public IConfigurationElement getConfigurationElement() {
- return fConfigurationElement;
- }
-
- /**
- * @return Returns the fContentTypes.
- */
- public HashMap getContentTypes() {
- return fContentTypes;
- }
-
- /**
- * @return Returns the fId.
- */
- public String getId() {
- return fId;
- }
-
- /**
- * @param result
- * @param e
- */
- private void handleCreateExecutableException(Object[] result, Throwable e) {
- Logger.logException("Unable to create open on: " + getId(), e); //$NON-NLS-1$
- e.printStackTrace();
- result[0] = null;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnProvider.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnProvider.java
deleted file mode 100644
index 46d90b93d3..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/openon/OpenOnProvider.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.openon;
-
-
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;
-
-
-/**
- * Determines the appropriate IOpenOn to call based on current partition.
- *
- * @deprecated Use base support for hyperlink navigation
- */
-public class OpenOnProvider {
- private static OpenOnProvider fInstance;
-
- /**
- * returns singleton instance of OpenOnProvider
- *
- * @return OpenOnProvider
- */
- public synchronized static OpenOnProvider getInstance() {
- if (fInstance == null) {
- fInstance = new OpenOnProvider();
- }
- return fInstance;
- }
-
-
- /**
- * Returns the content type of document
- *
- * @param document -
- * assumes document is not null
- * @return String content type of given document
- */
- protected String getContentType(IDocument document) {
- String type = null;
-
- IModelManager mgr = StructuredModelManager.getModelManager();
- IStructuredModel model = null;
- try {
- model = mgr.getExistingModelForRead(document);
- if (model != null) {
- type = model.getContentTypeIdentifier();
- }
- }
- finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- return type;
- }
-
- /**
- * Returns the appropriate IOpenOn for the current partition
- *
- * @return
- */
- public IOpenOn getOpenOn(IDocument document, int offset) {
- IOpenOn openOn = null;
-
- // determine the current partition
- if (document != null) {
- String contentTypeID = getContentType(document);
- String partitionType = getPartitionType(document, offset);
-
- IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeID);
-
- while (openOn == null && contentType != null) {
- // Query OpenOnBuilder and get the list of OpenOns for the
- // current partition
- OpenOnDefinition[] defs = OpenOnBuilder.getInstance().getOpenOnDefinitions(contentType.getId(), partitionType);
- contentType = contentType.getBaseType();
-
- // If more than 1 openon is returned, need to further check
- // which OpenOn is the appropriate one to return
- // for now just returning the first one
- if (defs != null && defs.length > 0) {
- openOn = defs[0].createOpenOn();
- }
- }
- }
-
- return openOn;
- }
-
- /**
- * Returns the partition type located at offset in the document
- *
- * @param document -
- * assumes document is not null
- * @param offset
- * @return String partition type
- */
- protected String getPartitionType(IDocument document, int offset) {
- String type = null;
- try {
- // TODO: provide partitioning information so we're not using a default like this
- if (document instanceof IStructuredDocument) {
- type = TextUtilities.getContentType(document, IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, offset, false);
- }
- }
- catch (BadLocationException e1) {
- }
- finally {
- if (type == null) {
- try {
- ITypedRegion region = document.getPartition(offset);
- if (region != null) {
- type = region.getType();
- }
- }
- catch (BadLocationException e) {
- type = null;
- }
- }
- }
- return type;
- }
-}

Back to the top