]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.propertiesfileeditor; | |
12 | ||
13 | import org.eclipse.jface.text.IRegion; | |
14 | import org.eclipse.jface.text.ITextSelection; | |
15 | import org.eclipse.jface.text.Region; | |
16 | import org.eclipse.jface.text.hyperlink.IHyperlink; | |
17 | ||
18 | import org.eclipse.ui.IFileEditorInput; | |
19 | ||
20 | import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; | |
21 | import org.eclipse.jdt.ui.actions.JdtActionConstants; | |
22 | import org.eclipse.jdt.ui.actions.SelectionDispatchAction; | |
23 | ||
24 | /** | |
25 | * This action opens a tool (internal editor or view or an external application) for the element at | |
26 | * the given location. | |
27 | * <p> | |
28 | * XXX: This does not work for properties files coming from a JAR due to missing J Core | |
29 | * functionality. For details see http://bugs.eclipse.org/22376 | |
30 | * </p> | |
31 | * <p> | |
32 | * This class may be instantiated; it is not intended to be subclassed. | |
33 | * </p> | |
34 | * | |
35 | * @since 3.1 | |
36 | */ | |
37 | public class OpenAction extends SelectionDispatchAction { | |
38 | ||
39 | ||
40 | private PropertiesFileEditor fEditor; | |
41 | ||
42 | ||
43 | /** | |
44 | * Creates a new <code>OpenAction</code>. | |
45 | * | |
46 | * @param editor the Properties file editor which provides the context information for this action | |
47 | */ | |
48 | public OpenAction(PropertiesFileEditor editor) { | |
49 | super(editor.getEditorSite()); | |
50 | fEditor= editor; | |
51 | setText(PropertiesFileEditorMessages.OpenAction_label); | |
52 | setToolTipText(PropertiesFileEditorMessages.OpenAction_tooltip); | |
53 | ||
54 | // XXX: Must be removed once support for JARs is available (see class Javadoc for details). | |
55 | setEnabled(fEditor.getEditorInput() instanceof IFileEditorInput); | |
56 | } | |
57 | ||
58 | /* | |
59 | * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.text.ITextSelection) | |
60 | */ | |
61 | @Override | |
62 | public void selectionChanged(ITextSelection selection) { | |
63 | setEnabled(checkEnabled(selection)); | |
64 | } | |
65 | ||
66 | private boolean checkEnabled(ITextSelection selection) { | |
67 | if (selection == null || selection.isEmpty()) | |
68 | return false; | |
69 | ||
70 | // XXX: Must be changed to IStorageEditorInput once support for JARs is available (see class Javadoc for details) | |
71 | return fEditor.getEditorInput() instanceof IFileEditorInput; | |
72 | } | |
73 | ||
74 | @Override | |
75 | public void run(ITextSelection selection) { | |
76 | ||
77 | if (!checkEnabled(selection)) | |
78 | return; | |
79 | ||
80 | IRegion region= new Region(selection.getOffset(), selection.getLength()); | |
81 | PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector(); | |
82 | detector.setContext(fEditor); | |
83 | IHyperlink[]hyperlinks= detector.detectHyperlinks(fEditor.internalGetSourceViewer(), region, false); | |
84 | ||
85 | if (hyperlinks != null && hyperlinks.length == 1) | |
86 | hyperlinks[0].open(); | |
87 | ||
88 | } | |
89 | ||
90 | public void generated_2733244627394025914(PropertiesFileEditor propertiesfileeditor) { | |
91 | setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR); | |
92 | propertiesfileeditor.setAction(JdtActionConstants.OPEN, this); | |
93 | } | |
94 | } |