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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.results.html;
import java.net.URL;
import java.util.regex.Pattern;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.osee.framework.ui.skynet.cm.OseeCm;
import org.eclipse.osee.framework.ui.skynet.cm.OseeCmEditor;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.skynet.render.RendererManager;
import org.eclipse.osee.framework.ui.skynet.widgets.xBranch.BranchView;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
/**
* @author Donald G. Dunne
*/
public class XResultBrowserListener implements LocationListener {
public XResultBrowserListener() {
super();
}
@Override
public void changing(LocationEvent event) {
try {
String location = event.location;
if (location.contains("javascript:print")) {
return;
}
String cmdStr = location.replaceFirst("about:blank", "");
cmdStr = cmdStr.replaceFirst("blank", "");
XResultBrowserHyperCmd xResultBrowserHyperCmd = XResultBrowserHyperCmd.getCmdStrHyperCmd(cmdStr);
String value = XResultBrowserHyperCmd.getCmdStrValue(cmdStr);
switch (xResultBrowserHyperCmd) {
case openAction:
event.doit = false;
openArtifact(value, OseeCmEditor.CmPcrEditor);
break;
case openArtifactBranch:
event.doit = false;
try {
java.util.regex.Matcher m = Pattern.compile("^(.*?)\\((.*?)\\)$").matcher(value);
if (m.find()) {
String hrid = m.group(1);
Integer branchId = Integer.parseInt(m.group(2));
Artifact artifact = ArtifactQuery.getArtifactFromId(hrid, BranchManager.getBranch(branchId));
RendererManager.openInJob(artifact, PresentationType.DEFAULT_OPEN);
}
} catch (Exception ex) {
OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
}
break;
case openArtifactEditor:
event.doit = false;
openArtifact(value, OseeCmEditor.ArtifactEditor);
break;
case openBranch:
event.doit = false;
int branchId = new Integer(value);
Branch branch = BranchManager.getBranch(branchId);
BranchView.revealBranch(branch);
break;
case browserInternal:
event.doit = false;
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
try {
IWebBrowser browser = browserSupport.createBrowser("osee.ats.navigator.browser");
browser.openURL(new URL(value));
} catch (Exception ex) {
OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
}
break;
case browserExternal:
event.doit = false;
Program.launch(value);
break;
default:
break;
}
} catch (Exception ex) {
OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, "Can't process hyperlink.", ex);
}
}
private void openArtifact(String guid, OseeCmEditor view) {
OseeCm.getInstance().openArtifact(guid, view);
}
@Override
public void changed(LocationEvent event) {
// do nothing
}
}
|