blob: 3a35c167fa3a2268cd631f015fe98a12bc7abc5e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/****************************************************************************
* Copyright (c) 2007 Composent, Inc. 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:
* Composent, Inc. - initial API and implementation
*****************************************************************************/
package org.eclipse.ecf.example.collab.share;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.ecf.example.collab.share.EclipseCollabHyperlinkDetector.Selection;
import org.eclipse.ecf.internal.example.collab.ClientPlugin;
import org.eclipse.ecf.internal.example.collab.ui.EditorHelper;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
*
*/
public class EclipseCollabHyperlink implements IHyperlink {
private final IRegion region;
private final String fileName;
private final Selection selection;
/**
* @param detectedRegion
* @param fileName
* @param selection
*/
public EclipseCollabHyperlink(IRegion detectedRegion, String fileName, Selection selection) {
this.region = detectedRegion;
this.fileName = fileName;
this.selection = selection;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion()
*/
public IRegion getHyperlinkRegion() {
return region;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText()
*/
public String getHyperlinkText() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel()
*/
public String getTypeLabel() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
*/
public void open() {
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchWindow ww = wb.getActiveWorkbenchWindow();
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName));
if (file != null) {
final EditorHelper eh = new EditorHelper(ww);
try {
eh.openAndSelectForFile(file, (selection == null) ? 0 : selection.getStart(), (selection == null) ? 0 : (selection.getEnd() - selection.getStart()));
} catch (final Exception e) {
ClientPlugin.log("Exception in openEditorAndSelectForFile", e);
}
} else {
MessageDialog.openInformation(ww.getShell(), "Open Editor Failed", NLS.bind("Cannot open editor for {0}. It was not found in your workspace.", fileName));
}
}
}
|