]> git.uio.no Git - ifi-stolz-refaktor.git/blobdiff - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlink.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / javaeditor / JavaElementHyperlink.java
diff --git a/case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlink.java b/case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlink.java
new file mode 100644 (file)
index 0000000..70f1752
--- /dev/null
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.javaeditor;
+
+import org.eclipse.core.runtime.Assert;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+
+import org.eclipse.jdt.core.IJavaElement;
+
+import org.eclipse.jdt.internal.corext.util.Messages;
+
+import org.eclipse.jdt.ui.JavaElementLabels;
+import org.eclipse.jdt.ui.actions.OpenAction;
+import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
+
+
+/**
+ * Java element hyperlink.
+ *
+ * @since 3.1
+ */
+public class JavaElementHyperlink implements IHyperlink {
+
+       public final IRegion fRegion;
+       public final SelectionDispatchAction fOpenAction;
+       public final IJavaElement fElement;
+       private final boolean fQualify;
+
+
+       /**
+        * Creates a new Java element hyperlink.
+        * 
+        * @param region the region of the link
+        * @param openAction the action to use to open the java elements
+        * @param element the java element to open or <code>null</code> if {@link OpenAction} should be
+        *            invoked at the given region
+        * @param qualify <code>true</code> if the hyperlink text should show a qualified name for
+        *            element
+        */
+       public JavaElementHyperlink(IRegion region, SelectionDispatchAction openAction, IJavaElement element, boolean qualify) {
+               Assert.isNotNull(openAction);
+               Assert.isNotNull(region);
+
+               fRegion= region;
+               fOpenAction= openAction;
+               fElement= element;
+               fQualify= qualify;
+       }
+
+       /*
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkRegion()
+        * @since 3.1
+        */
+       public IRegion getHyperlinkRegion() {
+               return fRegion;
+       }
+
+       /*
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#open()
+        * @since 3.1
+        */
+       public void open() {
+               fOpenAction.generated_1557947178182620328(this);
+       }
+
+       /*
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getTypeLabel()
+        * @since 3.1
+        */
+       public String getTypeLabel() {
+               return null;
+       }
+
+       /*
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkText()
+        * @since 3.1
+        */
+       public String getHyperlinkText() {
+               if (fQualify && fElement != null) {
+                       String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_POST_QUALIFIED);
+                       return Messages.format(JavaEditorMessages.JavaElementHyperlink_hyperlinkText_qualified, new Object[] { elementLabel });
+               } else {
+                       return JavaEditorMessages.JavaElementHyperlink_hyperlinkText;
+               }
+       }
+}