~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/SpecfileElementHyperlink.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2008 Alexander Kurtakov.
 
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
 *    Alexander Kurtakov - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink;
 
12
 
 
13
import java.util.HashMap;
 
14
 
 
15
import org.eclipse.core.resources.IFile;
 
16
import org.eclipse.core.resources.IMarker;
 
17
import org.eclipse.core.runtime.CoreException;
 
18
import org.eclipse.jface.text.IRegion;
 
19
import org.eclipse.jface.text.hyperlink.IHyperlink;
 
20
import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog;
 
21
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement;
 
22
import org.eclipse.ui.IEditorDescriptor;
 
23
import org.eclipse.ui.IWorkbenchPage;
 
24
import org.eclipse.ui.PlatformUI;
 
25
import org.eclipse.ui.ide.IDE;
 
26
 
 
27
/**
 
28
 * Hyperlink implementation for the following hyperlink elements: SOURCE, PATCH
 
29
 * and %define.
 
30
 */
 
31
public class SpecfileElementHyperlink implements IHyperlink {
 
32
        private IRegion region;
 
33
        private SpecfileElement source;
 
34
        private IFile file;
 
35
 
 
36
        public SpecfileElementHyperlink(IRegion region, SpecfileElement source,
 
37
                        IFile file) {
 
38
                this.region = region;
 
39
                this.source = source;
 
40
                this.file = file;
 
41
        }
 
42
 
 
43
        public IRegion getHyperlinkRegion() {
 
44
                return region;
 
45
        }
 
46
 
 
47
        public String getHyperlinkText() {
 
48
                return null;
 
49
        }
 
50
 
 
51
        public String getTypeLabel() {
 
52
                return null;
 
53
        }
 
54
 
 
55
        public void open() {
 
56
                IWorkbenchPage page = PlatformUI.getWorkbench()
 
57
                                .getActiveWorkbenchWindow().getActivePage();
 
58
                IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry()
 
59
                                .getDefaultEditor(file.getName());
 
60
                HashMap<String, Object> map = new HashMap<String, Object>();
 
61
                // TODO don't increment the line number once the SpecfileSource reports
 
62
                // correct line
 
63
                map.put(IMarker.LINE_NUMBER, Integer
 
64
                                .valueOf(getSource().getLineNumber() + 1));
 
65
                map.put(IDE.EDITOR_ID_ATTR, desc.getId());
 
66
                try {
 
67
                        IMarker marker = file.createMarker(IMarker.TEXT);
 
68
                        marker.setAttributes(map);
 
69
                        IDE.openEditor(page, marker);
 
70
                        marker.delete();
 
71
                } catch (CoreException e) {
 
72
                        SpecfileLog.logError(e);
 
73
                }
 
74
        }
 
75
 
 
76
        /**
 
77
         * @return the source
 
78
         */
 
79
        public SpecfileElement getSource() {
 
80
                return source;
 
81
        }
 
82
 
 
83
}