Skip to content

Commit 69d3203

Browse files
eharris369GitHub Enterprise
authored andcommitted
Merge pull request #195 from eharris/194-addOpenMicroclimateUIAction
Issue #194: Add open Microclimate UI action
2 parents e160f68 + 5d263df commit 69d3203

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

dev/com.ibm.microclimate.ui/plugin.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ACTION_REFRESH=Re&fresh
2525
ACTION_RESTART_RUN_MODE=Restart in &Run Mode
2626
ACTION_RESTART_DEBUG_MODE=Restart in &Debug Mode
2727
ACTION_ENABLE_DISABLE_AUTO_BUILD=Disable &Auto Build
28+
ACTION_OPEN_MICROCLIMATE_UI=Open &Microclimate UI
2829

2930
PREFS_PARENT_PAGE_NAME=Microclimate
3031
PREFS_CONNECTION_PAGE_NAME=Microclimate Connections

dev/com.ibm.microclimate.ui/plugin.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@
194194
icon="%REFRESH_ICON_PATH"
195195
label="%ACTION_REFRESH"
196196
class="com.ibm.microclimate.ui.internal.actions.RefreshAction"/>
197+
<action
198+
id="com.ibm.microclimate.ui.openMicroclimateUI"
199+
enablesFor="1"
200+
menubarPath="group.new"
201+
label="%ACTION_OPEN_MICROCLIMATE_UI"
202+
class="com.ibm.microclimate.ui.internal.actions.OpenMicroclimateUIAction"/>
197203
</objectContribution>
198204
</extension>
199205

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*******************************************************************************
2+
* IBM Confidential
3+
* OCO Source Materials
4+
* (C) Copyright IBM Corp. 2018 All Rights Reserved.
5+
* The source code for this program is not published or otherwise
6+
* divested of its trade secrets, irrespective of what has
7+
* been deposited with the U.S. Copyright Office.
8+
*******************************************************************************/
9+
10+
package com.ibm.microclimate.ui.internal.actions;
11+
12+
import java.net.URI;
13+
14+
import org.eclipse.jface.action.IAction;
15+
import org.eclipse.jface.viewers.ISelection;
16+
import org.eclipse.jface.viewers.IStructuredSelection;
17+
import org.eclipse.osgi.util.NLS;
18+
import org.eclipse.ui.IObjectActionDelegate;
19+
import org.eclipse.ui.IWorkbenchPart;
20+
import org.eclipse.ui.PlatformUI;
21+
import org.eclipse.ui.browser.IWebBrowser;
22+
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
23+
24+
import com.ibm.microclimate.core.internal.MCLogger;
25+
import com.ibm.microclimate.core.internal.MCUtil;
26+
import com.ibm.microclimate.core.internal.connection.MicroclimateConnection;
27+
import com.ibm.microclimate.ui.internal.messages.Messages;
28+
29+
public class OpenMicroclimateUIAction implements IObjectActionDelegate {
30+
31+
protected MicroclimateConnection connection;
32+
33+
@Override
34+
public void selectionChanged(IAction action, ISelection selection) {
35+
if (!(selection instanceof IStructuredSelection)) {
36+
action.setEnabled(false);
37+
return;
38+
}
39+
40+
IStructuredSelection sel = (IStructuredSelection) selection;
41+
if (sel.size() == 1) {
42+
Object obj = sel.getFirstElement();
43+
if (obj instanceof MicroclimateConnection) {
44+
connection = (MicroclimateConnection)obj;
45+
action.setEnabled(connection.isConnected());
46+
return;
47+
}
48+
}
49+
action.setEnabled(false);
50+
}
51+
52+
@Override
53+
public void run(IAction action) {
54+
if (connection == null) {
55+
// should not be possible
56+
MCLogger.logError("Open Microclimate UI action ran but no Microclimate connection was selected");
57+
return;
58+
}
59+
60+
if (!connection.isConnected()) {
61+
MCUtil.openDialog(true, Messages.OpenMicroclimateUIError,
62+
NLS.bind(Messages.OpenMicroclimateUINotConnectedError, connection.baseUrl));
63+
return;
64+
}
65+
66+
URI uri = connection.baseUrl;
67+
68+
try {
69+
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
70+
IWebBrowser browser = browserSupport
71+
.createBrowser(IWorkbenchBrowserSupport.NAVIGATION_BAR | IWorkbenchBrowserSupport.LOCATION_BAR,
72+
uri.toString(), uri.toString(), "Microclimate UI - " + uri);
73+
74+
browser.openURL(uri.toURL());
75+
} catch (Exception e) {
76+
MCLogger.logError("Error opening Microclimate UI in browser", e); //$NON-NLS-1$
77+
}
78+
}
79+
80+
@Override
81+
public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
82+
// nothing
83+
}
84+
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public class Messages extends NLS {
6464

6565
public static String ImportProjectError;
6666
public static String StartBuildError;
67+
public static String OpenMicroclimateUIError;
68+
public static String OpenMicroclimateUINotConnectedError;
6769

6870
static {
6971
// initialize resource bundle

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ RefreshResourceError=An error occurred while trying to refresh the {0} resource.
5757

5858
ImportProjectError=An error occurred while importing the {0} project.
5959
StartBuildError=An error occurred while starting a build for the {0} project.
60+
OpenMicroclimateUIError=An error occurred while opening the Microclimate UI.
61+
OpenMicroclimateUINotConnectedError=The Microclimate UI could not be reached at {0}. Check that Microclimate is running.

0 commit comments

Comments
 (0)