diff options
author | afinkbein | 2008-09-26 16:59:27 +0000 |
---|---|---|
committer | afinkbein | 2008-09-26 16:59:27 +0000 |
commit | 14ffbb8203441fd8c540b3b08ca4a6a2c45873b5 (patch) | |
tree | 4f8b5b4b99061316eb132eac68bdcc91a6488eb2 | |
parent | c4e59461791173b0c633be835bf295602049a4de (diff) | |
download | org.eclipse.osee-14ffbb8203441fd8c540b3b08ca4a6a2c45873b5.tar.gz org.eclipse.osee-14ffbb8203441fd8c540b3b08ca4a6a2c45873b5.tar.xz org.eclipse.osee-14ffbb8203441fd8c540b3b08ca4a6a2c45873b5.zip |
88 files changed, 7957 insertions, 0 deletions
diff --git a/org.eclipse.osee.framework.ui.service.control/.classpath b/org.eclipse.osee.framework.ui.service.control/.classpath new file mode 100644 index 00000000000..02159672985 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.osee.framework.ui.service.control/.project b/org.eclipse.osee.framework.ui.service.control/.project new file mode 100644 index 00000000000..7da41abf787 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.framework.ui.service.control</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.osee.framework.ui.service.control/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.osee.framework.ui.service.control/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..7353765a435 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Fri Mar 28 14:02:26 GMT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.eclipse.osee.framework.ui.service.control/META-INF/MANIFEST.MF b/org.eclipse.osee.framework.ui.service.control/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..6c6fd3cf4c4 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/META-INF/MANIFEST.MF @@ -0,0 +1,35 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Control Plug-in (Incubation) +Bundle-SymbolicName: org.eclipse.osee.framework.ui.service.control;singleton:=true +Bundle-Version: 0.4.0.qualifier +Bundle-Activator: org.eclipse.osee.framework.ui.service.control.ControlPlugin +Bundle-Vendor: Eclipse.org +Export-Package: org.eclipse.osee.framework.ui.service.control, + org.eclipse.osee.framework.ui.service.control.actions, + org.eclipse.osee.framework.ui.service.control.data, + org.eclipse.osee.framework.ui.service.control.dialogs, + org.eclipse.osee.framework.ui.service.control.jobs, + org.eclipse.osee.framework.ui.service.control.managers, + org.eclipse.osee.framework.ui.service.control.managers.interfaces, + org.eclipse.osee.framework.ui.service.control.menu, + org.eclipse.osee.framework.ui.service.control.renderer, + org.eclipse.osee.framework.ui.service.control.view, + org.eclipse.osee.framework.ui.service.control.widgets, + org.eclipse.osee.framework.ui.service.control.wizards.launcher, + org.eclipse.osee.framework.ui.service.control.wizards.launcher.data, + org.eclipse.osee.framework.ui.service.control.wizards.launcher.pages, + org.eclipse.osee.framework.ui.service.control.wizards.launcher.widgets +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.osee.framework.jdk.core, + net.jini, + org.eclipse.osee.framework.skynet.core, + org.eclipse.osee.framework.ui.skynet, + org.eclipse.osee.framework.jini, + org.eclipse.osee.framework.ui.plugin, + org.eclipse.osee.framework.plugin.core, + org.eclipse.osee.framework.ui.swt, + com.jcraft.jsch +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/org.eclipse.osee.framework.ui.service.control/build.properties b/org.eclipse.osee.framework.ui.service.control/build.properties new file mode 100644 index 00000000000..1689971d494 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/build.properties @@ -0,0 +1,7 @@ +bin.includes = plugin.xml,\
+ images/,\
+ META-INF/,\
+ .
+jars.compile.order = .
+source.. = src/
+output.. = bin/
diff --git a/org.eclipse.osee.framework.ui.service.control/images/annotate.gif b/org.eclipse.osee.framework.ui.service.control/images/annotate.gif Binary files differnew file mode 100644 index 00000000000..40afd5bfda4 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/annotate.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/config.gif b/org.eclipse.osee.framework.ui.service.control/images/config.gif Binary files differnew file mode 100644 index 00000000000..9ac596da3a4 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/config.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/connect_folder.gif b/org.eclipse.osee.framework.ui.service.control/images/connect_folder.gif Binary files differnew file mode 100644 index 00000000000..2e9b6290114 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/connect_folder.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/connected_plug.gif b/org.eclipse.osee.framework.ui.service.control/images/connected_plug.gif Binary files differnew file mode 100644 index 00000000000..8493df40dfe --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/connected_plug.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/connection.gif b/org.eclipse.osee.framework.ui.service.control/images/connection.gif Binary files differnew file mode 100644 index 00000000000..9a2594bf50e --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/connection.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/disconnected.gif b/org.eclipse.osee.framework.ui.service.control/images/disconnected.gif Binary files differnew file mode 100644 index 00000000000..0994e2487fb --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/disconnected.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/file.gif b/org.eclipse.osee.framework.ui.service.control/images/file.gif Binary files differnew file mode 100644 index 00000000000..7ccc6a70317 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/file.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/group.gif b/org.eclipse.osee.framework.ui.service.control/images/group.gif Binary files differnew file mode 100644 index 00000000000..5ba5b91c5bb --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/group.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/help.gif b/org.eclipse.osee.framework.ui.service.control/images/help.gif Binary files differnew file mode 100644 index 00000000000..68ae93b159c --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/help.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/monitor.GIF b/org.eclipse.osee.framework.ui.service.control/images/monitor.GIF Binary files differnew file mode 100644 index 00000000000..1c1054979f8 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/monitor.GIF diff --git a/org.eclipse.osee.framework.ui.service.control/images/refresh.gif b/org.eclipse.osee.framework.ui.service.control/images/refresh.gif Binary files differnew file mode 100644 index 00000000000..a063c230aca --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/refresh.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/rocket.gif b/org.eclipse.osee.framework.ui.service.control/images/rocket.gif Binary files differnew file mode 100644 index 00000000000..1caea3cba9a --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/rocket.gif diff --git a/org.eclipse.osee.framework.ui.service.control/images/tools.gif b/org.eclipse.osee.framework.ui.service.control/images/tools.gif Binary files differnew file mode 100644 index 00000000000..bb64374a7be --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/images/tools.gif diff --git a/org.eclipse.osee.framework.ui.service.control/plugin.xml b/org.eclipse.osee.framework.ui.service.control/plugin.xml new file mode 100644 index 00000000000..f1a6fd1de73 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/plugin.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+ <extension-point id="ServiceView" name="org.eclipse.osee.framework.ui.service.control.ServiceView" schema="schema/ServiceView.exsd"/>
+ <extension-point id="ServiceLaunch" name="ServiceLaunch" schema="schema/ServiceLaunch.exsd"/>
+
+ <extension
+ id="org.eclipse.osee.framework.ui.skynet"
+ name="OSEE"
+ point="org.eclipse.ui.views">
+ <category
+ id="osee.jdk.core.category"
+ name="OSEE"
+ parentCategory="osee.jdk.core.category"/>
+ <view
+ category="osee.jdk.core.category"
+ class="org.eclipse.osee.framework.ui.service.control.view.ServiceManagerView"
+ icon="images/monitor.GIF"
+ id="org.eclipse.osee.framework.ui.service.control.view.ServiceManagerView"
+ name="Service Manager"/>
+ </extension>
+ <extension
+ point="org.eclipse.osee.framework.ui.service.control.ServiceLaunch">
+ <Application
+ RequiresJiniGroup="true"
+ ServiceName="Local Jini Lookup Service">
+ <NotLocalToPlugin
+ PluginId="org.eclipse.osee.framework.jini">
+ </NotLocalToPlugin>
+ <EclipseApplication
+ AppArgs="-port 8080 -nohup"
+ EclipseApplicationName="org.eclipse.osee.framework.jini.JiniLookup"
+ IsLocalAllowed="true"
+ VmArgs="-Xmx512m -Dlookupcomponent -XX:MaxPermSize=256m">
+ </EclipseApplication>
+ <StandAloneApplication
+ AppArgs="8080 -nohup"
+ ExecutionCommand="-jar@oseejini.jar"
+ IsLocalAllowed="true"
+ IsRemoteAllowed="false"
+ VmArgs="-Xmx512m -Dlookupcomponent -XX:MaxPermSize=256m">
+ <ApplicationBundle
+ UnzipLocation="$USERNAME/server_launching"
+ ZipFileName="oseejinilookup.zip">
+ </ApplicationBundle>
+ </StandAloneApplication>
+ </Application>
+ </extension>
+</plugin>
diff --git a/org.eclipse.osee.framework.ui.service.control/schema/ServiceLaunch.exsd b/org.eclipse.osee.framework.ui.service.control/schema/ServiceLaunch.exsd new file mode 100644 index 00000000000..c0da21276e2 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/schema/ServiceLaunch.exsd @@ -0,0 +1,234 @@ +<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.osee.framework.ui.service.control">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.osee.framework.ui.service.control" id="ServiceLaunch" name="ServiceLaunch"/>
+ </appInfo>
+ <documentation>
+ Contributions to this extension point provide information needed to launch a service.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="Application"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="Application">
+ <complexType>
+ <sequence>
+ <element ref="EclipseApplication" minOccurs="0" maxOccurs="1"/>
+ <element ref="StandAloneApplication" minOccurs="0" maxOccurs="1"/>
+ <element ref="NotLocalToPlugin" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ <attribute name="ServiceName" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="RequiresJiniGroup" type="boolean" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="EclipseApplication">
+ <complexType>
+ <attribute name="EclipseApplicationName" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="IsLocalAllowed" type="boolean" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="VmArgs" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="AppArgs" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="StandAloneApplication">
+ <complexType>
+ <sequence>
+ <element ref="Host" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="ApplicationBundle"/>
+ </sequence>
+ <attribute name="ExecutionCommand" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="IsLocalAllowed" type="boolean" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="IsRemoteAllowed" type="boolean" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="VmArgs" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="AppArgs" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="Host">
+ <complexType>
+ <attribute name="Name" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="ApplicationBundle">
+ <complexType>
+ <attribute name="ZipFileName" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="UnzipLocation" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="NotLocalToPlugin">
+ <complexType>
+ <attribute name="PluginId" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.osee.framework.ui.service.control/schema/ServiceView.exsd b/org.eclipse.osee.framework.ui.service.control/schema/ServiceView.exsd new file mode 100644 index 00000000000..a4e97bc9712 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/schema/ServiceView.exsd @@ -0,0 +1,126 @@ +<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.osee.framework.ui.service.control">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.osee.framework.ui.service.control" id="ServiceView" name="org.eclipse.osee.framework.ui.service.control.ServiceView"/>
+ </appInfo>
+ <documentation>
+ Contributions to this extension point enable service manager to connect to a jini service and allow user to interact with it or get more detailed information. Contributors will need to provide a remote interface to define how to connect to the service and will need to provide a service renderer to provide the graphical user interface.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="ServiceHandler" minOccurs="1" maxOccurs="unbounded"/>
+ <element ref="RegisterBundle" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="ServiceHandler">
+ <complexType>
+ <attribute name="ServiceInterface" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="java.rmi.Remote"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="ServiceRenderer" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="osee.service.control.renderer.ServiceRenderer"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="ServiceIcon" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="resource"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/ControlPlugin.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/ControlPlugin.java new file mode 100644 index 00000000000..809bf939d3a --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/ControlPlugin.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.service.control; + +import org.eclipse.osee.framework.ui.plugin.OseeUiActivator; + +/** + * The main plugin class to be used in the desktop. + * + * @author Roberto E. Escobar + */ +public class ControlPlugin extends OseeUiActivator { + + private static ControlPlugin pluginInstance; // The shared instance. + + /** + * The constructor. + */ + public ControlPlugin() { + pluginInstance = this; + } + + /** + * Returns the shared instance. + */ + public static ControlPlugin getInstance() { + return pluginInstance; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/HideLookupsAction.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/HideLookupsAction.java new file mode 100644 index 00000000000..0d70728b127 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/HideLookupsAction.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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.service.control.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; + +/** + * @author Roberto E. Escobar + */ +public class HideLookupsAction extends Action { + + private ManagerMain mainWindow; + private static String ACTION_TITLE = "non-member Lookup Servers"; + + public HideLookupsAction(ManagerMain mainWindow) { + super("", Action.AS_CHECK_BOX); + this.mainWindow = mainWindow; + setImageDescriptor(ControlPlugin.getInstance().getImageDescriptor("tools.gif")); + setText("Display " + ACTION_TITLE); + } + + public void run() { + mainWindow.getLookupUpdater().filterLookupServers(isChecked()); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java new file mode 100644 index 00000000000..1720b4c3ec1 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/InspectLookUpServerAction.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.service.control.actions; + +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.osee.framework.ui.service.control.dialogs.InspectReggieDialogHelper; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; +import org.eclipse.swt.widgets.Display; + +/** + * @author Roberto E. Escobar + */ +public class InspectLookUpServerAction implements IDoubleClickListener { + private ManagerMain mainWindow; + + public InspectLookUpServerAction(ManagerMain mainWindow) { + super(); + this.mainWindow = mainWindow; + this.mainWindow.getLookupViewer().getViewer().addDoubleClickListener(this); + } + + public void doubleClick(DoubleClickEvent event) { + ISelection sel = event.getSelection(); + if (!sel.isEmpty()) { + Object object = ((StructuredSelection) sel).getFirstElement(); + if (object instanceof ServiceRegistrar) { + Display.getDefault().asyncExec(new InspectReggieDialogHelper(mainWindow, (ServiceRegistrar) object)); + } + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/KillServiceAction.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/KillServiceAction.java new file mode 100644 index 00000000000..9b46c265080 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/KillServiceAction.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.service.control.actions; + +import java.rmi.RemoteException; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.osee.framework.jdk.core.type.TreeObject; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.jini.service.interfaces.IService; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.widgets.IServiceManager; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class KillServiceAction extends Action implements ISelectionChangedListener { + + private IServiceManager<TreeParent> mainWindow; + + public KillServiceAction(IServiceManager<TreeParent> mainWindow) { + super(); + this.mainWindow = mainWindow; + mainWindow.getServicesViewer().getViewer().addSelectionChangedListener(this); + + setText("Kill Service"); + setToolTipText("Shutdown the selected service."); + setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_OBJS_ERROR_TSK)); + } + + public void run() { + ISelection sel = mainWindow.getServicesViewer().getViewer().getSelection(); + if (!sel.isEmpty()) { + TreeObject treeObject = (TreeObject) ((StructuredSelection) sel).getFirstElement(); + if (treeObject instanceof ServiceNode) { + ServiceNode serviceNode = ((ServiceNode) treeObject); + Object service = serviceNode.getServiceItem().service; + if (service instanceof IService) { + try { + ((IService) service).kill(); + } catch (RemoteException ex) { + MessageDialog.openError( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Kill Service Error", + "Unable to kill [" + serviceNode.getName() + "] service.\n" + "Service may no longer be available."); + } + } + } + } + } + + public void selectionChanged(SelectionChangedEvent event) { + StructuredSelection selection = (StructuredSelection) event.getSelection(); + if (!selection.isEmpty()) { + TreeObject selectedObject = (TreeObject) selection.getFirstElement(); + if (selectedObject instanceof ServiceNode) { + ServiceNode serviceNode = ((ServiceNode) selectedObject); + Object service = serviceNode.getServiceItem().service; + if (service instanceof IService) { + this.setEnabled(true); + } else { + this.setEnabled(false); + } + } else { + this.setEnabled(false); + } + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/LookupUpdates.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/LookupUpdates.java new file mode 100644 index 00000000000..a2ede88c535 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/LookupUpdates.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * 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.service.control.actions; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.eclipse.osee.framework.jini.discovery.EclipseJiniClassloader; +import org.eclipse.osee.framework.jini.discovery.IRegistrarListener; +import org.eclipse.osee.framework.ui.service.control.managers.ReggieCache; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.osee.framework.ui.service.control.renderer.ReggieItemHandler; +import org.eclipse.osee.framework.ui.service.control.widgets.LookupViewer; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceRegistrar; + +/** + * @author Roberto E. Escobar + */ +public class LookupUpdates implements IRegistrarListener { + + private LookupViewer viewer; + private ReggieCache reggieCache; + private Map<ServiceID, IRenderer> handlerMap; + private Map<ServiceID, ServiceRegistrar> filteredReggieMap; + private Collection<ServiceRegistrar> unfilteredList; + + public LookupUpdates(ManagerMain mainWindow) { + super(); + this.viewer = mainWindow.getLookupViewer(); + this.handlerMap = new HashMap<ServiceID, IRenderer>(); + this.reggieCache = ReggieCache.getEclipseInstance(EclipseJiniClassloader.getInstance()); + this.filteredReggieMap = new HashMap<ServiceID, ServiceRegistrar>(); + this.unfilteredList = reggieCache.getServiceRegistrars().values(); + this.viewer.setRendererMap(handlerMap); + this.viewer.setInput(filteredReggieMap.values()); + reggieCache.addListener(this); + } + + public void clear() { + handlerMap.clear(); + filteredReggieMap.clear(); + } + + public void filterLookupServers(boolean displayAll) { + this.viewer.setInput(displayAll ? unfilteredList : filteredReggieMap.values()); + this.viewer.refresh(); + } + + public void reggieAdded(List<ServiceRegistrar> serviceRegistrars) { + // System.out.println("Reggie Added: "); + Iterator<ServiceRegistrar> iterator = serviceRegistrars.iterator(); + while (iterator.hasNext()) { + ServiceRegistrar reggie = iterator.next(); + ServiceID serviceID = reggie.getServiceID(); + if (!handlerMap.containsKey(serviceID)) { + handlerMap.put(serviceID, new ReggieItemHandler(reggie)); + + if (ReggieItemHandler.isAllowed(reggie)) { + filteredReggieMap.put(serviceID, reggie); + } + } + } + viewer.refresh(); + } + + @SuppressWarnings("unchecked") + public void reggieRemoved(List<ServiceRegistrar> serviceRegistrars) { + // System.out.println("Reggie Removed: "); + Set<ServiceID> cachedReggies = handlerMap.keySet(); + Set<ServiceID> availableReggies = new HashSet<ServiceID>(); + Iterator<ServiceRegistrar> iterator = serviceRegistrars.iterator(); + while (iterator.hasNext()) { + ServiceRegistrar reggie = iterator.next(); + availableReggies.add(reggie.getServiceID()); + } + + List discardedIds = + org.eclipse.osee.framework.jdk.core.util.Collections.setComplement(cachedReggies, availableReggies); + Iterator iterator2 = discardedIds.iterator(); + ServiceID toProcess = null; + while (iterator2.hasNext()) { + toProcess = (ServiceID) iterator2.next(); + handlerMap.remove(toProcess); + + if (filteredReggieMap.containsKey(toProcess)) { + filteredReggieMap.remove(toProcess); + } + } + viewer.refresh(); + } + + public void reggieChanged(List<ServiceRegistrar> serviceRegistrars) { + // System.out.println("Reggie Changed: "); + Iterator<ServiceRegistrar> iterator = serviceRegistrars.iterator(); + while (iterator.hasNext()) { + ServiceRegistrar reggie = iterator.next(); + ServiceID serviceID = reggie.getServiceID(); + if (handlerMap.containsKey(serviceID)) { + handlerMap.put(serviceID, new ReggieItemHandler(reggie)); + } + if (ReggieItemHandler.isAllowed(reggie)) { + filteredReggieMap.put(serviceID, reggie); + } + } + viewer.refresh(); + } + + public void dispose() { + reggieCache.removeListener(this); + viewer.dispose(); + handlerMap.clear(); + filteredReggieMap.clear(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/NodeDoubleClicked.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/NodeDoubleClicked.java new file mode 100644 index 00000000000..a650973539f --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/NodeDoubleClicked.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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.service.control.actions; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.osee.framework.jdk.core.type.TreeObject; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.managers.ConnectionManager; +import org.eclipse.osee.framework.ui.service.control.managers.ServiceConnectionException; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class NodeDoubleClicked implements IDoubleClickListener { + + private ManagerMain mainWindow; + private ConnectionManager connectionManager; + + public NodeDoubleClicked(ManagerMain mainWindow) { + super(); + this.mainWindow = mainWindow; + this.connectionManager = mainWindow.getConnectionManager(); + this.mainWindow.getServicesViewer().getViewer().addDoubleClickListener(this); + } + + public void doubleClick(DoubleClickEvent event) { + ISelection sel = event.getSelection(); + if (!sel.isEmpty()) { + TreeObject treeObject = (TreeObject) ((StructuredSelection) sel).getFirstElement(); + if (treeObject instanceof ServiceNode) { + ServiceNode serviceNode = (ServiceNode) treeObject; + if (connectionManager.isAllowedConnectionType(serviceNode.getServiceItem())) { + try { + connectionManager.attemptConnection(serviceNode); + } catch (ServiceConnectionException ex) { + MessageDialog.openError( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Unable to Connect", + "Unable to connect to [" + serviceNode.getName() + "] service.\n" + "Service may no longer be available."); + } + } else { + MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Unsupported Connection", "Connection is not allowed for [" + serviceNode.getName() + "] Service."); + } + } + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/NodeSelected.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/NodeSelected.java new file mode 100644 index 00000000000..3f81ab7a084 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/NodeSelected.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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.service.control.actions; + +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.osee.framework.jdk.core.type.TreeObject; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.data.IJiniService; +import org.eclipse.osee.framework.ui.service.control.data.ReggieMonitorServiceNode; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.osee.framework.ui.service.control.widgets.IServiceManager; +import org.eclipse.osee.framework.ui.service.control.widgets.LookupViewer; +import org.eclipse.osee.framework.ui.swt.FormattedText; + +/** + * @author Roberto E. Escobar + */ +public class NodeSelected implements ISelectionChangedListener { + + private IServiceManager<TreeParent> mainWindow; + private FormattedText textArea; + private LookupViewer lookupViewer; + + public NodeSelected(IServiceManager<TreeParent> mainWindow) { + super(); + this.mainWindow = mainWindow; + this.mainWindow.getServicesViewer().getViewer().addSelectionChangedListener(this); + this.textArea = this.mainWindow.getQuickViewer(); + this.lookupViewer = this.mainWindow.getLookupViewer(); + if (lookupViewer != null) { + lookupViewer.getViewer().addSelectionChangedListener(this); + } + + } + + public void selectionChanged(SelectionChangedEvent event) { + StructuredSelection selection = (StructuredSelection) event.getSelection(); + if (!selection.isEmpty()) { + Object selectedObject = selection.getFirstElement(); + if (selectedObject instanceof TreeObject) { + handleTreeSelection((TreeObject) selectedObject); + } else if (selectedObject instanceof ServiceRegistrar) { + handleLookupSelection((ServiceRegistrar) selectedObject); + } + } + } + + private void handleTreeSelection(TreeObject treeObject) { + if (treeObject instanceof IRenderer) { + ((IRenderer) treeObject).renderInComposite(textArea); + } + + if (treeObject instanceof IJiniService) { + if (lookupViewer != null) { + + String serviceId = null; + if (treeObject instanceof ReggieMonitorServiceNode) { + serviceId = ((ReggieMonitorServiceNode) treeObject).getSpawnedReggieServiceId(); + } else { + serviceId = ((IJiniService) treeObject).getServiceID().toString(); + } + + lookupViewer.setSelection(serviceId); + } + } + } + + private void handleLookupSelection(ServiceRegistrar serviceRegistrar) { + if (lookupViewer != null) { + IRenderer renderer = this.mainWindow.getLookupViewer().getRenderer(serviceRegistrar.getServiceID()); + if (renderer != null) { + renderer.renderInComposite(textArea); + } + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java new file mode 100644 index 00000000000..010ee736d1c --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/OpenLaunchWizard.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.service.control.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchWizard; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceWizardDialog; +import org.eclipse.swt.widgets.Display; + +/** + * @author Roberto E. Escobar + */ +public class OpenLaunchWizard extends Action { + + public OpenLaunchWizard(ManagerMain mainWindow) { + super(); + setImageDescriptor(ControlPlugin.getInstance().getImageDescriptor("rocket.gif")); + setText("Launch A Service"); +// setToolTipText("Open the service launching wizard."); + //TODO: Please remove next two lines upon action 4ZXCH completion. + this.setToolTipText("Disabled until action 4ZXCH is complete."); + this.setEnabled(false); + } + + public void run() { + super.run(); + ServiceLaunchWizard wizard = new ServiceLaunchWizard(); + ServiceWizardDialog dialog = new ServiceWizardDialog(Display.getDefault().getActiveShell(), wizard); + dialog.setBlockOnOpen(true); + dialog.open(); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/RefreshDataStore.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/RefreshDataStore.java new file mode 100644 index 00000000000..f7b420d79c3 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/RefreshDataStore.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.service.control.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.osee.framework.jini.discovery.EclipseJiniClassloader; +import org.eclipse.osee.framework.jini.discovery.ServiceDataStore; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.managers.ReggieCache; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; + +/** + * @author Roberto E. Escobar + */ +public class RefreshDataStore extends Action { + + private ManagerMain mainWindow; + + public RefreshDataStore(ManagerMain mainWindow) { + super(); + this.mainWindow = mainWindow; + this.setText("Refresh"); + this.setToolTipText("Refresh Lookup Servers and Services.\n" + "NOTE: Disconnects from service when connected."); + this.setImageDescriptor(ControlPlugin.getInstance().getImageDescriptor("refresh.gif")); + } + + public void run() { + mainWindow.getLookupUpdater().clear(); + mainWindow.getServicesManager().clear(); + mainWindow.getConnectionManager().forceDisconnect(); + mainWindow.getServicesViewer().refresh(); + mainWindow.getLookupViewer().refresh(); + mainWindow.getQuickViewer().clearTextArea(); + ServiceDataStore.getEclipseInstance(EclipseJiniClassloader.getInstance()).refresh(); + ReggieCache.getEclipseInstance(EclipseJiniClassloader.getInstance()).refresh(); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/ServiceUpdates.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/ServiceUpdates.java new file mode 100644 index 00000000000..9550c1f4d24 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/ServiceUpdates.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.service.control.actions; + +import java.util.Collection; +import org.eclipse.osee.framework.jdk.core.type.IInputListener; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.widgets.IServiceManager; + +/** + * @author Roberto E. Escobar + */ +public class ServiceUpdates implements IInputListener<TreeParent> { + + private IServiceManager<TreeParent> parentWindow; + + @SuppressWarnings("unchecked") + public ServiceUpdates(IServiceManager parentWindow) { + this.parentWindow = parentWindow; + this.parentWindow.getInputManager().addInputListener(this); + } + + public void refresh() { + this.parentWindow.getServicesViewer().refresh(); + } + + public void addNode(TreeParent node) { + refresh(); + } + + public void removeNode(TreeParent node) { + refresh(); + } + + public void removeAll() { + refresh(); + } + + public void inputChanged() { + refresh(); + } + + public void addNodes(Collection<TreeParent> nodes) { + refresh(); + } + + public void nodeChanged(TreeParent inNode) { + refresh(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/UpdateLookupViewerToolTip.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/UpdateLookupViewerToolTip.java new file mode 100644 index 00000000000..fb7755cfb7b --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/UpdateLookupViewerToolTip.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.service.control.actions; + +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.widgets.IServiceManager; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.TableItem; + +/** + * @author Roberto E. Escobar + */ +public class UpdateLookupViewerToolTip implements MouseTrackListener { + + private IServiceManager<TreeParent> mainWindow; + private StructuredViewer structuredViewer; + + public UpdateLookupViewerToolTip(IServiceManager<TreeParent> mainWindow) { + super(); + this.mainWindow = mainWindow; + this.mainWindow.getLookupViewer().getViewer().getControl().addMouseTrackListener(this); + structuredViewer = this.mainWindow.getLookupViewer().getViewer(); + } + + public void mouseEnter(MouseEvent e) { + structuredViewer.getControl().setToolTipText("Displays JINI Lookup Servers"); + } + + public void mouseExit(MouseEvent e) { + structuredViewer.getControl().setToolTipText("Displays JINI Lookup Servers"); + } + + public void mouseHover(MouseEvent e) { + String toSet = ""; + Point point = new Point(e.x, e.y); + TableItem tableItem = ((TableViewer) structuredViewer).getTable().getItem(point); + if (tableItem != null) { + Object elementData = tableItem.getData(); + if (elementData instanceof ServiceRegistrar) { + toSet = "Double-Click to explorer services that are registered ONLY on this lookup server."; + structuredViewer.getControl().setToolTipText(toSet); + } + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/UpdateToolTip.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/UpdateToolTip.java new file mode 100644 index 00000000000..234e25aa3f4 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/actions/UpdateToolTip.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * 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.service.control.actions; + +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.data.CategoryParent; +import org.eclipse.osee.framework.ui.service.control.data.ReggieMonitorServiceNode; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.managers.ConnectionManager; +import org.eclipse.osee.framework.ui.service.control.widgets.IServiceManager; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.TreeItem; + +/** + * @author Roberto E. Escobar + */ +public class UpdateToolTip implements MouseTrackListener { + + private IServiceManager<TreeParent> mainWindow; + private TreeViewer treeViewer; + + public UpdateToolTip(IServiceManager<TreeParent> mainWindow) { + super(); + this.mainWindow = mainWindow; + this.mainWindow.getServicesViewer().getViewer().getControl().addMouseTrackListener(this); + treeViewer = (TreeViewer) this.mainWindow.getServicesViewer().getViewer(); + } + + private String handleCategorySelection(CategoryParent category) { + int numberOfItems = category.getChildren().length; + String name = category.getName(); + return name + ": " + numberOfItems + (numberOfItems == 1 ? " service" : " services"); + } + + public void mouseEnter(MouseEvent e) { + mainWindow.getServicesViewer().getViewer().getControl().setToolTipText("Displays JINI services"); + } + + public void mouseExit(MouseEvent e) { + mainWindow.getServicesViewer().getViewer().getControl().setToolTipText("Displays JINI services"); + } + + public void mouseHover(MouseEvent e) { + String toSet = ""; + Point point = new Point(e.x, e.y); + TreeItem treeItem = treeViewer.getTree().getItem(point); + if (treeItem != null) { + Object elementData = treeItem.getData(); + if (elementData instanceof CategoryParent) { + toSet = handleCategorySelection((CategoryParent) elementData); + mainWindow.getServicesViewer().getViewer().getControl().setToolTipText(toSet); + } else if (elementData instanceof ReggieMonitorServiceNode) { + ReggieMonitorServiceNode monitorNode = (ReggieMonitorServiceNode) elementData; + + toSet = + "Right-Click and select Kill from pop-up menu \n" + "to terminate Lookup Server.\n" + "On: " + monitorNode.getSpawnedReggieOnHost() + "\n" + "Service Id: " + monitorNode.getSpawnedReggieServiceId(); + mainWindow.getServicesViewer().getViewer().getControl().setToolTipText(toSet); + } else if (elementData instanceof ServiceNode) { + ServiceNode serviceNode = (ServiceNode) elementData; + if (ConnectionManager.getInstance().isAllowedConnectionType(serviceNode.getServiceItem())) { + toSet = "Double-Click to interact with " + serviceNode.getName(); + mainWindow.getServicesViewer().getViewer().getControl().setToolTipText(toSet); + } + } + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/CategoryParent.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/CategoryParent.java new file mode 100644 index 00000000000..ae67eb2ce13 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/CategoryParent.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.service.control.data; + +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public class CategoryParent extends TreeParent implements IRenderer { + + public CategoryParent() { + super(); + } + + public CategoryParent(String name) { + super(name); + } + + public Control renderInComposite(Composite parent) { + if (parent instanceof FormattedText) { + ((FormattedText) parent).clearTextArea(); + } + return parent; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/GroupParent.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/GroupParent.java new file mode 100644 index 00000000000..cba58984388 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/GroupParent.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.service.control.data; + +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public class GroupParent extends TreeParent implements IRenderer { + + public GroupParent() { + super(); + } + + public GroupParent(String name) { + super(name); + } + + public Control renderInComposite(Composite parent) { + if (parent instanceof FormattedText) { + ((FormattedText) parent).clearTextArea(); + } + return parent; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/IJiniService.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/IJiniService.java new file mode 100644 index 00000000000..2481ce3312e --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/IJiniService.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * 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.service.control.data; + +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import net.jini.core.lookup.ServiceID; + +/** + * @author Roberto E. Escobar + */ +public interface IJiniService extends IRenderer { + + public ServiceID getServiceID(); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ReggieMonitorServiceNode.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ReggieMonitorServiceNode.java new file mode 100644 index 00000000000..0ca4320f9aa --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ReggieMonitorServiceNode.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * 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.service.control.data; + +import org.eclipse.osee.framework.jini.service.core.SimpleFormattedEntry; +import org.eclipse.osee.framework.jini.utility.StartJini; +import net.jini.core.entry.Entry; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceItem; + +/** + * @author Roberto E. Escobar + */ +public class ReggieMonitorServiceNode extends ServiceNode { + + private String spawnedReggieId; + private String spawnedReggieOnHost; + + /** + * @param serviceID + * @param serviceItem + */ + public ReggieMonitorServiceNode(ServiceID serviceID, ServiceItem serviceItem) { + super(serviceID, serviceItem); + spawnedReggieId = parseInfo(serviceItem, StartJini.SPAWNED_REGGIE_SERVICE_ID); + spawnedReggieOnHost = parseInfo(serviceItem, StartJini.SPAWNED_REGGIE_ON_HOST); + } + + @Override + public void setServiceItem(ServiceItem serviceItem) { + super.setServiceItem(serviceItem); + spawnedReggieId = parseInfo(serviceItem, StartJini.SPAWNED_REGGIE_SERVICE_ID); + spawnedReggieOnHost = parseInfo(serviceItem, StartJini.SPAWNED_REGGIE_ON_HOST); + } + + private String parseInfo(ServiceItem serviceItem, String key) { + String toReturn = ""; + Entry[] entryArray = serviceItem.attributeSets; + for (Entry entry : entryArray) { + if (entry instanceof SimpleFormattedEntry) { + String name = ((SimpleFormattedEntry) entry).name; + String value = ((SimpleFormattedEntry) entry).value; + if (name != null && name.length() > 0 && value != null && value.length() > 0) { + if (name.equals(key)) { + toReturn = value; + } + } + } + } + return toReturn; + } + + public String getSpawnedReggieServiceId() { + return spawnedReggieId; + } + + public String getSpawnedReggieOnHost() { + return spawnedReggieOnHost; + } + + public static boolean isReggieMonitor(ServiceItem serviceItem) { + boolean isReggieMonitor = false; + Entry[] entryArray = serviceItem.attributeSets; + for (Entry entry : entryArray) { + if (entry instanceof SimpleFormattedEntry) { + String name = ((SimpleFormattedEntry) entry).name; + String value = ((SimpleFormattedEntry) entry).value; + if (name != null && name.length() > 0 && value != null && value.length() > 0) { + if (name.equals("Spawned Reggie Id")) { + isReggieMonitor = true; + } + } + } + } + return isReggieMonitor; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ServiceNode.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ServiceNode.java new file mode 100644 index 00000000000..09dd8ec60d2 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ServiceNode.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * 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.service.control.data; + +import java.util.Set; +import java.util.TreeSet; + +import net.jini.core.entry.Entry; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceItem; + +import org.eclipse.osee.framework.jdk.core.type.TreeObject; +import org.eclipse.osee.framework.jini.service.core.GroupEntry; +import org.eclipse.osee.framework.jini.service.core.PropertyEntry; +import org.eclipse.osee.framework.ui.service.control.renderer.ServiceItemHandler; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public class ServiceNode extends TreeObject implements IJiniService { + + private ServiceID serviceID; + private ServiceItem serviceItem; + private ServiceItemHandler handler; + private boolean connected; + private Set<String> groups; + + public ServiceNode(ServiceID serviceID, ServiceItem serviceItem) { + super(); + this.serviceID = serviceID; + this.serviceItem = serviceItem; + this.handler = new ServiceItemHandler(serviceItem); + this.connected = false; + this.groups = parseGroups(serviceItem); + } + + public void setServiceItem(ServiceItem serviceItem) { + this.serviceID = serviceItem.serviceID; + this.serviceItem = serviceItem; + this.handler = new ServiceItemHandler(serviceItem); + this.groups = parseGroups(serviceItem); + } + + public ServiceID getServiceID() { + return serviceID; + } + + public ServiceItem getServiceItem() { + return serviceItem; + } + + public boolean isConnected() { + return connected; + } + + public void setConnected(boolean connected) { + this.connected = connected; + } + + public Control renderInComposite(Composite parent) { + return handler.renderInComposite(parent); + } + + public void setGroups(Set<String> groups) { + this.groups = groups; + } + + public boolean isMemberOf(String value) { + return groups.contains(value); + } + + public Set<String> getGroups() { + return groups; + } + + private Set<String> parseGroups(ServiceItem serviceItem) { + Set<String> toReturn = new TreeSet<String>(); + Entry[] entryArray = serviceItem.attributeSets; + for (Entry entry : entryArray) { + if (entry instanceof GroupEntry) { + String[] groups = ((GroupEntry) entry).group; + for (String temp : groups) { + if (temp != null) { + temp = temp.trim(); + } + if (temp == null || temp.length() == 0) { + toReturn.add("Public"); + } else { + toReturn.add(temp); + } + } + } else if (entry instanceof PropertyEntry) { + toReturn.add( (String) ((PropertyEntry)entry).getProperty("group", "OSEE Services")); + } + } + if (toReturn.size() == 0) { + toReturn.add("Public"); + } + return toReturn; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ServiceNodeFactory.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ServiceNodeFactory.java new file mode 100644 index 00000000000..17d3bfdc07b --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/data/ServiceNodeFactory.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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.service.control.data; + +import net.jini.core.entry.Entry; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceItem; +import net.jini.lookup.entry.Name; +import net.jini.lookup.entry.ServiceInfo; + +import org.eclipse.osee.framework.jini.service.core.PropertyEntry; + +/** + * @author Roberto E. Escobar + */ +public class ServiceNodeFactory { + + private static ServiceNodeFactory instance = null; + + private ServiceNodeFactory() { + } + + public static ServiceNodeFactory getInstance() { + if (instance == null) { + instance = new ServiceNodeFactory(); + } + return instance; + } + + public ServiceNode createServiceNode(ServiceID serviceID, ServiceItem serviceItem) { + ServiceNode serviceNode = null; + + if (ReggieMonitorServiceNode.isReggieMonitor(serviceItem)) { + serviceNode = new ReggieMonitorServiceNode(serviceID, serviceItem); + } else { + serviceNode = new ServiceNode(serviceID, serviceItem); + } + + String label = getLabelBasedOnName(serviceItem); + if (label.equals("")) { + label = getLabelBasedOnServiceInfo(serviceItem); + } + serviceNode.setName(label); + return serviceNode; + } + + private String getLabelBasedOnName(ServiceItem serviceItem) { + Entry[] entryArray = serviceItem.attributeSets; + for (Entry entry : entryArray) { + if (entry instanceof Name) { + return ((Name) entry).name.toString(); + } else if (entry instanceof PropertyEntry){ + return (String)((PropertyEntry)entry).getProperty("name", "unknown"); + } + } + return ""; + } + + private String getLabelBasedOnServiceInfo(ServiceItem serviceItem) { + Entry[] entryArray = serviceItem.attributeSets; + for (Entry entry : entryArray) { + if (entry instanceof ServiceInfo) { + return ((ServiceInfo) entry).name.toString(); + } + } + return serviceItem.service.getClass().getName(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/InspectReggieDialog.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/InspectReggieDialog.java new file mode 100644 index 00000000000..c208151aeb2 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/InspectReggieDialog.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * 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.service.control.dialogs; + +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.jdk.core.type.InputManager; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.actions.KillServiceAction; +import org.eclipse.osee.framework.ui.service.control.actions.NodeSelected; +import org.eclipse.osee.framework.ui.service.control.actions.ServiceUpdates; +import org.eclipse.osee.framework.ui.service.control.managers.ServiceTreeBuilder; +import org.eclipse.osee.framework.ui.service.control.renderer.ReggieItemHandler; +import org.eclipse.osee.framework.ui.service.control.widgets.IServiceManager; +import org.eclipse.osee.framework.ui.service.control.widgets.LookupViewer; +import org.eclipse.osee.framework.ui.service.control.widgets.ServicesViewer; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Roberto E. Escobar + */ +public class InspectReggieDialog extends MessageDialog implements IServiceManager<TreeParent> { + + private Button okButton; + private Button cancelButton; + private boolean selectionOk; + + private ServiceRegistrar reggie; + private ServicesViewer servicesViewer; + + private FormattedText quickViewer; + private ServiceTreeBuilder serviceTreeBuilder; + private ReggieItemHandler reggieParser; + + public InspectReggieDialog(Shell parentShell, ServiceRegistrar reggie, ReggieItemHandler reggieParser, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, + defaultIndex); + this.reggie = reggie; + this.reggieParser = reggieParser; + this.serviceTreeBuilder = new ServiceTreeBuilder(); + this.selectionOk = false; + } + + @Override + protected Control createCustomArea(Composite parent) { + super.createCustomArea(parent); + + SashForm composite = new SashForm(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setOrientation(SWT.VERTICAL); + composite.SASH_WIDTH = 3; + + reggieParser.renderInComposite(new FormattedText(composite, SWT.NONE)); + + SashForm sashForm = new SashForm(composite, SWT.NONE); + sashForm.setLayout(new GridLayout()); + sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + sashForm.setOrientation(SWT.HORIZONTAL); + sashForm.SASH_WIDTH = 3; + + servicesViewer = new ServicesViewer(sashForm, SWT.NONE); + + quickViewer = new FormattedText(sashForm, SWT.BORDER); + quickViewer.getStyledText().setToolTipText("Displays Service Information"); + quickViewer.setTextAreaBackground(SWT.COLOR_WHITE); + + composite.setWeights(new int[] {3, 7}); + sashForm.setWeights(new int[] {4, 6}); + + attachListeners(); + initializeBackend(); + return parent; + } + + private void attachListeners() { + new ServiceUpdates(this); + new NodeSelected(this); + createPopup(); + } + + private void createPopup() { + MenuManager menuManager = new MenuManager("#PopupMenu"); + menuManager.setRemoveAllWhenShown(true); + menuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + manager.add(new KillServiceAction(InspectReggieDialog.this)); + } + }); + + Control control = servicesViewer.getViewer().getControl(); + Menu menu = menuManager.createContextMenu(control); + control.setMenu(menu); + } + + private void initializeBackend() { + servicesViewer.setInput(serviceTreeBuilder.getInputManager().getInputList()); + populateServices(); + } + + private void populateServices() { + Job job = new PopulateInspectReggieDialog("Searching for services on ", serviceTreeBuilder, reggie); + PopulateInspectReggieDialog.scheduleJob(job); + } + + @Override + protected Control createButtonBar(Composite parent) { + Control c = super.createButtonBar(parent); + okButton = getButton(0); + cancelButton = getButton(1); + + okButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + selectionOk = true; + } + }); + + cancelButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + selectionOk = false; + } + }); + return c; + } + + public boolean isValid() { + return selectionOk; + } + + public FormattedText getQuickViewer() { + return quickViewer; + } + + public ServicesViewer getServicesViewer() { + return servicesViewer; + } + + public InputManager<TreeParent> getInputManager() { + return serviceTreeBuilder.getInputManager(); + } + + public LookupViewer getLookupViewer() { + return null; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/InspectReggieDialogHelper.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/InspectReggieDialogHelper.java new file mode 100644 index 00000000000..5e274089edc --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/InspectReggieDialogHelper.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.service.control.dialogs; + +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.osee.framework.ui.service.control.renderer.ReggieItemHandler; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Roberto E. Escobar + */ +public class InspectReggieDialogHelper implements Runnable { + + private int result; + private Shell shell; + private ServiceRegistrar reggie; + private ReggieItemHandler reggieParser; + + public InspectReggieDialogHelper(ManagerMain mainWindow, ServiceRegistrar reggie) { + this.shell = mainWindow.getShell(); + this.reggie = reggie; + this.reggieParser = new ReggieItemHandler(reggie); + } + + public void run() { + InspectReggieDialog dlg = + new InspectReggieDialog(shell, reggie, reggieParser, "Inspect Lookup Server", null, String.format( + "Services Registered on %s:%s", reggieParser.getHost(), reggieParser.getPort()), + MessageDialog.QUESTION, new String[] {"OK", "Cancel"}, 0); + + result = dlg.open(); + if (result == Window.OK) { + } + } + + public int getResult() { + return result; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java new file mode 100644 index 00000000000..eb7e8b49a8c --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/dialogs/PopulateInspectReggieDialog.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * 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.service.control.dialogs; + +import java.rmi.RemoteException; + +import net.jini.core.lookup.ServiceItem; +import net.jini.core.lookup.ServiceMatches; +import net.jini.core.lookup.ServiceRegistrar; +import net.jini.core.lookup.ServiceTemplate; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.managers.ServiceTreeBuilder; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class PopulateInspectReggieDialog extends Job { + + private ServiceRegistrar reggie; + private ServiceTreeBuilder serviceTreeBuilder; + + public PopulateInspectReggieDialog(String title, ServiceTreeBuilder serviceTreeBuilder, ServiceRegistrar reggie) { + super(title); + this.serviceTreeBuilder = serviceTreeBuilder; + this.reggie = reggie; + + } + + public static void scheduleJob(Job job) { + job.setUser(true); + job.setPriority(Job.SHORT); + job.schedule(); + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + this.getThread().setContextClassLoader(ExportClassLoader.getInstance()); + ServiceMatches serviceMatches = reggie.lookup(new ServiceTemplate(null, null, null), Integer.MAX_VALUE); + final ServiceItem[] serviceItemArray = serviceMatches.items; + Display.getDefault().asyncExec(new Runnable() { + public void run() { + for (ServiceItem item : serviceItemArray) { + serviceTreeBuilder.serviceAdded(item); + } + } + }); + return Status.OK_STATUS; + } catch (RemoteException ex) { + try { + displayMessage("Reggie Lookup Error", String.format("Error searching for services in [%s:%s] reggie.\n%s", + reggie.getLocator().getHost(), reggie.getLocator().getPort(), ControlPlugin.getStackMessages(ex))); + } catch (RemoteException ex1) { + displayMessage("Reggie Lookup Error", String.format("Unable to access selected the selected reggie.\n%s", + ControlPlugin.getStackMessages(ex))); + } + } + return Status.CANCEL_STATUS; + } + + private void displayMessage(final String title, final String message) { + displayMessage(title, message, true); + } + + private void displayMessage(final String title, final String message, final boolean isError) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + if (isError) { + MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message); + } else { + MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, + message); + } + } + }); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/EclipseApplicationLaunchJob.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/EclipseApplicationLaunchJob.java new file mode 100644 index 00000000000..ad9219f37fc --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/EclipseApplicationLaunchJob.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * 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.service.control.jobs; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchDataPersist; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceItem; +import org.eclipse.swt.SWT; + +/** + * @author Roberto E. Escobar + */ +public class EclipseApplicationLaunchJob extends Job { + private final Logger logger = ConfigUtil.getConfigFactory().getLogger(EclipseApplicationLaunchJob.class); + private TextDisplayHelper display; + private ServiceLaunchingInformation serviceInfo; + private String javaCompiler; + private File latestPlugin; + + public EclipseApplicationLaunchJob(String name, String javaCompiler, File latestPlugin, ServiceLaunchingInformation serviceInfo, TextDisplayHelper display) { + super(name); + this.javaCompiler = javaCompiler; + this.serviceInfo = serviceInfo; + this.display = display; + this.latestPlugin = latestPlugin; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + IStatus toReturn = Status.OK_STATUS; + try { + ServiceLaunchDataPersist data = ServiceLaunchDataPersist.getInstance(); + data.saveLastServiceLaunched(serviceInfo.getServiceItem().getName()); + + if (latestPlugin != null) { + String compilerExec = javaCompiler.trim(); + if (compilerExec.endsWith(".exe")) { + compilerExec = compilerExec.substring(0, compilerExec.lastIndexOf(".exe")); + } + + String exec = serviceInfo.getServiceItem().getLocalExecution(); + if (Lib.isWindows()) { + compilerExec = "\"" + compilerExec + "\""; + exec = exec.replaceAll("-?nohup" + ServiceItem.EXEC_SEPARATOR + "?", ""); + } + exec = exec.replace("java", compilerExec); + + exec = exec.replaceAll(ServiceItem.EXEC_SEPARATOR + ServiceItem.EXEC_SEPARATOR, ServiceItem.EXEC_SEPARATOR); + + logger.log(Level.INFO, "Local Launch: " + exec); + + exec += ServiceItem.EXEC_SEPARATOR + "-debug"; + + display.addText("\n\t\t ----------- Execute -------------\n\n", SWT.BOLD, SWT.COLOR_BLACK, false); + String temp = exec.replaceAll(ServiceItem.EXEC_SEPARATOR, " "); + display.addText("\tExecuting:", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + String tag = "-application"; + display.addText("\t" + temp.substring(temp.lastIndexOf(tag) + tag.length(), temp.length()) + "\n\n", + SWT.BOLD, SWT.COLOR_BLACK, false); + + display.addText("\tRaw Command:", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText("\t" + exec.replaceAll(ServiceItem.EXEC_SEPARATOR, " ") + "\n\n", SWT.BOLD, + SWT.COLOR_BLACK, false); + + File workingDir = new File(System.getProperty("user.home") + File.separator + "oseeservices"); + workingDir.mkdirs(); + + ProcessBuilder runner = new ProcessBuilder(); + runner.directory(workingDir); + runner.command(exec.split(ServiceItem.EXEC_SEPARATOR)); + Process process = runner.start(); + + display.startProcessHandling(process); + } else { + display.addText("\n" + serviceInfo.getServiceItem().getPlugin() + " could not be found." + "\n\n", + SWT.NORMAL, SWT.COLOR_RED, false); + toReturn = Status.CANCEL_STATUS; + } + } catch (IOException ex) { + display.addText("\n" + ControlPlugin.getStackMessages(ex) + "\n\n", SWT.NORMAL, SWT.COLOR_RED, false); + toReturn = Status.CANCEL_STATUS; + } + return toReturn; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/StandAloneApplicationLaunchJob.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/StandAloneApplicationLaunchJob.java new file mode 100644 index 00000000000..912376acaa9 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/StandAloneApplicationLaunchJob.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * 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.service.control.jobs; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchDataPersist; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceItem; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.ProgressBar; +import org.eclipse.ui.PlatformUI; +import org.osgi.framework.Bundle; + +/** + * @author Roberto E. Escobar + */ +public class StandAloneApplicationLaunchJob extends Job { + + private TextDisplayHelper display; + private ServiceLaunchingInformation serviceInfo; + private String javaCompiler; + private File localLocation; + private ProgressBar progress; + + public StandAloneApplicationLaunchJob(String name, String javaCompiler, File localLocation, ServiceLaunchingInformation serviceInfo, TextDisplayHelper display, ProgressBar progress) { + super(name); + this.javaCompiler = javaCompiler; + this.serviceInfo = serviceInfo; + this.display = display; + this.localLocation = localLocation; + this.progress = progress; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + IStatus toReturn = Status.OK_STATUS; + + ServiceLaunchDataPersist data = ServiceLaunchDataPersist.getInstance(); + data.saveLastServiceLaunched(serviceInfo.getServiceItem().getName()); + + display.clear(); + display.addText("\t\t ----------- Unzip -------------\n\n", SWT.BOLD, SWT.COLOR_BLACK, false); + + try { + Bundle bundle = Platform.getBundle(serviceInfo.getServiceItem().getPlugin()); + URL url = bundle.getEntry(serviceInfo.getServiceItem().getZipName()); + URL resolvedURL = FileLocator.resolve(url); + File zipLocation = new File(resolvedURL.getFile()); + + display.addText("\tFrom Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText("\t" + zipLocation.getAbsolutePath() + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); + display.addText("\tTo Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText("\t" + localLocation.getAbsolutePath() + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); + + System.out.println(localLocation); + unzip(zipLocation, localLocation); + + } catch (Exception ex) { + display.addText(ControlPlugin.getStackMessages(ex) + "\n\n", SWT.NORMAL, SWT.COLOR_RED, false); + } + + String exec = serviceInfo.getServiceItem().getStandAloneExecution(); + String compilerExec = javaCompiler.trim(); + if (compilerExec.endsWith(".exe")) { + compilerExec = compilerExec.substring(0, compilerExec.lastIndexOf(".exe")); + } + + if (Lib.isWindows()) { + compilerExec = "\"" + compilerExec + "\""; + exec = exec.replaceAll("-?nohup" + ServiceItem.EXEC_SEPARATOR + "?", ""); + } + exec = exec.replace("java", compilerExec); + + display.addText("\n\t\t ----------- Execute -------------\n\n", SWT.BOLD, SWT.COLOR_BLACK, false); + + display.addText("\tExecuting:", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText("\t" + exec.replaceAll(ServiceItem.EXEC_SEPARATOR, " ") + "\n", SWT.BOLD, SWT.COLOR_BLACK, false); + + ProcessBuilder runner = new ProcessBuilder(); + runner.directory(localLocation); + runner.command(exec.split(ServiceItem.EXEC_SEPARATOR)); + final Process process; + try { + process = runner.start(); + + display.startProcessHandling(process); + } catch (IOException ex) { + display.addText(ControlPlugin.getStackMessages(ex) + "\n", SWT.NORMAL, SWT.COLOR_RED, false); + } + return toReturn; + } + + private Map<String, String> unzip(File zipFile, File destinationDir) throws IOException { + int BUFFER = 2048; + BufferedOutputStream dest = null; + BufferedInputStream is = null; + ZipEntry entry = null; + Map<String, String> unzippedFiles = new HashMap<String, String>(); + try { + ZipFile zipfile = new ZipFile(zipFile.getAbsolutePath()); + StringBuffer statusBuffer = new StringBuffer(); + final int totalEntries = zipfile.size(); + int countEntries = 0; + + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + progress.setMinimum(0); + progress.setMaximum(totalEntries); + progress.setSelection(0); + } + }); + + Enumeration<? extends ZipEntry> e = zipfile.entries(); + while (e.hasMoreElements()) { + incrementProgress(1); + entry = e.nextElement(); + is = new BufferedInputStream(zipfile.getInputStream(entry)); + int count; + byte data[] = new byte[BUFFER]; + File fileDir = new File(destinationDir.getAbsolutePath() + File.separator + entry.getName()); + if (entry.isDirectory()) { + fileDir.mkdirs(); + continue; + } else { + fileDir.getParentFile().mkdirs(); + } + + if (!fileDir.exists() || (fileDir.exists() && fileDir.canWrite())) { + FileOutputStream fos = new FileOutputStream(fileDir.getAbsolutePath()); + dest = new BufferedOutputStream(fos, BUFFER); + while ((count = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, count); + } + dest.flush(); + dest.close(); + } + is.close(); + + statusBuffer.append("\n\t\tUNZIPPED: " + entry.getName()); + + if (++countEntries >= 10 || !e.hasMoreElements()) { + display.addText(statusBuffer.toString(), SWT.NORMAL, SWT.COLOR_BLACK, false); + display.updateScrollBar(); + statusBuffer.delete(0, statusBuffer.length()); + countEntries = 0; + } + unzippedFiles.put(fileDir.getAbsolutePath(), entry.getName()); + + } + } catch (Exception ex) { + String information = + "ZipFile: " + (zipFile != null ? zipFile.getAbsolutePath() : "NULL") + "\n" + "DestinationDir: " + (destinationDir != null ? destinationDir.getAbsolutePath() : "NULL") + "\n" + "Entry Processed: " + (entry != null ? entry.toString() : "NULL") + "\n"; + throw new IOException(information + ex.getMessage()); + } + return unzippedFiles; + } + + private void incrementProgress(final int increment) { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + int position = progress.getSelection(); + progress.setSelection(position + increment); + } + }); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java new file mode 100644 index 00000000000..59636198ed5 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/TextDisplayHelper.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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.service.control.jobs; + +import org.eclipse.osee.framework.ui.plugin.io.StreamToTextArea; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class TextDisplayHelper { + + private FormattedText formattedText; + private StreamToTextArea errorGobbler; + private StreamToTextArea outputGobbler; + + public TextDisplayHelper(FormattedText formattedText) { + this.formattedText = formattedText; + this.errorGobbler = null; + this.outputGobbler = null; + } + + public void updateScrollBar() { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + formattedText.getStyledText().setSelection(formattedText.getStyledText().getCharCount()); + } + }); + } + + public void addText(final String toDisplay, final int format, final int color, final boolean underline) { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + formattedText.addText(toDisplay, format, color, underline); + } + }); + } + + public void clear() { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + formattedText.clearTextArea(); + } + }); + } + + public FormattedText getFormattedText() { + return formattedText; + } + + public void startProcessHandling(Process process) { + disposeProcessHandling(); + errorGobbler = new StreamToTextArea(process.getErrorStream(), "\t\terr", getFormattedText()); + errorGobbler.setName("ServiceErrorHandler"); + errorGobbler.typeColor(SWT.COLOR_RED); + outputGobbler = new StreamToTextArea(process.getInputStream(), "\t\tout", getFormattedText()); + outputGobbler.setName("ServiceOutputHandler"); + outputGobbler.typeColor(SWT.COLOR_DARK_BLUE); + + errorGobbler.start(); + outputGobbler.start(); + } + + public void disposeProcessHandling() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (errorGobbler != null) { + errorGobbler.setStopped(true); + } + if (outputGobbler != null) { + outputGobbler.setStopped(true); + } + } + }); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java new file mode 100644 index 00000000000..c5af6005441 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/jobs/UploadRemoteFileJob.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * 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.service.control.jobs; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.Map; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.pages.UploadPage.LabelEnum; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.ProgressBar; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.osgi.framework.Bundle; + +import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.SftpException; + +/** + * @author Roberto E. Escobar + */ +public class UploadRemoteFileJob extends Job { + + private ServiceLaunchingInformation serviceInfo; + private TextDisplayHelper display; + private ProgressBar progress; + private Map<LabelEnum, Text> dataMap; + private boolean isUploadDirCreationAllowed; + + public UploadRemoteFileJob(String name, ServiceLaunchingInformation serviceInfo, TextDisplayHelper display, ProgressBar progress, Map<LabelEnum, Text> dataMap) { + super(name); + if (serviceInfo == null) throw new IllegalArgumentException("serviceInfo can not be null"); + if (display == null) throw new IllegalArgumentException("display can not be null"); + if (progress == null) throw new IllegalArgumentException("progress can not be null"); + this.serviceInfo = serviceInfo; + this.display = display; + this.progress = progress; + this.dataMap = dataMap; + this.isUploadDirCreationAllowed = false; + progress.setSelection(0); + progress.setMaximum(0); + progress.setMaximum(5); + } + + private void incrementProgress(final int increment) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + int position = progress.getSelection(); + progress.setSelection(position + increment); + } + }); + } + + private void displayInitMessage(File zipLocation) { + display.clear(); + display.addText("\t\t ----------- Unzip -------------\n\n", SWT.BOLD, SWT.COLOR_BLACK, false); + display.addText("\tFrom Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText(String.format("\t%s\n", zipLocation.getAbsolutePath()), SWT.NORMAL, SWT.COLOR_BLACK, false); + display.addText("\tTo Location: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText(String.format("\t%s://%s\n", serviceInfo.getSelectedHost(), serviceInfo.getUnzipLocation()), + SWT.NORMAL, SWT.COLOR_BLACK, false); + } + + private ChannelSftp getScpConnection() throws Exception { + display.addText("\n\tStarting SCP...", SWT.NORMAL, SWT.COLOR_BLACK, false); + ChannelSftp sftp = this.serviceInfo.getSSHConnection().getScpConnection(); + incrementProgress(1); + return sftp; + } + + private void createRemotePathOrCdIntoIt(IProgressMonitor monitor, ChannelSftp sftp) throws Exception { + if (monitor.isCanceled() != true) { + try { + sftp.cd(serviceInfo.getUnzipLocation()); + } catch (SftpException ex1) { + this.isUploadDirCreationAllowed = false; + Display.getDefault().syncExec(new Runnable() { + public void run() { + Shell shell = Display.getDefault().getActiveShell(); + isUploadDirCreationAllowed = + MessageDialog.openQuestion(shell, "Scp", + "Unable to find remote path. Would you like to create it?"); + } + }); + + if (isUploadDirCreationAllowed == true) { + try { + sftp.mkdir(serviceInfo.getUnzipLocation()); + } catch (SftpException ex2) { + throw new Exception("Unable to create remote path."); + } + } else { + throw new Exception("Unable to find remote path - user selected not to create it."); + } + + } finally { + incrementProgress(1); + } + } + } + + private void uploadFile(IProgressMonitor monitor, ChannelSftp sftp, File fileToUpload) throws Exception { + if (monitor.isCanceled() != true) { + display.addText(String.format("\n\tUploading [%s]", fileToUpload.getAbsolutePath()), SWT.NORMAL, + SWT.COLOR_BLACK, false); + InputStream input = null; + OutputStream output = null; + try { + input = new FileInputStream(fileToUpload); + output = sftp.put(fileToUpload.getName()); + byte[] buffer = new byte[1024]; + int count = -1; + while ((count = input.read(buffer)) != -1) { + output.write(buffer, 0, count); + } + display.addText(String.format("\n\tTransferred [%s] bytes", fileToUpload.length()), SWT.NORMAL, + SWT.COLOR_BLACK, false); + } catch (SftpException ex1) { + throw new Exception("Error uploading file."); + } finally { + incrementProgress(1); + if (input != null) { + input.close(); + } + if (output != null) { + output.close(); + } + } + } + } + + private void unzipRemoteFiles(IProgressMonitor monitor) throws Exception { + if (monitor.isCanceled() != true) { + String toExec = + String.format("cd %s\nunzip -o %s", serviceInfo.getUnzipLocation(), + serviceInfo.getServiceItem().getZipName()); + + display.addText("\n\tUnzip Cmd: ", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + display.addText("\t" + toExec.split("\n")[1] + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); + + String output = this.serviceInfo.getSSHConnection().executeCommandList(toExec.split("\n")); + display.addText("\n\t" + output + "\n", SWT.NORMAL, SWT.COLOR_BLACK, false); + incrementProgress(1); + } + } + + public File getFile(Bundle bundle, String path) throws FileNotFoundException, IOException { + URL url = bundle.getEntry(path); + if (url == null) { + throw new FileNotFoundException("Could not locate the file " + path); + } + try { + url = FileLocator.toFileURL(url); + File file = new File(url.getFile()); + return file; + } catch (Throwable e) { + throw new IOException("Invalid URL format for the URL " + url.toString(), e); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public IStatus run(IProgressMonitor monitor) { + IStatus toReturn = Status.OK_STATUS; + ChannelSftp sftp = null; + try { + Display.getDefault().syncExec(new Runnable() { + public void run() { + serviceInfo.setUnzipLocation(dataMap.get(LabelEnum.Host_Upload_Location).getText()); + } + }); + Bundle bundle = Platform.getBundle(serviceInfo.getServiceItem().getPlugin()); + File zipLocation = getFile(bundle, serviceInfo.getServiceItem().getZipName()); + + displayInitMessage(zipLocation); + + sftp = getScpConnection(); + + createRemotePathOrCdIntoIt(monitor, sftp); + + uploadFile(monitor, sftp, zipLocation); + + unzipRemoteFiles(monitor); + + } catch (Exception ex) { + display.addText(String.format("\n\t%s\n\n", ex.getLocalizedMessage()), SWT.NORMAL, SWT.COLOR_RED, false); + toReturn = new Status(Status.ERROR, ControlPlugin.PLUGIN_PREFERENCE_SCOPE, "Error during upload.", ex); + } finally { + incrementProgress(5); + if (sftp != null) { + sftp.exit(); + sftp.disconnect(); + } + } + + // incrementProgress(1); + // if (true != createDestinationFolder()) { + // incrementProgress(4); + // toReturn = Status.CANCEL_STATUS; + // } else { + + // if (true != toReturn.equals(Status.OK_STATUS)) { + // PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + // public void run() { + // MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Upload Error", + // "Upload of files to remote host failed."); + // } + // }); + // } + return toReturn; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ConnectionManager.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ConnectionManager.java new file mode 100644 index 00000000000..f297619a197 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ConnectionManager.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * 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.service.control.managers; + +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import net.jini.core.lookup.ServiceItem; +import org.eclipse.osee.framework.jini.service.interfaces.IService; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.managers.interfaces.IConnectionListener; +import org.eclipse.osee.framework.ui.service.control.renderer.IServiceRenderer; + +/** + * @author Roberto E. Escobar + */ +public class ConnectionManager { + + private static ConnectionManager instance = null; + private boolean connected; + private ServiceNode connectedTo; + private Class<?> connectionType; + private Collection<IConnectionListener> listeners; + private Map<Class<?>, IServiceRenderer> allowedConnectionTypes; + + private ConnectionManager() { + super(); + this.connected = false; + this.connectedTo = null; + this.connectionType = null; + this.listeners = Collections.synchronizedList(new ArrayList<IConnectionListener>()); + this.allowedConnectionTypes = new HashMap<Class<?>, IServiceRenderer>(); + } + + public static ConnectionManager getInstance() { + if (instance == null) { + instance = new ConnectionManager(); + } + return instance; + } + + public void addConnectionListener(IConnectionListener listener) { + synchronized (listeners) { + listeners.add(listener); + } + listener.onConnectionChanged(connectedTo, connected); + } + + public void removeConnectionListener(IConnectionListener listener) { + synchronized (listeners) { + listeners.remove(listener); + } + } + + private boolean isAbleToConnect(Object service) { + boolean returnVal = true; + if (service instanceof IService) { + try { + ((IService) service).getServiceID(); + } catch (RemoteException e) { + returnVal = false; + } + } + return returnVal; + } + + private void notifyConnected(ServiceNode serviceNode, boolean connected) { + synchronized (listeners) { + for (IConnectionListener listener : listeners) { + listener.onConnectionChanged(serviceNode, connected); + } + } + } + + public void forceDisconnect() { + if (connectedTo != null) { + if (connected) { + handleDisconnect(); + } + } + } + + public void attemptConnection(ServiceNode serviceNode) throws ServiceConnectionException { + if (connectedTo != null) { + ServiceNode temp = connectedTo; + if (connected) { + handleDisconnect(); + } + + if (!temp.getServiceID().equals(serviceNode.getServiceID())) { + handleConnect(serviceNode); + } + } else { + handleConnect(serviceNode); + } + } + + private void handleConnect(ServiceNode node) throws ServiceConnectionException { + if (isAbleToConnect(node.getServiceItem().service)) { + connected = true; + connectedTo = node; + this.connectionType = getConnectionType(node.getServiceItem()); + connectedTo.setConnected(connected); + notifyConnected(connectedTo, connected); + } else { + throw new ServiceConnectionException(); + } + } + + private void handleDisconnect() { + connected = false; + allowedConnectionTypes.get(connectionType).disconnect(); + connectedTo.setConnected(connected); + notifyConnected(connectedTo, connected); + connectionType = null; + connectedTo = null; + } + + public boolean isConnected() { + return connected; + } + + public Class<?> getConnectionType() { + return connectionType; + } + + public Class<?> getConnectionType(ServiceItem serviceItem) { + for (Class<?> connectionType : allowedConnectionTypes.keySet()) { + if (connectionType.isInstance(serviceItem.service)) { + return connectionType; + } + } + return null; + } + + public IServiceRenderer getRenderer() { + return allowedConnectionTypes.get(connectionType); + } + + public boolean isAllowedConnectionType(ServiceItem serviceItem) { + for (Class<?> connectionType : allowedConnectionTypes.keySet()) { + if (connectionType.isInstance(serviceItem.service)) { + return true; + } + } + return false; + } + + public void registerForConnection(Class<?> serviceType, IServiceRenderer renderer) { + allowedConnectionTypes.put(serviceType, renderer); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ContributionManager.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ContributionManager.java new file mode 100644 index 00000000000..3555f23d2b7 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ContributionManager.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * 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.service.control.managers; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.osgi.framework.Bundle; + +/** + * @author Roberto E. Escobar + */ +public class ContributionManager extends ClassLoader { + + private static ContributionManager instance = null; + private Map<String, String> extensionRegistryMap; + private Map<String, Class<?>> classesloaded; // <String, Class> + private List<String> bundleList; // <String> + private Map<String, String> interfaceToRendererMap; + private Map<String, String> interfaceToIconMap; + private Logger logger = ConfigUtil.getConfigFactory().getLogger(ContributionManager.class); + + private ContributionManager() { + super(); + extensionRegistryMap = new HashMap<String, String>(); + interfaceToIconMap = new HashMap<String, String>(); + loadFactoryBundleMap(); + } + + public static ContributionManager getInstance() { + if (instance == null) { + instance = new ContributionManager(); + } + return instance; + } + + // @SuppressWarnings("unchecked") + private void loadFactoryBundleMap() { + interfaceToRendererMap = new HashMap<String, String>(); + classesloaded = new HashMap<String, Class<?>>(); + bundleList = new ArrayList<String>(); + + String registrationStatus = ContributionManager.class.getName() + " Registration: [ \n"; + if (extensionRegistryMap.size() != 0) return; + IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); + if (extensionRegistry != null) { + IExtensionPoint point = + extensionRegistry.getExtensionPoint("org.eclipse.osee.framework.ui.service.control.ServiceView"); + if (point != null) { + IExtension[] extensions = point.getExtensions(); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + String classname = null; + String renderer = null; + String imagePath = null; + String bundleName = null; + for (IConfigurationElement el : elements) { + if (el.getName().equals("ServiceHandler")) { + bundleName = el.getContributor().getName(); + classname = el.getAttribute("ServiceInterface"); + + renderer = el.getAttribute("ServiceRenderer"); + imagePath = el.getAttribute("ServiceIcon"); + + if (classname != null && bundleName != null) { + bundleList.add(el.getContributor().getName()); + extensionRegistryMap.put(classname, bundleName); + + registrationStatus += "[" + bundleName + "] [" + classname + "] "; + + if (renderer != null) { + extensionRegistryMap.put(renderer, bundleName); + interfaceToRendererMap.put(classname, renderer); + registrationStatus += "[" + renderer + "]"; + } + + if (imagePath != null) { + extensionRegistryMap.put(imagePath, bundleName); + interfaceToIconMap.put(classname, imagePath); + + registrationStatus += " [" + imagePath + "]\n"; + } else { + registrationStatus += "\n"; + } + } + } + } + } + } + } + logger.log(Level.INFO, registrationStatus + "]\n"); + } + + public Map<String, String> getInterfaceToRendererMap() { + return interfaceToRendererMap; + } + + public Map<String, String> getInterfaceToIconMap() { + return interfaceToIconMap; + } + + protected synchronized Class<?> findClass(String classname) throws ClassNotFoundException { + Class<?> loadedclass = classesloaded.get(classname); + if (loadedclass != null) { + return loadedclass; + } + + if (extensionRegistryMap.containsKey(classname)) { + String bundleName = (String) extensionRegistryMap.get(classname); + Bundle bundle = Platform.getBundle(bundleName); + try { + Class<?> foundclass = bundle.loadClass(classname); + if (foundclass != null) { + classesloaded.put(classname, foundclass); + return foundclass; + } + } catch (Exception ex) { + } + } + + for (int i = 0; i < bundleList.size(); i++) { + try { + Class<?> foundclass = Platform.getBundle((String) bundleList.get(i)).loadClass(classname); + if (foundclass != null) { + String bundleName = bundleList.remove(i); + bundleList.add(0, bundleName); + } + if (!classesloaded.containsKey(classname)) { + classesloaded.put(classname, foundclass); + } + return foundclass; + + } catch (Exception ex) { + // Do nothing + } + } + return super.findClass(classname); + } + + public ImageDescriptor getImageDescriptor(String imageFilePath) { + if (imageFilePath != null && extensionRegistryMap.containsKey(imageFilePath)) { + String bundleName = (String) extensionRegistryMap.get(imageFilePath); + Bundle bundle = Platform.getBundle(bundleName); + if (bundle != null) { + + // look for the image (this will check both the plug-in and fragment folders + URL fullPathString = FileLocator.find(bundle, new Path(imageFilePath), null); + if (fullPathString == null) { + try { + fullPathString = new URL(imageFilePath); + } catch (MalformedURLException e) { + return null; + } + } + + if (fullPathString != null) { + return ImageDescriptor.createFromURL(fullPathString); + } + } + } + return null; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ReggieCache.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ReggieCache.java new file mode 100644 index 00000000000..d67f893791e --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ReggieCache.java @@ -0,0 +1,255 @@ +/******************************************************************************* + * 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.service.control.managers; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.jini.core.discovery.LookupLocator; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceMatches; +import net.jini.core.lookup.ServiceRegistrar; +import net.jini.core.lookup.ServiceTemplate; +import net.jini.discovery.DiscoveryEvent; +import net.jini.discovery.DiscoveryListener; +import net.jini.discovery.LookupDiscoveryManager; +import net.jini.lookup.ServiceDiscoveryManager; + +import org.eclipse.osee.framework.jini.discovery.IRegistrarListener; +import org.eclipse.osee.framework.jini.discovery.RelaxedSecurity; +import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; + +public class ReggieCache implements DiscoveryListener { + + private static ReggieCache theInstance = null; + private static Logger logger = Logger.getLogger(ReggieCache.class.getName()); + + private Set<IRegistrarListener> registrarListeners; + private Set<String> locators; + private Map<ServiceID, ServiceRegistrar> serviceRegistrars; + private LookupDiscoveryManager lookupDiscoveryManager; + private ServiceDiscoveryManager serviceDiscoveryManager; + + private ClassLoader loader; + + private ReggieCache(ClassLoader loader) { + this.loader = loader; + registrarListeners = Collections.synchronizedSet(new HashSet<IRegistrarListener>()); + serviceRegistrars = Collections.synchronizedMap(new HashMap<ServiceID, ServiceRegistrar>()); + locators = Collections.synchronizedSet(new HashSet<String>()); + + Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); + System.setSecurityManager(new RelaxedSecurity()); + registerWithJINI(); + } + + private void registerWithJINI() { + try { + LookupLocator[] locator = null; + lookupDiscoveryManager = new LookupDiscoveryManager(null, locator, this); + serviceDiscoveryManager = new ServiceDiscoveryManager(lookupDiscoveryManager, null); + } catch (RemoteException anRE) { + System.err.println("Failed to setup cache - exiting"); + anRE.printStackTrace(System.err); + System.exit(-1); + } catch (IOException anIOE) { + System.err.println("Failed to setup managers - exiting"); + anIOE.printStackTrace(System.err); + System.exit(-1); + } + } + + public static ReggieCache getEclipseInstance(ClassLoader loader) { + if (theInstance == null) { + if (loader == null) { + loader = ReggieCache.class.getClassLoader(); + } + theInstance = new ReggieCache(loader); + } + return theInstance; + } + + private class LookupList extends Thread { + + private String[] lookupLocations; + + public LookupList(String[] lookupLocations) { + this.lookupLocations = lookupLocations; + System.setSecurityManager(new RelaxedSecurity()); + } + + public void run() { + Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); + System.setSecurityManager(new RelaxedSecurity()); + try { + if (lookupLocations != null) { + LookupLocator[] locators = new LookupLocator[lookupLocations.length]; + for (int i = 0; i < locators.length; i++) { + locators[i] = new LookupLocator(lookupLocations[i]); + } + List<LookupLocator> locatorList = new ArrayList<LookupLocator>(); + for (int i = 0; i < locators.length; i++) { + try { + ServiceRegistrar reg = locators[i].getRegistrar(5000); + if (reg != null) { + locatorList.add(locators[i]); + } + } catch (Exception ex) { + System.out.println(); + } + } + lookupDiscoveryManager.addLocators(locatorList.toArray(new LookupLocator[locatorList.size()])); + } + } catch (MalformedURLException ex) { + logger.log(Level.SEVERE, ex.getMessage(), ex); + } + } + } + + public void addListener(IRegistrarListener listener) { + synchronized (registrarListeners) { + registrarListeners.add(listener); + // Notify the listener of all existing services that match + Iterator<IRegistrarListener> it = registrarListeners.iterator(); + while (it.hasNext()) { + IRegistrarListener reggie = it.next(); + reggie.reggieAdded(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); + } + } + } + + public void removeListener(IRegistrarListener listener) { + synchronized (registrarListeners) { + registrarListeners.remove(listener); + } + } + + public void discovered(DiscoveryEvent arg0) { + synchronized (serviceRegistrars) { + ServiceRegistrar[] reggies = arg0.getRegistrars(); + for (int i = 0; i < reggies.length; i++) { + + Object last = serviceRegistrars.put(reggies[i].getServiceID(), reggies[i]); + + synchronized (registrarListeners) { + if (last == null) { + Iterator<IRegistrarListener> it = registrarListeners.iterator(); + while (it.hasNext()) { + IRegistrarListener reggie = it.next(); + reggie.reggieAdded(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); + } + } else { + Iterator<IRegistrarListener> it = registrarListeners.iterator(); + while (it.hasNext()) { + IRegistrarListener reggie = it.next(); + reggie.reggieChanged(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); + } + } + } + } + } + + } + + public void discarded(DiscoveryEvent arg0) { + synchronized (serviceRegistrars) { + ServiceRegistrar[] reggies = arg0.getRegistrars(); + for (int i = 0; i < reggies.length; i++) { + + Object removedObject = serviceRegistrars.remove(reggies[i].getServiceID()); + if (removedObject == null) { + synchronized (registrarListeners) { + Iterator<IRegistrarListener> it = registrarListeners.iterator(); + while (it.hasNext()) { + IRegistrarListener reggie = it.next(); + reggie.reggieRemoved(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); + } + } + } + } + } + } + + public Map<ServiceID, ServiceRegistrar> getServiceRegistrars() { + return serviceRegistrars; + } + + public Set<String> getAvailableJiniGroups() { + Set<String> toReturn = new TreeSet<String>(); + synchronized (serviceRegistrars) { + for (ServiceRegistrar reggie : getServiceRegistrars().values()) { + try { + String[] groups = reggie.getGroups(); + for (String group : groups) { + toReturn.add(group); + } + } catch (RemoteException ex) { + } + } + } + return toReturn; + } + + public ServiceMatches lookupAllServices(ServiceRegistrar reggie) throws RemoteException { + Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); + ServiceTemplate st = new ServiceTemplate(null, null, null); + return reggie.lookup(st, Integer.MAX_VALUE); + } + + public void addLookupLocators(String[] lookups) { + Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); + for (int i = 0; i < lookups.length; i++) { + locators.add(lookups[i]); + } + + Thread thread = new LookupList(lookups); + thread.setContextClassLoader(ExportClassLoader.getInstance()); + thread.start(); + } + + public void terminate() { + lookupDiscoveryManager.terminate(); + serviceDiscoveryManager.terminate(); + } + + public void refresh() { + lookupDiscoveryManager.removeDiscoveryListener(this); + serviceRegistrars.clear(); + Iterator<IRegistrarListener> it = registrarListeners.iterator(); + while (it.hasNext()) { + IRegistrarListener reggie = it.next(); + reggie.reggieRemoved(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); + } + + registerWithJINI(); + + String[] locatorsArray = new String[locators.size()]; + int index = 0; + Iterator<String> iterator = locators.iterator(); + while (iterator.hasNext()) { + locatorsArray[index++] = iterator.next(); + } + addLookupLocators(locatorsArray); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServiceConnectionException.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServiceConnectionException.java new file mode 100644 index 00000000000..2504d2ca3d9 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServiceConnectionException.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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.service.control.managers; + +public class ServiceConnectionException extends Exception { + + private static final long serialVersionUID = 7224215322283659226L; + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServiceTreeBuilder.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServiceTreeBuilder.java new file mode 100644 index 00000000000..87a5f7b00cd --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServiceTreeBuilder.java @@ -0,0 +1,220 @@ +/******************************************************************************* + * 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.service.control.managers; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceItem; + +import org.eclipse.osee.framework.jdk.core.type.InputManager; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.eclipse.osee.framework.jdk.core.type.TreeObject; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.data.CategoryParent; +import org.eclipse.osee.framework.ui.service.control.data.GroupParent; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNodeFactory; + +/** + * @author Roberto E. Escobar + */ +public class ServiceTreeBuilder { + + private static ServiceNodeFactory serviceNodeFactory = null; + private InputManager<TreeParent> inputManager; + private Map<ServiceID, ServiceItem> map; + + public ServiceTreeBuilder() { + serviceNodeFactory = ServiceNodeFactory.getInstance(); + this.inputManager = new InputManager<TreeParent>(); + this.map = Collections.synchronizedMap(new HashMap<ServiceID, ServiceItem>()); + } + + private Set<GroupParent> findGroup(ServiceNode serviceNode) { + Set<GroupParent> toReturn = new HashSet<GroupParent>(); + List<TreeParent> nodes = inputManager.getInputList(); + for (TreeParent node : nodes) { + if (node instanceof GroupParent) { + GroupParent groupParent = ((GroupParent) node); + if (serviceNode.isMemberOf(groupParent.getName())) { + if (!toReturn.contains(groupParent)) { + toReturn.add(groupParent); + } + } + } + } + return toReturn; + } + + private CategoryParent findCategory(GroupParent groupParent, ServiceNode serviceNode) { + if (groupParent != null && groupParent.hasChildren()) { + TreeObject[] children = groupParent.getChildren(); + for (TreeObject child : children) { + if (child instanceof CategoryParent) { + CategoryParent categoryParent = ((CategoryParent) child); + if (categoryParent.getName().equals(serviceNode.getName())) { + return categoryParent; + } + } + } + } + return null; + } + + private Pair<CategoryParent, ServiceNode> findService(GroupParent groupParent, ServiceNode searchNode) { + CategoryParent category = findCategory(groupParent, searchNode); + if (category != null && category.hasChildren()) { + TreeObject[] children = category.getChildren(); + for (TreeObject child : children) { + if (child instanceof ServiceNode) { + ServiceNode serviceNode = ((ServiceNode) child); + if (serviceNode.getServiceID().equals(searchNode.getServiceID())) { + return new Pair<CategoryParent, ServiceNode>(category, serviceNode); + } + } + } + } + return null; + } + + public void serviceAdded(ServiceItem serviceItem) { + ServiceID serviceId = serviceItem.serviceID; + // System.out.println("Service Added: " + serviceId); + synchronized (map) { + if (!map.containsKey(serviceId)) { + map.put(serviceId, serviceItem); + + ServiceNode serviceNode = serviceNodeFactory.createServiceNode(serviceId, serviceItem); + Set<GroupParent> groupParents = findGroup(serviceNode); + Set<String> existingGroupNames = new TreeSet<String>(); + + if (groupParents.size() > 0) { + for (GroupParent groupParent : groupParents) { + if (!existingGroupNames.contains(groupParent.getName())) { + existingGroupNames.add(groupParent.getName()); + } +// CategoryParent categoryParent = findCategory(groupParent, serviceNode); +// if (categoryParent == null) { +// categoryParent = new CategoryParent(serviceNode.getName()); +// groupParent.addChild(categoryParent); +// categoryParent.addChild(serviceNode); +// } else { + Pair<CategoryParent, ServiceNode> node = findService(groupParent, serviceNode); + if (node != null) { + node.getValue().setServiceItem(serviceItem); + } else { + groupParent.addChild(serviceNode); + } +// } + } + inputManager.inputChanged(); + } + + for (String group : serviceNode.getGroups()) { + if (!existingGroupNames.contains(group)) { + GroupParent groupParent = new GroupParent(group); +// CategoryParent categoryParent = new CategoryParent(serviceNode.getName()); + groupParent.addChild(serviceNode); +// categoryParent.addChild(serviceNode); + inputManager.addNode(groupParent); + } + } + } + } + } + + public void serviceChanged(ServiceItem serviceItem) { + synchronized (map) { + boolean handleAsServiceAddedEvent = false; + ServiceID serviceId = serviceItem.serviceID; + // System.out.println("Service Changed: " + serviceId); + if (map.containsKey(serviceId)) { + map.put(serviceId, serviceItem); + + ServiceNode serviceNode = serviceNodeFactory.createServiceNode(serviceId, serviceItem); + Set<GroupParent> groupParents = findGroup(serviceNode); + Set<String> existingGroupNames = new TreeSet<String>(); + if (groupParents.size() > 0) { + for (GroupParent groupParent : groupParents) { + if (!existingGroupNames.contains(groupParent.getName())) { + existingGroupNames.add(groupParent.getName()); + } + Pair<CategoryParent, ServiceNode> node = findService(groupParent, serviceNode); + if (node != null) { + node.getValue().setServiceItem(serviceItem); + inputManager.inputChanged(); + } else { + handleAsServiceAddedEvent = true; + } + } + } + + for (String group : serviceNode.getGroups()) { + if (!existingGroupNames.contains(group)) { + handleAsServiceAddedEvent = true; + break; + } + } + } else { + handleAsServiceAddedEvent = true; + } + + if (handleAsServiceAddedEvent) { + serviceAdded(serviceItem); + } + } + } + + public void serviceRemoved(ServiceItem serviceItem) { + synchronized (map) { + ServiceID serviceId = serviceItem.serviceID; + // System.out.println("Service Removed: " + serviceId); + if (map.containsKey(serviceId)) { + ServiceNode serviceNode = serviceNodeFactory.createServiceNode(serviceId, serviceItem); + Set<GroupParent> groupParents = findGroup(serviceNode); + if (groupParents.size() > 0) { + for (GroupParent groupParent : groupParents) { + Pair<CategoryParent, ServiceNode> node = findService(groupParent, serviceNode); + if (node != null) { + node.getKey().removeChild(node.getValue()); + if (!node.getKey().hasChildren()) { + groupParent.removeChild(node.getKey()); + } + inputManager.inputChanged(); + } + if (!groupParent.hasChildren()) { + inputManager.removeNode(groupParent); + } + } + } + map.remove(serviceId); + } + } + } + + public void clear() { + synchronized (map) { + map.clear(); + inputManager.removeAll(); + } + } + + public InputManager<TreeParent> getInputManager() { + return inputManager; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServicesManager.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServicesManager.java new file mode 100644 index 00000000000..8b5a2f2399a --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/ServicesManager.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.service.control.managers; + +import org.eclipse.osee.framework.jdk.core.type.InputManager; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.jini.discovery.EclipseJiniClassloader; +import org.eclipse.osee.framework.jini.discovery.IServiceLookupListener; +import org.eclipse.osee.framework.jini.discovery.ServiceDataStore; +import net.jini.core.lookup.ServiceItem; + +/** + * @author Roberto E. Escobar + */ +public class ServicesManager implements IServiceLookupListener { + + private static ServicesManager instance = null; + private ServiceTreeBuilder servicesTreeBuilder; + + private ServicesManager() { + super(); + servicesTreeBuilder = new ServiceTreeBuilder(); + ServiceDataStore.getEclipseInstance(EclipseJiniClassloader.getInstance()).addListener(this); + } + + public static ServicesManager getInstance() { + if (instance == null) { + instance = new ServicesManager(); + } + return instance; + } + + public void serviceAdded(ServiceItem serviceItem) { + servicesTreeBuilder.serviceAdded(serviceItem); + } + + public void serviceChanged(ServiceItem serviceItem) { + servicesTreeBuilder.serviceChanged(serviceItem); + } + + public void serviceRemoved(ServiceItem serviceItem) { + servicesTreeBuilder.serviceRemoved(serviceItem); + } + + public void clear() { + servicesTreeBuilder.clear(); + } + + public InputManager<TreeParent> getInputManager() { + return servicesTreeBuilder.getInputManager(); + } + + public void dispose() { + ServiceDataStore.getEclipseInstance(EclipseJiniClassloader.getInstance()).removeListener(this); + servicesTreeBuilder.clear(); + servicesTreeBuilder.getInputManager().dispose(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/interfaces/IConnectionListener.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/interfaces/IConnectionListener.java new file mode 100644 index 00000000000..f221336b6e6 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/managers/interfaces/IConnectionListener.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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.service.control.managers.interfaces; + +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; + +/** + * @author Roberto E. Escobar + */ +public interface IConnectionListener { + + public void onConnectionChanged(ServiceNode serviceNode, boolean connected); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/menu/MenuBuilder.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/menu/MenuBuilder.java new file mode 100644 index 00000000000..983405609e3 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/menu/MenuBuilder.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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.service.control.menu; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.part.ViewPart; + +/** + * @author Roberto E. Escobar + */ +public class MenuBuilder { + + private ViewPart view; + private List<Action> actions; + + public MenuBuilder(ViewPart view) { + this.view = view; + this.actions = new ArrayList<Action>(); + } + + public void addAction(Action action) { + actions.add(action); + } + + public void createPopUpMenu(Viewer viewer) { + MenuManager menuManager = new MenuManager("#PopupMenu"); + menuManager.setRemoveAllWhenShown(true); + menuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + MenuBuilder.this.fillMenu(manager); + } + }); + + registerPopup(menuManager, viewer); + } + + private void registerPopup(MenuManager menuManager, Viewer viewer) { + Control control = viewer.getControl(); + Menu menu = menuManager.createContextMenu(control); + control.setMenu(menu); + + view.getSite().registerContextMenu(menuManager, viewer); + } + + public void contributeToActionBars() { + IActionBars bars = view.getViewSite().getActionBars(); + fillMenu(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillMenu(IMenuManager manager) { + int count = 0; + for (Action action : actions) { + count++; + manager.add(action); + if (count == 2) { + manager.add(new Separator()); + } + } + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void fillLocalToolBar(IToolBarManager manager) { + int count = 0; + for (Action action : actions) { + count++; + manager.add(action); + if (count == 2) { + break; + } + } + manager.add(new Separator()); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/menu/ServiceManagerMenuItem.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/menu/ServiceManagerMenuItem.java new file mode 100644 index 00000000000..46053c8a562 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/menu/ServiceManagerMenuItem.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.service.control.menu; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.osee.framework.ui.service.control.view.ServiceManagerView; +import org.eclipse.osee.framework.ui.skynet.util.OSEELog; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class ServiceManagerMenuItem implements IWorkbenchWindowActionDelegate { + + public void dispose() { + } + + public void init(IWorkbenchWindow window) { + } + + public void run(IAction action) { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + page.showView(ServiceManagerView.VIEW_ID); + } catch (PartInitException ex) { + OSEELog.logException(getClass(), ex, true); + } + } + + public void selectionChanged(IAction action, ISelection selection) { + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/IRenderer.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/IRenderer.java new file mode 100644 index 00000000000..a9f2f591444 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/IRenderer.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * 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.service.control.renderer; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public interface IRenderer { + + public Control renderInComposite(Composite parent); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/IServiceRenderer.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/IServiceRenderer.java new file mode 100644 index 00000000000..48ce38f130b --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/IServiceRenderer.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.service.control.renderer; + +import net.jini.core.lookup.ServiceItem; + +public interface IServiceRenderer extends IRenderer { + + public abstract void refresh(); + + public abstract void setService(ServiceItem serviceItem); + + public abstract void disconnect(); + + public abstract void dispose(); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/ReggieItemHandler.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/ReggieItemHandler.java new file mode 100644 index 00000000000..ce1b17c70d9 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/ReggieItemHandler.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * 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.service.control.renderer; + +import java.rmi.RemoteException; +import java.util.Set; +import java.util.TreeSet; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public class ReggieItemHandler implements IRenderer { + + private static final Set<String> allowedGroups = new TreeSet<String>();; + + static { + populteAllowedGroups(); + } + + private int port; + private String host; + private ServiceID id; + private String className; + private String[] groups; + + public ReggieItemHandler(ServiceRegistrar reggie) { + super(); + parseReggie(reggie); + } + + public String getClassName() { + return className; + } + + public String[] getGroups() { + return groups; + } + + public String getHost() { + return host; + } + + public ServiceID getId() { + return id; + } + + public int getPort() { + return port; + } + + public Control renderInComposite(Composite parent) { + if (parent instanceof FormattedText) { + FormattedText textArea = (FormattedText) parent; + textArea.clearTextArea(); + textArea.addText("\t" + "Service" + ": ", SWT.BOLD, SWT.COLOR_DARK_BLUE); + textArea.addText(className + "\n", SWT.NORMAL, SWT.COLOR_BLACK); + + textArea.addText("\t" + "Host" + ": ", SWT.BOLD, SWT.COLOR_DARK_BLUE); + textArea.addText(host + "\n", SWT.NORMAL, SWT.COLOR_BLACK); + + textArea.addText("\t" + "Port" + ": ", SWT.BOLD, SWT.COLOR_DARK_BLUE); + textArea.addText(port + "\n", SWT.NORMAL, SWT.COLOR_BLACK); + + textArea.addText("\t" + "Groups" + ": ", SWT.BOLD, SWT.COLOR_DARK_BLUE); + + String groupsToDisplay = ""; + if (groups != null) { + for (int index = 0; index < groups.length; index++) { + String group = groups[index]; + groupsToDisplay += (group != null && group.length() > 0 ? group : "Public"); + if (index + 1 < groups.length) { + groupsToDisplay += ", "; + } + } + } + + textArea.addText("{" + groupsToDisplay + "}\n", SWT.BOLD, SWT.COLOR_DARK_GREEN); + textArea.addText("\t" + "ID" + ": ", SWT.BOLD, SWT.COLOR_DARK_BLUE); + textArea.addText(id + "\n", SWT.NORMAL, SWT.COLOR_BLACK); + } + return parent; + } + + private void parseReggie(ServiceRegistrar reggie) { + try { + className = reggie.getLocator().getClass().getName(); + port = reggie.getLocator().getPort(); + host = reggie.getLocator().getHost(); + id = reggie.getServiceID(); + groups = reggie.getGroups(); + } catch (RemoteException ex) { + ex.printStackTrace(); + } + } + + private static void populteAllowedGroups() { + allowedGroups.clear(); + String[] tempGroups = ConfigUtil.getConfigFactory().getOseeConfig().getJiniServiceGroups(); + for (String toStore : tempGroups) { + if (!allowedGroups.contains(toStore)) { + allowedGroups.add(toStore); + } + } + } + + public static boolean isAllowed(ServiceRegistrar reggie) { + try { + return isAllowed(reggie.getGroups()); + } catch (RemoteException ex) { + ex.printStackTrace(); + } + return false; + } + + private static boolean isAllowed(String[] groups) { + if (groups != null) { + for (String toCheck : groups) { + if (allowedGroups.contains(toCheck)) { + return true; + } + } + } + return false; + } + + public static Set<String> getAllowedGroups() { + return allowedGroups; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/ServiceItemHandler.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/ServiceItemHandler.java new file mode 100644 index 00000000000..8d2e2f10908 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/renderer/ServiceItemHandler.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * 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.service.control.renderer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.jini.core.entry.Entry; +import net.jini.core.lookup.ServiceItem; +import net.jini.lookup.entry.Comment; +import net.jini.lookup.entry.Name; +import net.jini.lookup.entry.ServiceInfo; + +import org.eclipse.osee.framework.jdk.core.util.StringFormat; +import org.eclipse.osee.framework.jini.service.core.FormmatedEntry; +import org.eclipse.osee.framework.jini.service.core.GroupEntry; +import org.eclipse.osee.framework.jini.service.core.OwnerEntry; +import org.eclipse.osee.framework.jini.service.core.PropertyEntry; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public class ServiceItemHandler implements IRenderer { + + List<ItemRecord> serviceRecords; + + public ServiceItemHandler(ServiceItem serviceItem) { + serviceRecords = new ArrayList<ItemRecord>(); + parseServiceItem(serviceItem); + } + + private class ItemEntry { + String value; + private int style; + private int color; + + public ItemEntry(String value, int style, int color) { + this.value = value; + this.style = style; + this.color = color; + } + + public int getColor() { + return color; + } + + public int getStyle() { + return style; + } + + public String getValue() { + return value; + } + } + + private class ItemRecord { + private ItemEntry label; + private ItemEntry data; + + public ItemRecord(String label, String data) { + this(label, SWT.BOLD, SWT.COLOR_DARK_BLUE, data, SWT.NORMAL, SWT.COLOR_BLACK); + } + + public ItemRecord(String label, int labelStyle, int labelColor, String data) { + this(label, labelStyle, labelColor, data, SWT.NORMAL, SWT.COLOR_BLACK); + } + + public ItemRecord(String label, String data, int dataStyle, int dataColor) { + this(label, SWT.BOLD, SWT.COLOR_DARK_BLUE, data, dataStyle, dataColor); + } + + public ItemRecord(String label, int labelStyle, int labelColor, String data, int dataStyle, int dataColor) { + this.label = new ItemEntry(label, labelStyle, labelColor); + this.data = new ItemEntry(data, dataStyle, dataColor); + } + + public String getData() { + return data.getValue(); + } + + public String getLabel() { + return label.getValue(); + } + + public int getDataColor() { + return data.getColor(); + } + + public int getDataStyle() { + return data.getStyle(); + } + + public int getLabelColor() { + return label.getColor(); + } + + public int getLabelStyle() { + return label.getStyle(); + } + } + + public void parseServiceItem(ServiceItem serviceItem) { + serviceRecords.clear(); + if (serviceItem != null) { + String additionalInfo = ""; + Entry[] entries = serviceItem.attributeSets; + for (int i = 0; i < entries.length; i++) { + if (entries[i] instanceof Name) { + serviceRecords.add(new ItemRecord("Name", ((Name) entries[i]).name)); + } else if (entries[i] instanceof Comment) { + serviceRecords.add(new ItemRecord("Comment", ((Comment) entries[i]).comment)); + } else if (entries[i] instanceof OwnerEntry) { + serviceRecords.add(new ItemRecord("Owner", ((OwnerEntry) entries[i]).getOwner())); + } else if (entries[i] instanceof GroupEntry) { + String[] groups = ((GroupEntry) entries[i]).group; + serviceRecords.add(new ItemRecord("Group", + "{ " + ((groups == null) ? "" : StringFormat.commaSeparate(groups)) + " }", SWT.BOLD, + SWT.COLOR_DARK_GREEN)); + } else if (entries[i] instanceof FormmatedEntry) { + additionalInfo += ((FormmatedEntry) entries[i]).getFormmatedString(); + } else if (entries[i] instanceof ServiceInfo) { + ServiceInfo info = (ServiceInfo) entries[i]; + serviceRecords.add(new ItemRecord("Info Name", info.name)); + serviceRecords.add(new ItemRecord("Manufacturer", info.manufacturer)); + serviceRecords.add(new ItemRecord("Model", info.model)); + serviceRecords.add(new ItemRecord("Version", info.version)); + serviceRecords.add(new ItemRecord("SerialNumber", info.serialNumber)); + } else if (entries[i] instanceof PropertyEntry){ + PropertyEntry info = (PropertyEntry) entries[i]; + String[] keys = info.map.keySet().toArray(new String[info.map.keySet().size()]); + Arrays.sort(keys); + for(String key:keys){ + serviceRecords.add(new ItemRecord(key, info.map.get(key).toString())); + } + } + } + + if (entries.length == 0) { + String label = ""; + try { + label = serviceItem.service.getClass().getName(); + } catch (Exception ex) { + label = "nullpointerexception"; + } + serviceRecords.add(new ItemRecord("Name", label)); + } + if (!additionalInfo.equals("")) { + serviceRecords.add(new ItemRecord("Additional Info", additionalInfo)); + } + serviceRecords.add(new ItemRecord("ID", serviceItem.serviceID.toString())); + } + } + + public List<ItemRecord> getData() { + return this.serviceRecords; + } + + public Control renderInComposite(Composite parent) { + if (parent instanceof FormattedText) { + FormattedText textArea = (FormattedText) parent; + textArea.clearTextArea(); + + for (ItemRecord record : serviceRecords) { + String label = record.getLabel(); + String data = record.getData(); + if (label.equals("Additional Info")) { + String[] temp = data.split("\n"); + + textArea.addText("\t" + label + ": \n", record.getLabelStyle(), record.getLabelColor()); + + for (String innerRecord : temp) { + String[] array = innerRecord.split(":", 2); + for (int i = 0; i < array.length; i++) { + textArea.addText("\t\t\t" + array[i] + ": ", SWT.BOLD, SWT.COLOR_DARK_BLUE); + if (i + 1 < array.length) { + textArea.addText(" " + array[++i] + "\n", SWT.NORMAL, SWT.COLOR_BLACK); + } + } + } + } else { + textArea.addText("\t" + label + ": ", record.getLabelStyle(), record.getLabelColor()); + textArea.addText(data + "\n", record.getDataStyle(), record.getDataColor()); + } + } + } + return parent; + } + + public String toString() { + String toReturn = ""; + for (ItemRecord record : serviceRecords) { + String label = record.getLabel(); + String data = record.getData(); + if (label.equals("Additional Info")) { + String[] temp = data.split("\n"); + toReturn += label + ": \n"; + for (String innerRecord : temp) { + toReturn += "\t" + innerRecord + "\n"; + } + } else { + toReturn += label + ": " + data + "\n"; + } + } + return toReturn; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/view/ServiceManagerView.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/view/ServiceManagerView.java new file mode 100644 index 00000000000..d161b3fe897 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/view/ServiceManagerView.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * 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.service.control.view; + +import org.eclipse.osee.framework.jdk.core.util.StringFormat; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.actions.HideLookupsAction; +import org.eclipse.osee.framework.ui.service.control.actions.KillServiceAction; +import org.eclipse.osee.framework.ui.service.control.actions.OpenLaunchWizard; +import org.eclipse.osee.framework.ui.service.control.actions.RefreshDataStore; +import org.eclipse.osee.framework.ui.service.control.menu.MenuBuilder; +import org.eclipse.osee.framework.ui.service.control.widgets.ManagerMain; +import org.eclipse.osee.framework.ui.skynet.ats.IActionable; +import org.eclipse.osee.framework.ui.skynet.ats.OseeAts; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; + +/** + * @author Roberto E. Escobar + */ +public class ServiceManagerView extends ViewPart implements IActionable { + + public static final String VIEW_ID = "org.eclipse.osee.framework.ui.service.control.view.ServiceManagerView"; + private ManagerMain managerMain; + + public void createPartControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + managerMain = new ManagerMain(composite, SWT.NONE); + + createServicesViewerPopUp(); + createLookupViewerPopUp(); + + this.setContentDescription("Jini Groups { " + StringFormat.commaSeparate(ConfigUtil.getConfigFactory().getOseeConfig().getJiniServiceGroups()) + " }"); + + OseeAts.addBugToViewToolbar(this, this, ControlPlugin.getInstance(), VIEW_ID, "Service Manager"); + } + + private void createServicesViewerPopUp() { + MenuBuilder menuBuilder = new MenuBuilder(this); + menuBuilder.addAction(new OpenLaunchWizard(managerMain)); + menuBuilder.addAction(new RefreshDataStore(managerMain)); + menuBuilder.addAction(new KillServiceAction(managerMain)); + menuBuilder.contributeToActionBars(); + menuBuilder.createPopUpMenu(managerMain.getServicesViewer().getViewer()); + } + + private void createLookupViewerPopUp() { + MenuBuilder menuBuilder = new MenuBuilder(this); + menuBuilder.addAction(new HideLookupsAction(managerMain)); + menuBuilder.addAction(new RefreshDataStore(managerMain)); + menuBuilder.createPopUpMenu(managerMain.getLookupViewer().getViewer()); + } + + public String getActionDescription() { + return ""; + } + + @Override + public void dispose() { + super.dispose(); + if (managerMain != null) { + managerMain.dispose(); + } + + } + + @Override + public void setFocus() { + managerMain.setFocus(); + } +}
\ No newline at end of file diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/IServiceManager.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/IServiceManager.java new file mode 100644 index 00000000000..510ba94bc0f --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/IServiceManager.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.service.control.widgets; + +import org.eclipse.osee.framework.jdk.core.type.InputManager; +import org.eclipse.osee.framework.ui.swt.FormattedText; + +/** + * @author Roberto E. Escobar + */ +public interface IServiceManager<T> { + + public FormattedText getQuickViewer(); + + public ServicesViewer getServicesViewer(); + + public LookupViewer getLookupViewer(); + + public InputManager<T> getInputManager(); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java new file mode 100644 index 00000000000..8ce96faf595 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/LookupViewer.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * 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.service.control.widgets; + +import java.rmi.RemoteException; +import java.util.Collection; +import java.util.Map; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceRegistrar; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.osee.framework.ui.service.control.renderer.ReggieItemHandler; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +/** + * @author Roberto E. Escobar + */ +public class LookupViewer extends Composite { + + private static final Image LOOK_UP_IMAGE = ControlPlugin.getInstance().getImage("connection.gif"); + private static final Image DISCONNECTED_IMAGE = ControlPlugin.getInstance().getImage("disconnected.gif"); + + private StructuredViewer viewer; + private Map<ServiceID, IRenderer> handlerMap; + + public LookupViewer(Composite parent, int style) { + super(parent, style); + createControl(); + } + + private void createControl() { + this.setLayout(new GridLayout()); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + viewer = new TableViewer(this, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + viewer.setLabelProvider(new ListLabelProvider()); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setSorter(new ViewerSorter()); + viewer.setInput(new String[0]); + } + + public void refresh() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + viewer.refresh(); + } + }); + } + + public void setSelection(final String serviceId) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + Table table = ((TableViewer) viewer).getTable(); + TableItem[] items = table.getItems(); + for (TableItem item : items) { + Object object = item.getData(); + if (object instanceof ServiceRegistrar) { + if (((ServiceRegistrar) object).getServiceID().toString().equals(serviceId)) { + table.setSelection(new TableItem[] {item}); + return; + } + } + } + } + }); + } + + public StructuredViewer getViewer() { + return viewer; + } + + public void setInput(Collection<?> input) { + viewer.setInput(input); + } + + public void setRendererMap(Map<ServiceID, IRenderer> map) { + this.handlerMap = map; + } + + public IRenderer getRenderer(ServiceID serviceId) { + if (handlerMap != null) { + return handlerMap.get(serviceId); + } else { + return null; + } + } + + private class ListLabelProvider extends LabelProvider { + + public Image getImage(Object element) { + if (element instanceof ServiceRegistrar) { + if (ReggieItemHandler.isAllowed((ServiceRegistrar) element)) { + return LOOK_UP_IMAGE; + } else { + return DISCONNECTED_IMAGE; + } + } + return null; + } + + public String getText(Object element) { + if (element instanceof ServiceRegistrar) { + ServiceRegistrar reggie = (ServiceRegistrar) element; + try { + return " Jini Lookup: " + reggie.getLocator().getHost() + " : " + reggie.getLocator().getPort(); + } catch (RemoteException ex) { + ex.printStackTrace(); + return "Jini Lookup: " + "UNABLE TO LOCATE"; + } + } + return ""; + } + } + + public void dispose() { + viewer.getControl().dispose(); + } +}
\ No newline at end of file diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ManagerMain.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ManagerMain.java new file mode 100644 index 00000000000..1e70084a1ed --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ManagerMain.java @@ -0,0 +1,260 @@ +/******************************************************************************* + * 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.service.control.widgets; + +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.osee.framework.jdk.core.type.InputManager; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; +import org.eclipse.osee.framework.ui.service.control.actions.InspectLookUpServerAction; +import org.eclipse.osee.framework.ui.service.control.actions.LookupUpdates; +import org.eclipse.osee.framework.ui.service.control.actions.NodeDoubleClicked; +import org.eclipse.osee.framework.ui.service.control.actions.NodeSelected; +import org.eclipse.osee.framework.ui.service.control.actions.OpenLaunchWizard; +import org.eclipse.osee.framework.ui.service.control.actions.ServiceUpdates; +import org.eclipse.osee.framework.ui.service.control.actions.UpdateLookupViewerToolTip; +import org.eclipse.osee.framework.ui.service.control.actions.UpdateToolTip; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.managers.ConnectionManager; +import org.eclipse.osee.framework.ui.service.control.managers.ContributionManager; +import org.eclipse.osee.framework.ui.service.control.managers.ServicesManager; +import org.eclipse.osee.framework.ui.service.control.managers.interfaces.IConnectionListener; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.osee.framework.ui.service.control.renderer.IServiceRenderer; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +/** + * @author Roberto E. Escobar + */ +public class ManagerMain extends Composite implements IConnectionListener, IServiceManager<TreeParent> { + + private ServicesViewer servicesViewer; + private LookupViewer lookupViewer; + private FormattedText textArea; + private StackedViewer stackedViewer; + private ServicesManager servicesManager; + private LookupUpdates lookupUpdater; + private SashForm serviceAreaSash; + private SashForm mainSashForm; + private SashForm serviceAndDetailsSash; + private ConnectionManager connectionManager; + private ContributionManager contributionManager; + private Logger logger = ConfigUtil.getConfigFactory().getLogger(ManagerMain.class); + + public ManagerMain(Composite parent, int style) { + super(parent, style); + create(); + initializeBackend(); + registerActions(); + } + + private void create() { + this.setLayout(new GridLayout()); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + mainSashForm = new SashForm(this, SWT.NONE); + mainSashForm.setLayout(new GridLayout()); + mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + mainSashForm.setOrientation(SWT.HORIZONTAL); + mainSashForm.SASH_WIDTH = 3; + + createServiceAndDetailAreaSash(mainSashForm); + createConnectionArea(mainSashForm); + + mainSashForm.setWeights(new int[] {4, 5}); + } + + private void createServiceAndDetailAreaSash(Composite parent) { + serviceAndDetailsSash = new SashForm(parent, SWT.NONE); + serviceAndDetailsSash.setLayout(new GridLayout()); + serviceAndDetailsSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + serviceAndDetailsSash.setOrientation(SWT.VERTICAL); + serviceAndDetailsSash.SASH_WIDTH = 1; + + createServiceAreaSash(serviceAndDetailsSash); + + textArea = new FormattedText(serviceAndDetailsSash, SWT.BORDER); + textArea.getStyledText().setToolTipText("Displays Service Information"); + textArea.setTextAreaBackground(SWT.COLOR_WHITE); + + serviceAndDetailsSash.setWeights(new int[] {4, 5}); + } + + private void createServiceAreaSash(Composite parent) { + serviceAreaSash = new SashForm(parent, SWT.NONE); + serviceAreaSash.setLayout(new GridLayout()); + serviceAreaSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + serviceAreaSash.setOrientation(SWT.HORIZONTAL); + serviceAreaSash.SASH_WIDTH = 1; + + createLookupViewerArea(serviceAreaSash); + createServicesArea(serviceAreaSash); + + serviceAreaSash.setWeights(new int[] {4, 7}); + } + + private void createServicesArea(Composite parent) { + Group composite = new Group(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setText("Services"); + servicesViewer = new ServicesViewer(composite, SWT.NONE); + } + + private void createLookupViewerArea(Composite parent) { + Group composite = new Group(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setText("Available Lookup Servers"); + lookupViewer = new LookupViewer(composite, SWT.NONE); + } + + private void createConnectionArea(Composite parent) { + stackedViewer = new StackedViewer(parent, SWT.BORDER); + } + + public ServicesViewer getServicesViewer() { + return servicesViewer; + } + + public FormattedText getQuickViewer() { + return textArea; + } + + public ServicesManager getServicesManager() { + return servicesManager; + } + + public InputManager<TreeParent> getInputManager() { + return servicesManager.getInputManager(); + } + + public ConnectionManager getConnectionManager() { + return connectionManager; + } + + public LookupViewer getLookupViewer() { + return lookupViewer; + } + + public LookupUpdates getLookupUpdater() { + return lookupUpdater; + } + + private void registerActions() { + new OpenLaunchWizard(this); + new ServiceUpdates(this); + new NodeSelected(this); + new NodeDoubleClicked(this); + new UpdateToolTip(this); + new InspectLookUpServerAction(this); + new UpdateLookupViewerToolTip(this); + lookupUpdater = new LookupUpdates(this); + } + + public void dispose() { + lookupUpdater.dispose(); + servicesViewer.dispose(); + stackedViewer.dispose(); + lookupViewer.dispose(); + textArea.dispose(); + connectionManager.removeConnectionListener(this); + servicesManager.dispose(); + super.dispose(); + } + + private void initializeBackend() { + connectionManager = ConnectionManager.getInstance(); + contributionManager = ContributionManager.getInstance(); + + registerServiceRenderers(); + registerServiceIcons(); + + servicesManager = ServicesManager.getInstance(); + servicesViewer.setInput(servicesManager.getInputManager().getInputList()); + + connectionManager.addConnectionListener(this); + } + + private void registerServiceRenderers() { + Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); + + Map<String, String> interfaceToRenderer = contributionManager.getInterfaceToRendererMap(); + for (String interfaceName : interfaceToRenderer.keySet()) { + String serviceRenderer = interfaceToRenderer.get(interfaceName); + + try { + Class<?> interfaceClass = contributionManager.loadClass(interfaceName); + Class<?> rendererClass = contributionManager.loadClass(serviceRenderer); + try { + Object renderer = rendererClass.newInstance(); + connectionManager.registerForConnection(interfaceClass, (IServiceRenderer) renderer); + stackedViewer.addControl(interfaceClass.getCanonicalName(), (IRenderer) renderer); + } catch (InstantiationException ex) { + logger.log(Level.WARNING, "registerServiceRenderers: Instantiation Error.\n", ex); + } catch (IllegalAccessException ex) { + logger.log(Level.WARNING, "registerServiceRenderers: IllegalAccess Error.\n", ex); + } + } catch (ClassNotFoundException ex) { + logger.log(Level.WARNING, "registerServiceRenderers: ClassNotFound Error.\n", ex); + } + } + } + + private void registerServiceIcons() { + Map<String, String> interfaceToIcon = contributionManager.getInterfaceToIconMap(); + for (String interfaceName : interfaceToIcon.keySet()) { + + String iconPath = interfaceToIcon.get(interfaceName); + ImageDescriptor imageDescriptor = contributionManager.getImageDescriptor(iconPath); + if (imageDescriptor != null) { + try { + Class<?> interfaceClass = contributionManager.loadClass(interfaceName); + servicesViewer.registerImage(interfaceClass, imageDescriptor); + } catch (ClassNotFoundException ex) { + logger.log(Level.WARNING, "Error in registerServiceIcons.\n", ex); + } + } + } + } + + public void onConnectionChanged(ServiceNode serviceNode, boolean connected) { + if (connected) { + serviceAreaSash.setOrientation(SWT.VERTICAL); + Class<?> key = connectionManager.getConnectionType(); + IServiceRenderer renderer = connectionManager.getRenderer(); + renderer.setService(serviceNode.getServiceItem()); + stackedViewer.displayArea(key.getCanonicalName()); + stackedViewer.setVisible(true); + serviceAndDetailsSash.setWeights(new int[] {7, 3}); + renderer.refresh(); + } else { + serviceAreaSash.setOrientation(SWT.HORIZONTAL); + stackedViewer.displayArea(StackedViewer.DEFAULT_CONTROL); + stackedViewer.setVisible(false); + serviceAndDetailsSash.setWeights(new int[] {4, 5}); + } + this.mainSashForm.layout(); + this.serviceAndDetailsSash.layout(); + getServicesViewer().refresh(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesQuickViewer.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesQuickViewer.java new file mode 100644 index 00000000000..60f06f3c08a --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesQuickViewer.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.service.control.widgets; + +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +/** + * @author Roberto E. Escobar + */ +public class ServicesQuickViewer extends Composite { + + private FormattedText textArea; + + public ServicesQuickViewer(Composite parent, int style) { + super(parent, style); + create(); + } + + private void create() { + this.setLayout(new GridLayout()); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + textArea = new FormattedText(this, SWT.NONE); + textArea.setTextAreaBackground(SWT.COLOR_WHITE); + } + + public FormattedText getTextArea() { + return textArea; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java new file mode 100644 index 00000000000..d1c326642cf --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/ServicesViewer.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * 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.service.control.widgets; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import net.jini.core.lookup.ServiceItem; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.osee.framework.jdk.core.type.TreeObject; +import org.eclipse.osee.framework.jdk.core.type.TreeParent; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.data.CategoryParent; +import org.eclipse.osee.framework.ui.service.control.data.GroupParent; +import org.eclipse.osee.framework.ui.service.control.data.ServiceNode; +import org.eclipse.osee.framework.ui.service.control.managers.ConnectionManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class ServicesViewer extends Composite { + + private static final Image CONFIG_IMAGE = ControlPlugin.getInstance().getImage("config.gif"); + private static final Image FOLDER_IMAGE = + PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); + private static final Image GROUP_IMAGE = ControlPlugin.getInstance().getImage("group.gif"); + private static final Image CONNECT_FOLDER_IMAGE = ControlPlugin.getInstance().getImage("connect_folder.gif"); + private static final Image CONNECTED_IMAGE = ControlPlugin.getInstance().getImage("connected_plug.gif"); + + private StructuredViewer viewer; + private Map<Class<?>, Image> serviceIconMap; + + public ServicesViewer(Composite parent, int style) { + super(parent, style); + create(); + serviceIconMap = new HashMap<Class<?>, Image>(); + } + + private void create() { + this.setLayout(new GridLayout()); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + createTreeArea(this); + } + + private void createTreeArea(Composite parent) { + viewer = new TreeViewer(parent, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + viewer.setContentProvider(new TreeContentProvider()); + viewer.setLabelProvider(new TreeLabelProvider()); + viewer.setSorter(new ViewerSorter()); + viewer.setInput(new ArrayList<String>()); + viewer.getControl().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); + } + + private class TreeLabelProvider extends LabelProvider { + + public Image getImage(Object obj) { + Image toReturn = null; + if (obj instanceof GroupParent) { + toReturn = GROUP_IMAGE; + } else if (obj instanceof CategoryParent) { + toReturn = FOLDER_IMAGE; + CategoryParent categoryParent = (CategoryParent) obj; + if (categoryParent.hasChildren()) { + Object child = categoryParent.getChildren()[0]; + if (child instanceof ServiceNode) { + ServiceNode serviceNode = (ServiceNode) child; + if (ConnectionManager.getInstance().isAllowedConnectionType(serviceNode.getServiceItem())) { + toReturn = CONNECT_FOLDER_IMAGE; + } + } + } + } else if (obj instanceof ServiceNode) { + ServiceNode node = ((ServiceNode) obj); + if (node.isConnected()) { + toReturn = CONNECTED_IMAGE; + } else { + toReturn = CONFIG_IMAGE; + ServiceItem serviceItem = node.getServiceItem(); + for (Class<?> classType : serviceIconMap.keySet()) { + if (classType.isInstance(serviceItem.service)) { + Image image = serviceIconMap.get(classType); + if (image != null) { + toReturn = image; + } + break; + } + } + } + } + return toReturn; + } + + public String getText(Object obj) { + return obj.toString(); + } + } + + private class TreeContentProvider implements ITreeContentProvider { + + public void dispose() { + } + + public Object[] getChildren(Object parentElement) { + if (parentElement != null && parentElement instanceof TreeParent) { + TreeParent parent = (TreeParent) parentElement; + if (parent.hasChildren()) { + return parent.getChildren(); + } + } + return new Object[0]; + } + + public Object[] getElements(Object inputElement) { + if (inputElement != null && inputElement instanceof Collection) { + Collection<?> elementArray = (Collection<?>) inputElement; + return elementArray.toArray(); + } + return new Object[0]; + } + + public Object getParent(Object element) { + if (element != null && element instanceof TreeObject) { + TreeObject child = (TreeObject) element; + return child.getParent(); + } + return new Object(); + } + + public boolean hasChildren(Object element) { + if (element instanceof TreeParent) { + TreeParent parent = (TreeParent) element; + return parent.hasChildren(); + } + return false; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + public boolean setFocus() { + return this.viewer.getControl().setFocus(); + } + + public StructuredViewer getViewer() { + return viewer; + } + + public void setInput(List<TreeParent> input) { + viewer.setInput(input); + } + + public void refresh() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (viewer != null && !viewer.getControl().isDisposed()) { + viewer.refresh(); + } + } + }); + } + + public void dispose() { + viewer.getControl().dispose(); + super.dispose(); + } + + public void registerImage(Class<?> serviceType, ImageDescriptor icon) { + serviceIconMap.put(serviceType, icon.createImage()); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/StackedViewer.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/StackedViewer.java new file mode 100644 index 00000000000..a3faa0a16f3 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/widgets/StackedViewer.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.service.control.widgets; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.osee.framework.ui.service.control.renderer.IRenderer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; + +/** + * @author Roberto E. Escobar + */ +public class StackedViewer extends Composite { + + public static final String DEFAULT_CONTROL = "DEFAULT_CONTROL"; + private StackLayout stackLayout; + private Composite stackComposite; + private Map<String, Control> compositeMap; + + public StackedViewer(Composite parent, int style) { + super(parent, style); + create(); + } + + private void create() { + this.setLayout(new GridLayout()); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + stackComposite = new Composite(this, SWT.NONE); + stackLayout = new StackLayout(); + stackComposite.setLayout(stackLayout); + stackComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + populateStackedComposite(stackComposite); + displayArea(DEFAULT_CONTROL); + } + + private void populateStackedComposite(Composite parent) { + compositeMap = new HashMap<String, Control>(); + compositeMap.put(DEFAULT_CONTROL, createDefault(parent)); + } + + public void addControl(String key, IRenderer renderer) { + compositeMap.put(key, renderer.renderInComposite(stackComposite)); + } + + private Composite createDefault(Composite parent) { + Label label = new Label(parent, SWT.NONE); + label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + label.setText("DEFAULT LAYER"); + return label.getShell(); + } + + public void displayArea(String key) { + stackLayout.topControl = compositeMap.get(key); + stackComposite.layout(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/MultiTextDialog.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/MultiTextDialog.java new file mode 100644 index 00000000000..74fa34383dd --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/MultiTextDialog.java @@ -0,0 +1,99 @@ +/*******************************************************************************
+ * 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.service.control.wizards.launcher;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class MultiTextDialog extends Dialog {
+
+ private String title;
+ private String message;
+
+ private Text[] texts;
+ private String[] prompt;
+ private boolean[] displayable;
+ private String[] value;
+
+ public MultiTextDialog(Shell parentShell, String dialogTitle, String dialogMessage, String[] prompt, boolean[] displayable) {
+ super(parentShell);
+ this.title = dialogTitle;
+ this.message = dialogMessage;
+ this.prompt = prompt != null ? prompt : new String[0];
+ this.displayable = displayable != null ? displayable : new boolean[0];
+ this.value = null;
+ }
+
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == IDialogConstants.OK_ID) {
+ value = new String[prompt.length];
+ for (int i = 0; i < prompt.length; i++) {
+ value[i] = texts[i].getText();
+ }
+ } else {
+ value = null;
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ if (title != null) {
+ shell.setText(title);
+ }
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ for (int i = 0; i < prompt.length; i++) {
+ if (value != null && value[i] != null) {
+ texts[i].setFocus();
+ texts[i].setText(value[i]);
+ texts[i].selectAll();
+ }
+ }
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ if (message != null) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(message);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+ }
+ texts = new Text[prompt.length];
+ for (int i = 0; i < prompt.length; i++) {
+ if (displayable[i] != false) {
+ texts[i] = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ } else {
+ texts[i] = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
+ }
+ texts[i].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ }
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ public String[] getValue() {
+ return value;
+ }
+}
diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/SecureRemoteAccess.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/SecureRemoteAccess.java new file mode 100644 index 00000000000..d443043aa1a --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/SecureRemoteAccess.java @@ -0,0 +1,177 @@ +/*******************************************************************************
+ * 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.service.control.wizards.launcher;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osee.framework.jdk.core.util.io.CharBackedInputStream;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.UIKeyboardInteractive;
+import com.jcraft.jsch.UserInfo;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SecureRemoteAccess {
+ private static final Logger logger = ConfigUtil.getConfigFactory().getLogger(SecureRemoteAccess.class);
+ private Session session;
+
+ private SecureRemoteAccess(String host, String user) throws Exception {
+ JSch.setLogger(new LogForwarding());
+ try {
+ JSch jsch = new JSch();
+ jsch.setKnownHosts(host);
+ session = jsch.getSession(user, host);
+ session.setUserInfo(new PromptUserInfo());
+ session.connect(30000);
+ } catch (JSchException ex) {
+ throw new Exception("Error connecting to server.", ex);
+ }
+ }
+
+ public String executeCommandList(String[] commands) throws Exception {
+ Channel channel = null;
+ CharBackedInputStream inputStream = new CharBackedInputStream();
+ OutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ channel = session.openChannel("shell");
+ channel.setInputStream(inputStream);
+ channel.setOutputStream(outputStream);
+
+ for (String cmd : commands) {
+ inputStream.append(cmd);
+ inputStream.append("\n");
+ }
+
+ channel.connect();
+ Thread.sleep(5000);
+
+ } catch (JSchException ex) {
+ throw new Exception("Error executing commands on server.", ex);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ if (channel != null) {
+ channel.disconnect();
+ }
+ }
+ return outputStream.toString();
+ }
+
+ public ChannelSftp getScpConnection() throws Exception {
+ Channel channel = session.openChannel("sftp");
+ channel.connect();
+ return (ChannelSftp) channel;
+ }
+
+ public static SecureRemoteAccess getRemoteAccessAuthenticateWithPassword(String host, String username) throws Exception {
+ return new SecureRemoteAccess(host, username);
+ }
+
+ private static class LogForwarding implements com.jcraft.jsch.Logger {
+ private static Map<Integer, Level> levelMap = new HashMap<Integer, Level>();
+ static {
+ levelMap.put(com.jcraft.jsch.Logger.INFO, Level.INFO);
+ levelMap.put(com.jcraft.jsch.Logger.WARN, Level.WARNING);
+ levelMap.put(com.jcraft.jsch.Logger.FATAL, Level.SEVERE);
+ levelMap.put(com.jcraft.jsch.Logger.DEBUG, Level.FINE);
+ levelMap.put(com.jcraft.jsch.Logger.ERROR, Level.SEVERE);
+ }
+
+ public boolean isEnabled(int level) {
+ return true;
+ }
+
+ public void log(int level, String message) {
+ Level logLevel = levelMap.get(level);
+ if (logLevel == null) {
+ logLevel = Level.SEVERE;
+ }
+ logger.log(logLevel, message);
+ }
+ }
+
+ private final class PromptUserInfo implements UserInfo, UIKeyboardInteractive {
+ private String password;
+
+ public String getPassword() {
+ return password;
+ }
+
+ public boolean promptYesNo(String message) {
+ Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ MessageDialog dialog =
+ new MessageDialog(shell, "Warning", null, message, MessageDialog.WARNING, new String[] {
+ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 0);
+ return dialog.open() == 0;
+ }
+
+ public String getPassphrase() {
+ return null;
+ }
+
+ public boolean promptPassphrase(String message) {
+ return true;
+ }
+
+ public boolean promptPassword(String message) {
+ Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ MultiTextDialog inputDialog =
+ new MultiTextDialog(shell, "Password", "Enter password: ", new String[] {"password:"},
+ new boolean[] {false});
+ inputDialog.setBlockOnOpen(true);
+ int result = inputDialog.getReturnCode();
+ if (result == Window.OK) {
+ String[] inputs = inputDialog.getValue();
+ if (inputs != null && inputs.length == 1) {
+ password = inputs[0];
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void showMessage(String message) {
+ Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ MessageDialog.openInformation(shell, "Log-in Message", message);
+ }
+
+ public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo) {
+ Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ MultiTextDialog inputDialog =
+ new MultiTextDialog(shell, destination + ": " + name, "Enter Password: ", prompt, echo);
+ inputDialog.setBlockOnOpen(true);
+ int result = inputDialog.open();
+ if (result == Window.OK) {
+ return inputDialog.getValue();
+ }
+ return null;
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchDataPersist.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchDataPersist.java new file mode 100644 index 00000000000..c20a06e3115 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchDataPersist.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osgi.service.datalocation.Location; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import com.sun.org.apache.xml.internal.serialize.OutputFormat; +import com.sun.org.apache.xml.internal.serialize.XMLSerializer; + +/** + * @author Andrew M. Finkbeiner + */ +public class ServiceLaunchDataPersist { + + private static ServiceLaunchDataPersist instance = null; + private static final String ROOT_ELEMENT = "ServiceLaunchData"; + private static final String HOST_ELEMENT = "Host"; + private static final String LAST_SERVICE_ELEMENT = "LastSelectedService"; + private static final Logger logger = ConfigUtil.getConfigFactory().getLogger(ServiceLaunchDataPersist.class); + + private List<String> hosts; + private String lastServiceLaunched; + + private ServiceLaunchDataPersist() { + hosts = new ArrayList<String>(); + lastServiceLaunched = ""; + parseFile(read()); + } + + public static ServiceLaunchDataPersist getInstance() { + if (instance == null) { + instance = new ServiceLaunchDataPersist(); + } + return instance; + } + + private File getFile() { + Location user = Platform.getUserLocation(); + String path = user.getURL().getPath(); + File file = new File(path + File.separator + this.getClass().getCanonicalName() + ".xml"); + file.getParentFile().mkdirs(); + return file; + } + + public List<String> getHosts() { + return hosts; + } + + private void parseFile(Document document) { + hosts.clear(); + lastServiceLaunched = ""; + if (document != null) { + NodeList viewList = document.getElementsByTagName(HOST_ELEMENT); + for (int i = 0; i < viewList.getLength(); i++) { + Node node = viewList.item(i); + String value = node.getTextContent(); + if (value != null && !value.equals("")) { + hosts.add(value); + } + } + NodeList lastService = document.getElementsByTagName(LAST_SERVICE_ELEMENT); + if (lastService.getLength() == 1) { + Node node = lastService.item(0); + String value = node.getTextContent(); + if (value != null && !value.equals("")) { + lastServiceLaunched = value; + } + } + } + } + + private Document read() { + Document document = null; + File file = getFile(); + try { + if (file.exists()) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + document = builder.parse(file); + } + } catch (Exception ex) { + logger.log(Level.SEVERE, "Error reading File [" + file.getAbsolutePath() + "] ", ex); + } + return document; + } + + public void saveHostName(String addhost) { + if (addhost != null && !addhost.equals("") && !hosts.contains(addhost)) { + hosts.add(addhost); + } + saveFile(); + } + + private void write(Element root, File fileString) { + OutputFormat outputFormat; + OutputStreamWriter out = null; + try { + OutputStream bout = new BufferedOutputStream(new FileOutputStream(fileString)); + out = new OutputStreamWriter(bout); + + outputFormat = new OutputFormat("XML", "UTF-8", true); + XMLSerializer xmlSerializer = new XMLSerializer(out, outputFormat); + xmlSerializer.serialize(root); + out.flush(); + } catch (FileNotFoundException ex) { + logger.log(Level.SEVERE, "File error [" + fileString + "] ", ex); + } catch (IOException ex) { + logger.log(Level.SEVERE, "Error writing to File [" + fileString + "] ", ex); + } finally { + try { + out.close(); + } catch (IOException ex) { + logger.log(Level.SEVERE, "Error closing stream [" + fileString + "] ", ex); + } + } + } + + public String getLastServiceLaunched() { + return lastServiceLaunched; + } + + public void saveLastServiceLaunched(String lastServiceLaunched) { + this.lastServiceLaunched = lastServiceLaunched; + saveFile(); + } + + private void saveFile() { + if (hosts.size() > 0 || (lastServiceLaunched != null && !lastServiceLaunched.equals(""))) { + + Document xmlDoc; + try { + xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + Element rootElement = xmlDoc.createElement(ROOT_ELEMENT); + xmlDoc.appendChild(rootElement); + + Element hostElement = null; + for (String host : hosts) { + hostElement = xmlDoc.createElement(HOST_ELEMENT); + hostElement.setTextContent(host); + rootElement.appendChild(hostElement); + } + + if (lastServiceLaunched != null && !lastServiceLaunched.equals("")) { + Element lastServiceElement = xmlDoc.createElement(LAST_SERVICE_ELEMENT); + lastServiceElement.setTextContent(this.lastServiceLaunched.trim()); + rootElement.appendChild(lastServiceElement); + } + write(rootElement, getFile()); + } catch (ParserConfigurationException ex) { + logger.log(Level.SEVERE, "Error saving File [" + getFile() + "] ", ex); + } + + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchWizard.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchWizard.java new file mode 100644 index 00000000000..86ce22b7000 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchWizard.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher; + +import java.util.logging.Logger; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.osee.framework.jdk.core.util.io.IZipEntryCompleteCallback; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.pages.LocalRemotePage; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.pages.ServicePage; +import org.eclipse.osee.framework.ui.swt.DynamicWizard; + +public class ServiceLaunchWizard extends DynamicWizard implements IZipEntryCompleteCallback { + + private static final Logger logger = ConfigUtil.getConfigFactory().getLogger(ServiceLaunchWizard.class); + private ServiceLaunchingInformation serviceInfo; + + public ServiceLaunchWizard() { + serviceInfo = new ServiceLaunchingInformation(); + } + + @Override + public boolean canFinish() { + return serviceInfo.canFinish(); + } + + @Override + public boolean performCancel() { + return super.performCancel(); + } + + @Override + public boolean performFinish() { + if (!canFinish()) return false; + boolean returnVal = true; + ServiceLaunchDataPersist data = ServiceLaunchDataPersist.getInstance(); + data.saveHostName(serviceInfo.getSelectedHost()); + data.saveLastServiceLaunched(serviceInfo.getServiceItem().getName()); + return returnVal; + } + + @Override + public void addPages() { + super.addPages(); + this.setWindowTitle("Service Launching"); + + String servicePageTitle = "Service Page"; + String localRemoteTitle = "Location Selection"; + + IWizardPage startingPage = new LocalRemotePage(localRemoteTitle, null, servicePageTitle, serviceInfo, this); + this.addPage(startingPage); + this.addPage(new ServicePage(servicePageTitle, localRemoteTitle, null, serviceInfo)); + this.setStartingPage(startingPage); + } + + public Logger getLogger() { + return logger; + } + + public void setValue(int i) { + } + + public void setMinimum(int i) { + } + + public void setMaximum(int i) { + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchingInformation.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchingInformation.java new file mode 100644 index 00000000000..b23c118ead1 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceLaunchingInformation.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher; + +import java.util.List; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceItem; + +public class ServiceLaunchingInformation { + + private List<String> availableHosts; + + private SecureRemoteAccess sshConnection; + + private String selectedHost; + private String user; + private String[] execCmds; + private boolean upload; + private boolean isLocal; + private String unzipLocation; + + private ServiceItem selectedServiceItem; + + private ServiceLaunchDataPersist serviceLaunchData; + + public ServiceLaunchingInformation() { + serviceLaunchData = ServiceLaunchDataPersist.getInstance(); + availableHosts = serviceLaunchData.getHosts(); + unzipLocation = ""; + } + + public List<String> getAvailableHosts() { + return availableHosts; + } + + public void setAvailableHosts(List<String> availableHosts) { + this.availableHosts = availableHosts; + } + + public String[] getExecCmds() { + return execCmds; + } + + public void setExecCmds(String[] execCmds) { + this.execCmds = execCmds; + } + + public String getSelectedHost() { + return selectedHost; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public boolean isUpload() { + return upload; + } + + public void setUpload(boolean upload) { + this.upload = upload; + } + + public boolean canFinish() { + return (selectedHost != null && user != null && execCmds != null || isLocal()); + } + + public ServiceItem getServiceItem() { + return selectedServiceItem; + } + + public void setServiceItem(ServiceItem serviceItem) { + this.selectedServiceItem = serviceItem; + } + + public void setSelectedHost(String selectedHost) { + this.selectedHost = selectedHost; + } + + public void connectToRemoteHost() throws Exception { + sshConnection = SecureRemoteAccess.getRemoteAccessAuthenticateWithPassword(selectedHost, user); + } + + public SecureRemoteAccess getSSHConnection() { + return sshConnection; + } + + public void setIsLocal(boolean isLocal) { + this.isLocal = isLocal; + } + + public boolean isLocal() { + return isLocal; + } + + public String getUnzipLocation() { + return unzipLocation; + } + + public void setUnzipLocation(String unzipLocation) { + this.unzipLocation = unzipLocation; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceWizardDialog.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceWizardDialog.java new file mode 100644 index 00000000000..a8307070167 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/ServiceWizardDialog.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher; + +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.swt.widgets.Shell; + +public class ServiceWizardDialog extends WizardDialog { + + public ServiceWizardDialog(Shell parentShell, IWizard newWizard) { + super(parentShell, newWizard); + } + + @Override + protected void nextPressed() { + if (((DynamicWizardPage) this.getCurrentPage()).onNextPressed()) { + super.nextPressed(); + } + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/TextAreaDialog.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/TextAreaDialog.java new file mode 100644 index 00000000000..5dcf634c15d --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/TextAreaDialog.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Shell; + +public class TextAreaDialog extends MessageDialog { + + private StyledText cmdText; + private String groupTitle; + private String content; + + public TextAreaDialog(String groupTitle, String content, Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, + defaultIndex); + this.groupTitle = groupTitle; + this.content = content; + } + + public static void open(String groupTitle, String content, Shell parent, String title, String message) { + TextAreaDialog dialog = new TextAreaDialog(groupTitle, content, parent, title, null, // accept + // the + // default + // window + // icon + message, INFORMATION, new String[] {IDialogConstants.OK_LABEL}, 0); + // ok is the default + dialog.open(); + return; + } + + @Override + protected Control createCustomArea(Composite parent) { + + Group userinfo = new Group(parent, SWT.NONE); + userinfo.setText(groupTitle); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + userinfo.setLayout(gridLayout); + + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 1; + gridData.grabExcessHorizontalSpace = true; + userinfo.setLayoutData(gridData); + + cmdText = new StyledText(userinfo, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.WRAP); + cmdText.setEditable(false); + GridData gd = new GridData(); + gd.grabExcessHorizontalSpace = true; + gd.horizontalAlignment = GridData.FILL; + gd.horizontalSpan = 2; + gd.heightHint = 150; + cmdText.setLayoutData(gd); + cmdText.setText(content); + + return super.createCustomArea(parent); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/EclipseApplicationFormatter.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/EclipseApplicationFormatter.java new file mode 100644 index 00000000000..d3828e12e28 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/EclipseApplicationFormatter.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.data; + +import java.io.File; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.StringFormat; + +/** + * @author Roberto E. Escobar + */ +public class EclipseApplicationFormatter extends ExecutionCommandFormatter { + // private final String baseExecString = StringFormat.separateWith(new String[] {"#JAVA#", + // "#JVM_ARGS#", "-cp", + // "#ECLIPSE_INSTALL_HOME#" + (Lib.isWindows() ? "\\eclipse.exe" : "/eclipse"), + // "org.eclipse.core.launcher.Main", "-application", "#APPLICATION_NAME#", "#APPLICATION_ARGS#"}, + // EXEC_SEPARATOR); + private final String baseExecString = + StringFormat.separateWith(new String[] {"#ECLIPSE_INSTALL_HOME#", "-nosplash", "-application", + "#APPLICATION_NAME#", "#APPLICATION_ARGS#", "-vmargs", "#JVM_ARGS#"}, ServiceItem.EXEC_SEPARATOR); + + private String applicationName; + + public EclipseApplicationFormatter(String applicationName) { + this.applicationName = applicationName; + } + + protected String buildExecString() { + String toReturn = baseExecString; + toReturn = toReturn.replaceAll("#JAVA#", "java"); + String localLocation = null; + if (Platform.isRunning()) { + localLocation = (new File(Platform.getInstallLocation().getURL().getFile())).getAbsolutePath(); + } else { + throw new IllegalStateException("Platform needs to be running"); + } + if (Lib.isWindows()) { + localLocation = "\"" + localLocation + "\\eclipse.exe" + "\""; + } else { + localLocation += "/eclipse"; + } + toReturn = toReturn.replace("#ECLIPSE_INSTALL_HOME#", localLocation); + toReturn = toReturn.replace("#APPLICATION_NAME#", applicationName); + toReturn = toReturn.replace("#JVM_ARGS#", this.getJvmArgsString()); + toReturn = toReturn.replace("#APPLICATION_ARGS#", this.getApplicationArgsString()); + return toReturn; + } + + @Override + public void setServiceExecutionString(ServiceItem item) { + item.setEclipseAppExecution(buildExecString()); + } + + @Override + public void setRemoteAllowed(ServiceItem item) { + item.setRemoteExecution(buildExecString()); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ExecutionCommandFormatter.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ExecutionCommandFormatter.java new file mode 100644 index 00000000000..eecdf86840c --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ExecutionCommandFormatter.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.data; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.framework.jdk.core.util.StringFormat; + +/** + * @author Roberto E. Escobar + */ +abstract class ExecutionCommandFormatter { + protected List<String> jvmArgs; + protected List<String> applicationArgs; + + public ExecutionCommandFormatter() { + jvmArgs = new ArrayList<String>(); + applicationArgs = new ArrayList<String>(); + } + + public void addJvmArg(String value) { + jvmArgs.add(value); + } + + public void addApplicationArgs(String value) { + applicationArgs.add(value); + } + + public String getApplicationArgsString() { + String applicationArgsString = ""; + if (applicationArgs.size() > 0) { + applicationArgsString = + ServiceItem.EXEC_SEPARATOR + StringFormat.listToValueSeparatedString(applicationArgs, + ServiceItem.EXEC_SEPARATOR); + } + return applicationArgsString; + } + + public String getJvmArgsString() { + String jvmArgsString = ""; + if (jvmArgs.size() > 0) { + jvmArgsString = + ServiceItem.EXEC_SEPARATOR + StringFormat.listToValueSeparatedString(jvmArgs, ServiceItem.EXEC_SEPARATOR); + } + return jvmArgsString; + } + + protected abstract String buildExecString(); + + public abstract void setServiceExecutionString(ServiceItem item); + + public abstract void setRemoteAllowed(ServiceItem item); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/JiniGroupSelector.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/JiniGroupSelector.java new file mode 100644 index 00000000000..4de2c49fae6 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/JiniGroupSelector.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.data; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import net.jini.core.lookup.ServiceRegistrar; + +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.osee.framework.jdk.core.util.StringFormat; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.jini.discovery.EclipseJiniClassloader; +import org.eclipse.osee.framework.jini.discovery.IRegistrarListener; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.plugin.core.config.JiniLookupGroupConfig; +import org.eclipse.osee.framework.ui.service.control.managers.ReggieCache; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class JiniGroupSelector implements IRegistrarListener { + + private Set<String> availableGroups; + private String[] jiniGroup; + private ComboViewer comboViewer; + private ReggieCache reggieCache; + + public JiniGroupSelector() { + this.comboViewer = null; + this.availableGroups = new TreeSet<String>(); + this.jiniGroup = JiniLookupGroupConfig.getOseeJiniServiceGroups(); + if (jiniGroup == null || jiniGroup.length < 1) { + jiniGroup = new String[1]; + } + this.reggieCache = ReggieCache.getEclipseInstance(EclipseJiniClassloader.getInstance()); + } + + public void createJiniGroupWidget(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setText("Register Service with the following Jini Group: "); + + comboViewer = new ComboViewer(group, SWT.BORDER | SWT.SINGLE); + comboViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + comboViewer.getCombo().addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + jiniGroup[0] = comboViewer.getCombo().getText(); + } + }); + + comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) comboViewer.getSelection(); + Object obj = selection.getFirstElement(); + if (null != obj) { + String value = (String) obj; + jiniGroup[0] = value; + } + } + }); + this.reggieCache.addListener(this); + } + + private void populateGroups() { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + public void run() { + availableGroups.clear(); + availableGroups.addAll(reggieCache.getAvailableJiniGroups()); + if (comboViewer != null && true != comboViewer.getCombo().isDisposed()) { + List<String> list = new ArrayList<String>(availableGroups); + + String temp = jiniGroup[0]; + comboViewer.getCombo().removeAll(); + comboViewer.add(list.toArray()); + + jiniGroup[0] = temp; + if (true != Strings.isValid(jiniGroup[0])) { + jiniGroup = ConfigUtil.getConfigFactory().getOseeConfig().getJiniServiceGroups(); + + int result = list.indexOf(jiniGroup[0]); + if (result < 0) { + for (int index = 0; index < list.size(); index++) { + String value = list.get(index); + if (false != value.contains(jiniGroup[0])) { + jiniGroup[0] = value; + break; + } + } + } + } + + comboViewer.getCombo().select(list.indexOf(jiniGroup[0])); + } + } + }); + } + + public String getJiniGroupVmArg() { + return StringFormat.commaSeparate(jiniGroup); + } + + public void dispose() { + if (comboViewer != null && false != comboViewer.getCombo().isDisposed()) { + comboViewer.getCombo().dispose(); + } + this.reggieCache.removeListener(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jini.discovery.IRegistrarListener#reggieAdded(java.util.List) + */ + public void reggieAdded(List<ServiceRegistrar> serviceRegistrars) { + populateGroups(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jini.discovery.IRegistrarListener#reggieChanged(java.util.List) + */ + public void reggieChanged(List<ServiceRegistrar> serviceRegistrars) { + populateGroups(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jini.discovery.IRegistrarListener#reggieRemoved(java.util.List) + */ + public void reggieRemoved(List<ServiceRegistrar> serviceRegistrars) { + populateGroups(); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ServiceItem.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ServiceItem.java new file mode 100644 index 00000000000..48a5964e46c --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ServiceItem.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.data; + +import java.util.ArrayList; +import org.eclipse.osee.framework.jdk.core.util.OseeProperties; +import org.eclipse.osee.framework.jdk.core.util.Strings; + +public class ServiceItem implements Comparable<ServiceItem> { + public static final String EXEC_SEPARATOR = "@"; + public static final String JINI_GROUP_FIELD = "$JINI_GROUP"; + private ArrayList<String> hosts; + private String standAloneExecution; + private String eclipseAppExecution; + private String remoteExecution; + private boolean isEclipseAppAllowed; + private boolean isStandAloneAllowed; + private boolean isRemoteAllowed; + private boolean isLocalAllowed; + private String serviceName; + private String zipFileName; + private String unzipLocation; + private String pluginId; + private String jiniGroup; + private boolean isJiniGroupRequired; + + public ServiceItem(String serviceName) { + this.serviceName = serviceName; + this.isStandAloneAllowed = false; + this.isEclipseAppAllowed = false; + this.isRemoteAllowed = false; + this.isLocalAllowed = false; + this.standAloneExecution = ""; + this.eclipseAppExecution = ""; + this.remoteExecution = ""; + this.zipFileName = ""; + this.unzipLocation = ""; + this.pluginId = ""; + this.isJiniGroupRequired = false; + this.jiniGroup = ""; + this.hosts = new ArrayList<String>(); + } + + public String getLocalExecution() { + return updateForJiniGroup(eclipseAppExecution); + } + + public String getStandAloneExecution() { + return updateForJiniGroup(standAloneExecution); + } + + public String getRemoteExecution() { + return updateForJiniGroup(remoteExecution); + } + + private String updateForJiniGroup(String source) { + String jiniVmArg = ""; + if (false != isJiniGroupRequired()) { + jiniVmArg = + String.format("-D%s=\"%s\"", OseeProperties.OSEE_JINI_SERVICE_GROUPS, + Strings.isValid(getJiniGroup()) ? getJiniGroup() : JINI_GROUP_FIELD); + } + return source.replace(JINI_GROUP_FIELD, jiniVmArg); + } + + public boolean isRemoteAllowed() { + return isRemoteAllowed; + } + + public boolean isStandAloneAllowed() { + return isStandAloneAllowed; + } + + public boolean isEclipseAppAllowed() { + return isEclipseAppAllowed; + } + + public boolean isLocalAllowed() { + return isLocalAllowed; + } + + public ArrayList<String> getHosts() { + return hosts; + } + + public String toString() { + String hostList = "\n"; + for (String temp : hosts) { + hostList += " Host: " + temp + "\n"; + } + + String localExecution = "\n Local Allowed: " + isLocalAllowed + "\n"; + if (isLocalAllowed()) { + localExecution += "\t" + "EclipseAppAllowed: " + isEclipseAppAllowed() + "\n"; + if (isEclipseAppAllowed()) { + localExecution += "\t" + "EclipseAppExecute: " + this.getLocalExecution() + "\n"; + } + + localExecution += "\t" + "StandAloneExecution: " + isStandAloneAllowed() + "\n"; + if (isStandAloneAllowed()) { + localExecution += "\t" + "StandAloneExecution: " + this.getStandAloneExecution() + "\n"; + } + } + + String remoteExecution = " Remote Allowed: " + isRemoteAllowed() + "\n"; + if (isRemoteAllowed()) { + remoteExecution += "\t" + "RemoteExecution: " + this.getRemoteExecution() + "\n"; + } + + return String.format( + "[ Class: %s\n Name: %s %s %s Destination: %s\n Zip Name: %s\n Plugin Directory: %s %s" + "\n JiniGroup: %s]\n", + this.getClass().getSimpleName(), getName(), localExecution, remoteExecution, getUnzipLocation(), + getZipName(), getPlugin(), hostList, isJiniGroupRequired() ? jiniGroup : "NOT REQUIRED"); + } + + public int compareTo(ServiceItem other) { + if (other != null) { + String name1 = this.getName(); + String name2 = other.getName(); + name1 = (name1 != null ? name1 : ""); + name2 = (name2 != null ? name2 : ""); + return name1.compareTo(name2); + } + return 0; + } + + public String getName() { + return serviceName; + } + + public String getZipName() { + return zipFileName; + } + + public String getPlugin() { + return pluginId; + } + + public String getUnzipLocation() { + return unzipLocation; + } + + protected void setUnzipLocation(String unzipLocation) { + this.unzipLocation = unzipLocation; + } + + protected void setPlugin(String pluginId) { + this.pluginId = pluginId; + } + + protected void setZipName(String zipFileName) { + this.zipFileName = zipFileName; + } + + protected void setLocalAllowed(boolean isLocalAllowed) { + this.isLocalAllowed = isLocalAllowed; + } + + protected void setStandAloneExecution(String value) { + this.standAloneExecution = value; + this.isStandAloneAllowed = true; + } + + protected void setEclipseAppExecution(String value) { + this.eclipseAppExecution = value; + this.isEclipseAppAllowed = true; + } + + protected void setRemoteExecution(String value) { + this.remoteExecution = value; + this.isRemoteAllowed = true; + } + + public void setJiniGroupRequired(boolean booleanValue) { + this.isJiniGroupRequired = booleanValue; + } + + public boolean isJiniGroupRequired() { + return isJiniGroupRequired; + } + + public void setJiniGroup(String jiniGroup) { + this.jiniGroup = jiniGroup; + } + + public String getJiniGroup() { + return jiniGroup; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ServiceLaunchConfig.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ServiceLaunchConfig.java new file mode 100644 index 00000000000..04740175b68 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/ServiceLaunchConfig.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.data; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.plugin.core.config.ConfigUtil; +import org.eclipse.osee.framework.plugin.core.util.ExtensionPoints; + +/** + * @author Roberto E. Escobar + */ +public class ServiceLaunchConfig { + private final Logger logger = ConfigUtil.getConfigFactory().getLogger(ServiceLaunchConfig.class); + private final String EXTENSION_POINT_NAME = "org.eclipse.osee.framework.ui.service.control.ServiceLaunch"; + private final String APPLICATION_ELEMENT = "Application"; + + private enum ExecutionTypesEnum { + EclipseApplication("EclipseApplicationName"), StandAloneApplication("ExecutionCommand"); + + String entryTag; + + ExecutionTypesEnum(String tag) { + this.entryTag = tag; + } + + String getEntryTag() { + return entryTag; + } + } + + private enum ArgumentTypesEnum { + VmArgs, AppArgs; + } + + private Collection<ServiceItem> localServiceItems; + private Collection<ServiceItem> remoteServiceItems; + private Collection<ServiceItem> combinedServiceItems; + private static final ServiceLaunchConfig instance = new ServiceLaunchConfig(); + + public static ServiceLaunchConfig getInstance() { + return instance; + } + + private ServiceLaunchConfig() { + super(); + readServiceItems(); + } + + public Collection<ServiceItem> getRemoteServiceItems() { + return remoteServiceItems; + } + + public Collection<ServiceItem> getLocalServiceItems() { + return localServiceItems; + } + + public Collection<ServiceItem> getServiceItems() { + return combinedServiceItems; + } + + private void readServiceItems() { + remoteServiceItems = new ArrayList<ServiceItem>(); + localServiceItems = new ArrayList<ServiceItem>(); + combinedServiceItems = new ArrayList<ServiceItem>(); + + List<ServiceItem> serviceItems = getServicesToLaunch(); + for (ServiceItem item : serviceItems) { + if (item.isLocalAllowed()) { + localServiceItems.add(item); + } + if (item.isRemoteAllowed()) { + remoteServiceItems.add(item); + } + combinedServiceItems.add(item); + } + } + + private List<ServiceItem> getServicesToLaunch() { + List<ServiceItem> toReturn = new ArrayList<ServiceItem>(); + List<IConfigurationElement> elements = + ExtensionPoints.getExtensionElements(EXTENSION_POINT_NAME, APPLICATION_ELEMENT); + for (IConfigurationElement element : elements) { + String serviceName = element.getAttribute("ServiceName"); + if (false != Strings.isValid(serviceName)) { + try { + + ServiceItem serviceItem = new ServiceItem(serviceName); + serviceItem.setJiniGroupRequired(getBooleanValue("RequiresJiniGroup", element)); + getPluginId(element, serviceItem); + getApplicationConfig(ExecutionTypesEnum.EclipseApplication, element, serviceItem); + getApplicationConfig(ExecutionTypesEnum.StandAloneApplication, element, serviceItem); + toReturn.add(serviceItem); + } catch (Throwable ex) { + logger.log(Level.WARNING, String.format("Error while loading service launch extension for: [%s]", + serviceName), ex); + } + } + } + return toReturn; + } + + private void getPluginId(IConfigurationElement parent, ServiceItem serviceItem) { + String plugin = parent.getContributor().getName(); + IConfigurationElement[] elements = parent.getChildren("NotLocalToPlugin"); + if (elements != null && elements.length > 0) { + String temp = elements[0].getAttribute("PluginId"); + if (false != Strings.isValid(temp)) { + plugin = temp; + } + } + serviceItem.setPlugin(plugin); + } + + private void getApplicationConfig(ExecutionTypesEnum configElement, IConfigurationElement element, ServiceItem serviceItem) { + IConfigurationElement[] elements = element.getChildren(configElement.name()); + if (elements != null && elements.length > 0) { + for (IConfigurationElement theElement : elements) { + ExecutionCommandFormatter commandFormatter = getExecutionCommandInstance(configElement, theElement); + if (null != commandFormatter) { + serviceItem.setLocalAllowed(getBooleanValue("IsLocalAllowed", theElement)); + + getExecutionArguments(ArgumentTypesEnum.VmArgs, theElement, commandFormatter); + getExecutionArguments(ArgumentTypesEnum.AppArgs, theElement, commandFormatter); + + if (false != serviceItem.isJiniGroupRequired()) { + commandFormatter.addJvmArg(ServiceItem.JINI_GROUP_FIELD); + } + + if (false != getBooleanValue("IsRemoteAllowed", theElement)) { + commandFormatter.setRemoteAllowed(serviceItem); + getHosts(theElement, serviceItem); + } + getApplicationBundle(theElement, serviceItem); + commandFormatter.setServiceExecutionString(serviceItem); + } + } + } + } + + private void getApplicationBundle(IConfigurationElement parent, ServiceItem serviceItem) { + IConfigurationElement[] elements = parent.getChildren("ApplicationBundle"); + for (IConfigurationElement element : elements) { + String fileName = element.getAttribute("ZipFileName"); + if (false != Strings.isValid(fileName)) { + serviceItem.setZipName(fileName.trim()); + } + + String unzipLocation = element.getAttribute("UnzipLocation"); + if (false != Strings.isValid(unzipLocation)) { + serviceItem.setUnzipLocation(unzipLocation.trim()); + } + } + } + + private void getHosts(IConfigurationElement parent, ServiceItem serviceItem) { + IConfigurationElement[] elements = parent.getChildren("Host"); + for (IConfigurationElement element : elements) { + String host = element.getAttribute("Name"); + if (false != Strings.isValid(host)) { + serviceItem.getHosts().add(host.trim()); + } + } + } + + private boolean getBooleanValue(String tagName, IConfigurationElement element) { + String value = element.getAttribute(tagName); + return false != Strings.isValid(value) && false != value.equalsIgnoreCase("true"); + } + + private void getExecutionArguments(ArgumentTypesEnum argType, IConfigurationElement element, ExecutionCommandFormatter commandFormatter) { + String rawArgs = element.getAttribute(argType.name()); + if (false != Strings.isValid(rawArgs)) { + String[] args = rawArgs.split(" "); + for (String arg : args) { + switch (argType) { + case VmArgs: + commandFormatter.addJvmArg(arg); + break; + case AppArgs: + commandFormatter.addApplicationArgs(arg); + break; + default: + break; + } + } + } + } + + private ExecutionCommandFormatter getExecutionCommandInstance(ExecutionTypesEnum configElement, IConfigurationElement config) { + ExecutionCommandFormatter toReturn = null; + String name = config.getAttribute(configElement.getEntryTag()); + if (false != Strings.isValid(name)) { + name = name.trim(); + switch (configElement) { + case EclipseApplication: + toReturn = new EclipseApplicationFormatter(name); + break; + case StandAloneApplication: + toReturn = new StandAloneApplicationFormatter(name); + break; + default: + break; + } + } + return toReturn; + } + +}
\ No newline at end of file diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/StandAloneApplicationFormatter.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/StandAloneApplicationFormatter.java new file mode 100644 index 00000000000..ac0974486d7 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/data/StandAloneApplicationFormatter.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.data; + +/** + * @author Roberto E. Escobar + */ +public class StandAloneApplicationFormatter extends ExecutionCommandFormatter { + private final String baseExecString = "nohup" + ServiceItem.EXEC_SEPARATOR + "#JAVA#"; + private String executionString; + + public StandAloneApplicationFormatter(String executionString) { + this.executionString = executionString; + } + + @Override + protected String buildExecString() { + String toReturn = baseExecString.replace("#JAVA#", "java"); + toReturn += + this.getJvmArgsString() + ServiceItem.EXEC_SEPARATOR + executionString + this.getApplicationArgsString(); + return toReturn; + } + + @Override + public void setServiceExecutionString(ServiceItem item) { + item.setStandAloneExecution(buildExecString()); + } + + @Override + public void setRemoteAllowed(ServiceItem item) { + item.setRemoteExecution(buildExecString()); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/ExecutePage.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/ExecutePage.java new file mode 100644 index 00000000000..bc27f666ee7 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/ExecutePage.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.pages; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.JiniGroupSelector; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceItem; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +public class ExecutePage extends DynamicWizardPage { + + private static final String TEMPORARY_JINI_GROUP = "<USE COMBO BOX FROM ABOVE>"; + private enum LabelEnum { + Service, User, Host; + } + + private Map<LabelEnum, Text> dataMap; + private FormattedText cmdText; + private FormattedText updateText; + private ServiceLaunchingInformation serviceInfo; + private JiniGroupSelector jiniGroupSelector; + + public ExecutePage(String pageName, String previous, String next, ServiceLaunchingInformation serviceInfo) { + super(pageName, previous, next); + this.serviceInfo = serviceInfo; + this.dataMap = new HashMap<LabelEnum, Text>(); + setTitle("Launch Service"); + setDescription("Through ssh the remote host is accessed and a list of commands are run that launch the selected service."); + setPageComplete(true); + } + + public void createControl(Composite parent) { + Group composite = new Group(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setText("Upload Info"); + + createLabelArea(composite); + if (false != serviceInfo.getServiceItem().isJiniGroupRequired()) { + jiniGroupSelector = new JiniGroupSelector(); + jiniGroupSelector.createJiniGroupWidget(composite); + } + createExecuteInfoGroup(composite); + createButtonArea(composite); + + setControl(composite); + } + + private void createLabelArea(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + dataMap.clear(); + for (LabelEnum labelEnum : LabelEnum.values()) { + new Label(composite, SWT.NONE).setText(labelEnum.toString() + ":"); + + Text updateable = new Text(composite, SWT.SINGLE); + updateable.setEditable(false); + updateable.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + dataMap.put(labelEnum, updateable); + } + } + + private void createExecuteInfoGroup(Composite parent) { + SashForm sashForm = new SashForm(parent, SWT.NONE); + sashForm.setLayout(new GridLayout()); + sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + sashForm.setOrientation(SWT.VERTICAL); + sashForm.SASH_WIDTH = 3; + + Group group = new Group(sashForm, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setText("Enter Commands To Execute:"); + + cmdText = new FormattedText(group, SWT.NONE, 50, 100, true); + cmdText.getStyledText().setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE)); + cmdText.getStyledText().addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + String cmds = cmdText.getStyledText().getText(); + String[] cmdList = cmds.split("\r\n"); + for (int i = 0; i < cmdList.length; i++) { + cmdList[i] = cmdList[i].trim(); + } + serviceInfo.setExecCmds(cmdList); + + } + + }); + + updateText = new FormattedText(sashForm, SWT.BORDER, 200, 300, false); + sashForm.setWeights(new int[] {3, 7}); + } + + public void createButtonArea(Composite parent) { + Composite buttonComposite = new Composite(parent, SWT.NONE); + buttonComposite.setLayout(new GridLayout(2, true)); + buttonComposite.setLayoutData(new GridData(SWT.END, SWT.END, false, false)); + + Button clearText = new Button(buttonComposite, SWT.PUSH); + clearText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + clearText.setText("Clear"); + clearText.setToolTipText("Clear the execution status window"); + clearText.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + updateText.clearTextArea(); + } + + }); + + final Button execute = new Button(buttonComposite, SWT.PUSH); + execute.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + execute.setText("Execute"); + execute.setToolTipText("Executes commands speficied int the command window on the remote host"); + execute.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + execute.setEnabled(false); + try { + String[] execCommands = serviceInfo.getExecCmds(); + if (null != jiniGroupSelector) { + serviceInfo.getServiceItem().setJiniGroup(jiniGroupSelector.getJiniGroupVmArg()); + + for (int index = 0; index < execCommands.length; index++) { + String temp = execCommands[index]; + if (temp.contains(TEMPORARY_JINI_GROUP)) { + execCommands[index] = + temp.replace(TEMPORARY_JINI_GROUP, serviceInfo.getServiceItem().getJiniGroup()); + } + } + } + String output = serviceInfo.getSSHConnection().executeCommandList(execCommands); + updateText.addText(output); + } catch (Exception ex) { + updateText.addText("\n" + ControlPlugin.getStackMessages(ex) + "\n", SWT.NORMAL, SWT.COLOR_RED); + } + execute.setEnabled(true); + } + }); + } + }); + } + + @Override + public void setVisible(boolean visible) { + this.cmdText.clearTextArea(); + this.dataMap.get(LabelEnum.Service).setText(serviceInfo.getServiceItem().getName()); + this.dataMap.get(LabelEnum.User).setText(serviceInfo.getUser()); + this.dataMap.get(LabelEnum.Host).setText(serviceInfo.getSelectedHost()); + + if (null != jiniGroupSelector) { + serviceInfo.getServiceItem().setJiniGroup(TEMPORARY_JINI_GROUP); + } + + String execute = + "cd " + serviceInfo.getUnzipLocation() + "\n" + serviceInfo.getServiceItem().getRemoteExecution().replaceAll( + ServiceItem.EXEC_SEPARATOR, " "); + + this.cmdText.addText(execute); + + super.setVisible(visible); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/HostInfoPage.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/HostInfoPage.java new file mode 100644 index 00000000000..fe05648c3af --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/HostInfoPage.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.pages; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.skynet.core.SkynetAuthentication; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchDataPersist; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +public class HostInfoPage extends DynamicWizardPage { + private Combo hostName; + private Text userName; + private ServiceLaunchingInformation serviceInfo; + private List<String> hosts; + + public HostInfoPage(String pageName, String previous, String next, ServiceLaunchingInformation serviceInfo) { + super(pageName, previous, next); + this.serviceInfo = serviceInfo; + this.hosts = new ArrayList<String>(); + setTitle("Host Information"); + setDescription("Please select a remote host to connect to and input a valid username."); + setPageComplete(false); + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NULL); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + composite.setLayout(gridLayout); + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 1; + gridData.grabExcessHorizontalSpace = true; + composite.setLayoutData(gridData); + createHostInfoGroup(composite); + createUserInfoGroup(composite); + setControl(composite); + } + + private void createHostInfoGroup(Composite parent) { + Group hostinfo = new Group(parent, SWT.NONE); + hostinfo.setText("Host: "); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + hostinfo.setLayout(gridLayout); + + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 1; + gridData.grabExcessHorizontalSpace = true; + hostinfo.setLayoutData(gridData); + + hostName = new Combo(hostinfo, SWT.SINGLE | SWT.BORDER); + hostName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + serviceInfo.setAvailableHosts(serviceInfo.getServiceItem().getHosts()); + hosts = serviceInfo.getAvailableHosts(); + for (String name : hosts) { + if (name != null && !name.equals("")) { + hostName.add(name); + } + } + + hostName.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + tryToGoToNext(); + } + }); + hostName.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + tryToGoToNext(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + + }); + } + + private void createUserInfoGroup(Composite parent) { + Group userinfo = new Group(parent, SWT.NONE); + userinfo.setText("User Name: "); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + userinfo.setLayout(gridLayout); + + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 1; + userinfo.setLayoutData(gridData); + + userName = new Text(userinfo, SWT.SINGLE | SWT.BORDER); + userName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + String name; + try { + name = SkynetAuthentication.getUser().getName(); + } catch (Exception ex) { + name = System.getProperty("user.name"); + } + userName.setText(name); + userName.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + tryToGoToNext(); + } + }); + } + + private void tryToGoToNext() { + if (Strings.isValid(userName.getText()) && Strings.isValid(this.hostName.getText())) { + setPageComplete(true); + } + } + + @Override + public void setVisible(boolean visible) { + serviceInfo.setAvailableHosts(serviceInfo.getServiceItem().getHosts()); + hosts = serviceInfo.getAvailableHosts(); + if (hostName != null && !hostName.isDisposed()) { + hostName.removeAll(); + for (String name : hosts) { + if (name != null && !name.equals("")) { + hostName.add(name); + } + } + hostName.select(0); + } + + super.setVisible(visible); + } + + public Combo getHostNameCombo() { + return hostName; + } + + @Override + public boolean onNextPressed() { + serviceInfo.setUser(userName.getText()); + serviceInfo.setSelectedHost(hostName.getText()); + serviceInfo.setUnzipLocation(serviceInfo.getServiceItem().getUnzipLocation() + "/" + serviceInfo.getServiceItem().getPlugin()); + + ServiceLaunchDataPersist data = ServiceLaunchDataPersist.getInstance(); + data.saveHostName(hostName.getText()); + data.saveLastServiceLaunched(serviceInfo.getServiceItem().getName()); + + try { + serviceInfo.connectToRemoteHost(); + } catch (Exception ex) { + StringWriter error = new StringWriter(); + ex.printStackTrace(new PrintWriter(error)); + MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Unable to connect to the remote host", ControlPlugin.getStackMessages(ex)); + return false; + } + return true; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/LocalLaunchPage.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/LocalLaunchPage.java new file mode 100644 index 00000000000..bbce2040b3e --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/LocalLaunchPage.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.pages; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchWizard; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.widgets.EclipseApplicationLaunchWidget; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.widgets.ILaunchWidget; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.widgets.StandAloneApplicationLaunchWidget; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +/** + * @author Roberto E. Escobar + */ +public class LocalLaunchPage extends DynamicWizardPage { + + private ServiceLaunchingInformation serviceInfo; + + private Button eclipseApplicationButton; + private Button standAloneButton; + private StackLayout stackLayout; + private Composite stackedComposite; + private Map<Button, ILaunchWidget> widgets; + + public LocalLaunchPage(String pageName, String previous, String next, ServiceLaunchingInformation serviceInfo) { + super(pageName, previous, next); + this.serviceInfo = serviceInfo; + setTitle("Local Launch"); + setDescription("Select a local launch method to execute service."); + setPageComplete(true); + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + createLaunchTypeButtonArea(composite); + + stackedComposite = new Composite(composite, SWT.NONE); + stackedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + stackLayout = new StackLayout(); + stackedComposite.setLayout(stackLayout); + + ServiceLaunchWizard wizard = (ServiceLaunchWizard) this.getWizard(); + + widgets = new HashMap<Button, ILaunchWidget>(); + widgets.put(eclipseApplicationButton, new EclipseApplicationLaunchWidget(serviceInfo)); + widgets.put(standAloneButton, new StandAloneApplicationLaunchWidget(serviceInfo, wizard)); + + Set<Button> keys = widgets.keySet(); + for (Button key : keys) { + ILaunchWidget widget = widgets.get(key); + widget.create(stackedComposite); + } + determineDefaultSelection(); + registerListeners(); + + setPageComplete(true); + setControl(composite); + } + + private void determineDefaultSelection() { + Button key = null; + if (serviceInfo.getServiceItem().isStandAloneAllowed()) { + standAloneButton.setEnabled(true); + standAloneButton.setSelection(true); + key = standAloneButton; + } + + if (serviceInfo.getServiceItem().isEclipseAppAllowed()) { + eclipseApplicationButton.setEnabled(true); + eclipseApplicationButton.setSelection(true); + key = eclipseApplicationButton; + } + + if (standAloneButton.getSelection() && eclipseApplicationButton.getSelection()) { + standAloneButton.setSelection(false); + } + + if (key != null) { + stackLayout.topControl = widgets.get(key).getControl(); + stackedComposite.layout(); + } + } + + @Override + public void setVisible(boolean visible) { + for (Button button : widgets.keySet()) { + widgets.get(button).refresh(); + button.setEnabled(false); + button.setSelection(false); + } + determineDefaultSelection(); + super.setVisible(visible); + } + + private void createLaunchTypeButtonArea(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setText("Select how to launch the application locally"); + + eclipseApplicationButton = new Button(group, SWT.RADIO); + eclipseApplicationButton.setEnabled(false); + eclipseApplicationButton.setText("As an Eclipse Application"); + eclipseApplicationButton.setToolTipText("This option launches the selected service\n" + "as an Eclipse application. The executable will be selected from \n" + "the latest plugin folder under the eclipse installation location.\n" + "The Eclipse framework will be used to execute the application."); + + standAloneButton = new Button(group, SWT.RADIO); + standAloneButton.setEnabled(false); + standAloneButton.setText("As a Standalone Application"); + standAloneButton.setToolTipText("This option launches the selected service\n" + "as a standalone application under the specified directory."); + } + + private void registerListeners() { + eclipseApplicationButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + stackLayout.topControl = widgets.get(eclipseApplicationButton).getControl(); + stackedComposite.layout(); + + } + }); + + standAloneButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + stackLayout.topControl = widgets.get(standAloneButton).getControl(); + stackedComposite.layout(); + } + }); + } + + @Override + public void dispose() { + if (widgets != null) { + super.dispose(); + Set<Button> keys = widgets.keySet(); + for (Button key : keys) { + ILaunchWidget widget = widgets.get(key); + widget.dispose(); + } + } + } + + @Override + public boolean isPageComplete() { + return true; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/LocalRemotePage.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/LocalRemotePage.java new file mode 100644 index 00000000000..f88918762c4 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/LocalRemotePage.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.pages; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchWizard; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceLaunchConfig; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +public class LocalRemotePage extends DynamicWizardPage { + + private ServiceLaunchingInformation serviceInfo; + private Button local; + private Button remote; + private ServiceLaunchWizard wizard; + private Composite composite; + + public LocalRemotePage(String pageName, String previous, String next, ServiceLaunchingInformation serviceInfo, ServiceLaunchWizard wizard) { + super(pageName, previous, next); + this.serviceInfo = serviceInfo; + setTitle("Local/Remote Launch"); + setDescription("Please select local or remote for the launching of the selected service."); + setPageComplete(true); + this.wizard = wizard; + } + + public void createControl(Composite parent) { + composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + createHostInfoGroup(composite); + setControl(composite); + } + + private void createHostInfoGroup(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + group.setText("Launch Location"); + + local = new Button(group, SWT.RADIO); + local.setText("Local"); + local.setSelection(true); + local.setEnabled(false); + + remote = new Button(group, SWT.RADIO); + remote.setText("Remote"); + remote.setEnabled(false); + + if (ServiceLaunchConfig.getInstance().getLocalServiceItems().size() > 0) { + local.setEnabled(true); + } else { + remote.setSelection(true); + } + + if (ServiceLaunchConfig.getInstance().getRemoteServiceItems().size() > 0) { + remote.setEnabled(true); + } else { + local.setSelection(true); + } + + } + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + } + + @Override + public boolean canFlipToNextPage() { + return true; + } + + @Override + public boolean onNextPressed() { + ServicePage servicePage = ((ServicePage) this.getNextPage()); + servicePage.setIsLocal(local.getSelection()); + serviceInfo.setIsLocal(local.getSelection()); + + if (local.getSelection()) { + String unzipLocationTitle = "Execute Local Service"; + servicePage.setNextPage(unzipLocationTitle); + wizard.addPage(new LocalLaunchPage(unzipLocationTitle, servicePage.getName(), "", serviceInfo)); + } else { + String hostInformationTitle = "Host Information"; + String uploadServiceTitle = "Upload service"; + String executeServiceTitle = "Execute Remote Service"; + + servicePage.setNextPage(hostInformationTitle); + IWizardPage[] pagesToAdd = + new IWizardPage[] { + new HostInfoPage(hostInformationTitle, servicePage.getName(), uploadServiceTitle, serviceInfo), + new UploadPage(uploadServiceTitle, hostInformationTitle, executeServiceTitle, serviceInfo), + new ExecutePage(executeServiceTitle, uploadServiceTitle, "", serviceInfo)}; + for (IWizardPage page : pagesToAdd) { + wizard.addPage(page); + } + } + return true; + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/ServicePage.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/ServicePage.java new file mode 100644 index 00000000000..5e5847e8369 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/ServicePage.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.pages; + +import java.util.Collection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceItem; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceLaunchConfig; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +public class ServicePage extends DynamicWizardPage { + + private ListViewer listViewer; + private ServiceLaunchingInformation serviceInfo; + private Collection<ServiceItem> localList; + private Collection<ServiceItem> remoteList; + private Group group; + private boolean isLocal; + + public ServicePage(String pageName, String previous, String next, ServiceLaunchingInformation serviceInfo) { + super(pageName, previous, next); + this.serviceInfo = serviceInfo; + this.isLocal = true; + setTitle("Service Selection"); + setDescription("Please select the service you would like to launch."); + setPageComplete(false); + } + + public void setIsLocal(boolean isLocal) { + this.isLocal = isLocal; + manageInputList(); + } + + public void createControl(Composite parent) { + group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + group.setText("Service Selection"); + + listViewer = new ListViewer(group, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + GridData d = new GridData(SWT.FILL, SWT.FILL, true, true); + listViewer.getControl().setLayoutData(d); + listViewer.setContentProvider(new ListContentProvider()); + listViewer.setLabelProvider(new ListLabelProvider()); + listViewer.setSorter(new ListSorter()); + + listViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + if (selection != null && !selection.isEmpty()) { + ServiceItem item = (ServiceItem) selection.getFirstElement(); + serviceInfo.setServiceItem(item); + serviceInfo.setAvailableHosts(item.getHosts()); + setPageComplete(true); + } else { + setPageComplete(false); + } + } + }); + + localList = ServiceLaunchConfig.getInstance().getLocalServiceItems(); + remoteList = ServiceLaunchConfig.getInstance().getRemoteServiceItems(); + manageInputList(); + setControl(group); + } + + private void manageInputList() { + Collection<ServiceItem> listToSet = this.localList; + if (!isLocal) { + listToSet = this.remoteList; + } + if (listViewer != null && !listViewer.getControl().isDisposed()) { + listViewer.setInput(listToSet); + serviceInfo.setServiceItem(null); + } + } + + private class ListLabelProvider extends LabelProvider { + public Image getImage(Object element) { + return null; + } + + public String getText(Object element) { + return ((ServiceItem) element).getName(); + } + } + + private class ListContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + Collection<?> collection = (Collection<?>) inputElement; + return collection.toArray(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + public class ListSorter extends ViewerSorter { + public int compare(Viewer viewer, Object e1, Object e2) { + ServiceItem item1 = (ServiceItem) e1; + ServiceItem item2 = (ServiceItem) e2; + return item1.compareTo(item2); + } + } + + @Override + public void dispose() { + super.dispose(); + if (listViewer != null) { + listViewer.getList().dispose(); + } + } + + @Override + public boolean onNextPressed() { + boolean toReturn = false; + IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); + if (selection != null && !selection.isEmpty()) { + ServiceItem item = (ServiceItem) selection.getFirstElement(); + serviceInfo.setServiceItem(item); + serviceInfo.setAvailableHosts(item.getHosts()); + toReturn = true; + } + return toReturn; + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/UploadPage.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/UploadPage.java new file mode 100644 index 00000000000..b27beb640f2 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/pages/UploadPage.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.pages; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.jobs.TextDisplayHelper; +import org.eclipse.osee.framework.ui.service.control.jobs.UploadRemoteFileJob; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.swt.DynamicWizardPage; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ProgressBar; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +public class UploadPage extends DynamicWizardPage { + + public enum LabelEnum { + Service, User, Host, Host_Upload_Location; + + public String toString() { + return this.name().replaceAll("_", " "); + } + } + + private Map<LabelEnum, Text> dataMap; + + private ServiceLaunchingInformation serviceInfo; + private FormattedText cmdText; + private ProgressBar progress; + + private static final Image HELP_IMAGE = ControlPlugin.getInstance().getImage("help.gif"); + + public UploadPage(String pageName, String previous, String next, ServiceLaunchingInformation serviceInfo) { + super(pageName, previous, next); + this.serviceInfo = serviceInfo; + this.dataMap = new HashMap<LabelEnum, Text>(); + setTitle("Upload Service Selection"); + setDescription("An scp client will upload the files required by the service to the host machine at the given location."); + setPageComplete(true); + } + + public void createControl(Composite parent) { + Group composite = new Group(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setText("Upload Info"); + + createLabelArea(composite); + + cmdText = new FormattedText(composite, SWT.NONE, 200, 300); + cmdText.getStyledText().setEditable(false); + + createUploadBarArea(composite); + + setControl(composite); + } + + private void createLabelArea(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + dataMap.clear(); + for (LabelEnum labelEnum : LabelEnum.values()) { + new Label(composite, SWT.NONE).setText(labelEnum.toString() + ":"); + + Text updateable; + if (labelEnum.equals(LabelEnum.Host_Upload_Location)) { + updateable = new Text(composite, SWT.SINGLE | SWT.BORDER); + updateable.setEditable(true); + } else { + updateable = new Text(composite, SWT.SINGLE); + updateable.setEditable(false); + } + updateable.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + dataMap.put(labelEnum, updateable); + } + } + + public void createUploadBarArea(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + progress = new ProgressBar(composite, SWT.HORIZONTAL); + progress.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + progress.setEnabled(true); + progress.setMinimum(0); + progress.setMaximum(20); + progress.setSelection(0); + + Composite buttonComposite = new Composite(composite, SWT.NONE); + buttonComposite.setLayout(new GridLayout(3, true)); + buttonComposite.setLayoutData(new GridData(SWT.END, SWT.END, false, false)); + + Button clearText = new Button(buttonComposite, SWT.PUSH); + clearText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + clearText.setText("Clear"); + clearText.setToolTipText("Clear the execution status window"); + clearText.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + progress.setSelection(0); + cmdText.clearTextArea(); + } + + }); + + Button upload = new Button(buttonComposite, SWT.NONE); + upload.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + upload.setText("Upload"); + upload.setToolTipText("Uploads files to the remote host"); + upload.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + Job job = + new UploadRemoteFileJob("Uploading Files", serviceInfo, new TextDisplayHelper(cmdText), + progress, dataMap); + job.setUser(true); + job.setPriority(Job.LONG); + job.schedule(); + } + }); + } + }); + + final Label help = new Label(buttonComposite, SWT.NONE); + help.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); + help.setImage(HELP_IMAGE); + help.setToolTipText("Double-Click to open help dialog."); + help.addMouseListener(new MouseListener() { + + public void mouseDoubleClick(MouseEvent e) { + MessageDialog.openInformation( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Upload Help", + "Upload Hints: \n\n" + "1. If the service binds to a static port, ensure that the \n" + "service to be launched is not running on the target machine.\n\n" + "2. If the remote directory used to upload files to exists previously, \n" + "make sure that the user login has write/execute permissions for that folder.\n"); + } + + public void mouseDown(MouseEvent e) { + } + + public void mouseUp(MouseEvent e) { + } + + }); + } + + @Override + public void setVisible(boolean visible) { + this.dataMap.get(LabelEnum.Service).setText(serviceInfo.getServiceItem().getName()); + this.dataMap.get(LabelEnum.User).setText(serviceInfo.getUser()); + this.dataMap.get(LabelEnum.Host).setText(serviceInfo.getSelectedHost()); + + String unzipLocation = serviceInfo.getUnzipLocation(); + if (unzipLocation == null || unzipLocation.equals("")) { + serviceInfo.setUnzipLocation(serviceInfo.getServiceItem().getUnzipLocation() + "/" + serviceInfo.getServiceItem().getPlugin()); + } + this.dataMap.get(LabelEnum.Host_Upload_Location).setText(serviceInfo.getUnzipLocation()); + super.setVisible(visible); + } + + @Override + public boolean onNextPressed() { + serviceInfo.setUnzipLocation(dataMap.get(LabelEnum.Host_Upload_Location).getText()); + return super.onNextPressed(); + } + +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/EclipseApplicationLaunchWidget.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/EclipseApplicationLaunchWidget.java new file mode 100644 index 00000000000..5f45c6cef8d --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/EclipseApplicationLaunchWidget.java @@ -0,0 +1,251 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.widgets; + +import java.io.File; +import java.net.URL; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.jobs.EclipseApplicationLaunchJob; +import org.eclipse.osee.framework.ui.service.control.jobs.TextDisplayHelper; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.JiniGroupSelector; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.ServiceItem; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Shell; +import org.osgi.framework.Bundle; + +/** + * @author Roberto E. Escobar + */ +public class EclipseApplicationLaunchWidget implements ILaunchWidget { + + private Control control; + private ServiceLaunchingInformation serviceInfo; + private FormattedText serviceInfoText; + private FormattedText executionResultText; + private StyledText javaCompilerText; + private File latestPlugin; + private File localLocation; + private String javaCompiler; + private Shell shell; + private JiniGroupSelector groupSelector; + private TextDisplayHelper displayHelper; + + public EclipseApplicationLaunchWidget(ServiceLaunchingInformation serviceInfo) { + this.serviceInfo = serviceInfo; + } + + public void create(Composite parent) { + shell = parent.getShell(); + + SashForm composite = new SashForm(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.SASH_WIDTH = 3; + composite.setOrientation(SWT.VERTICAL); + + Composite infoComposite = new Composite(composite, SWT.NONE); + infoComposite.setLayout(new GridLayout()); + infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + createControlsArea(infoComposite); + createJavaCompilerArea(infoComposite); + + createExecutionArea(composite); + + int[] weights = null; + if (false != serviceInfo.getServiceItem().isJiniGroupRequired()) { + groupSelector = new JiniGroupSelector(); + groupSelector.createJiniGroupWidget(infoComposite); + weights = new int[] {4, 6}; + } else { + weights = new int[] {4, 6}; + } + + composite.setWeights(weights); + control = composite; + displayHelper = new TextDisplayHelper(executionResultText); + } + + private void createControlsArea(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + group.setText("Service Details"); + + serviceInfoText = new FormattedText(group, SWT.NONE, 100, 400, false); + refresh(); + } + + private void createExecutionArea(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + group.setText("Execution Log"); + + executionResultText = new FormattedText(group, SWT.NONE, 200, 400); + executionResultText.setTextAreaBackground(SWT.COLOR_WHITE); + executionResultText.getStyledText().setEditable(false); + + Composite composite = new Composite(group, SWT.NONE); + composite.setLayout(new GridLayout(2, true)); + composite.setLayoutData(new GridData(SWT.END, SWT.END, true, false)); + + Button clear = new Button(composite, SWT.NONE); + clear.setLayoutData(new GridData(SWT.END, SWT.END, false, false)); + clear.setText("Clear"); + clear.setToolTipText("Clear the execution status window"); + clear.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + executionResultText.clearTextArea(); + } + + }); + + Button execute = new Button(composite, SWT.NONE); + execute.setLayoutData(new GridData(SWT.END, SWT.END, false, false)); + execute.setText("Execute"); + execute.setToolTipText("Executes service as an Eclipse Application"); + execute.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + getEclipseInformation(); + javaCompiler = javaCompilerText.getText(); + if (null != groupSelector) { + serviceInfo.getServiceItem().setJiniGroup(groupSelector.getJiniGroupVmArg()); + } + Job job = + new EclipseApplicationLaunchJob("Eclipse Application Launch", javaCompiler, latestPlugin, + serviceInfo, displayHelper); + job.setUser(true); + job.setPriority(Job.LONG); + job.schedule(); + } + }); + } + + private void createJavaCompilerArea(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout(2, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setText("Select a java runtime location"); + + final String javaHome = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; + javaCompiler = javaHome; + + javaCompilerText = new StyledText(group, SWT.BORDER); + javaCompilerText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + javaCompilerText.setText(javaHome); + + javaCompilerText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + javaCompiler = javaCompilerText.getText(); + } + }); + + Button fileDialog = new Button(group, SWT.NONE); + fileDialog.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); + fileDialog.setImage(ControlPlugin.getInstance().getImage("file.gif")); + fileDialog.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + String defaultDir = javaCompilerText.getText(); + File dir = new File(defaultDir); + if (dir.isFile() || dir.isDirectory()) + dialog.setFilterPath(defaultDir); + else { + dialog.setFilterPath(javaHome); + } + + dialog.setFilterExtensions(new String[] {"java"}); + + dialog.setFilterNames(new String[] {"java"}); + + String result = dialog.open(); + if (result != null && !result.equals("")) { + javaCompilerText.setText(result); + javaCompiler = result; + } + } + }); + } + + private void getEclipseInformation() { + latestPlugin = null; + try { + Bundle bundle = Platform.getBundle(serviceInfo.getServiceItem().getPlugin()); + URL url = bundle.getEntry("/"); + URL resolvedURL = FileLocator.resolve(url); + latestPlugin = new File(resolvedURL.getFile()); + } catch (Exception ex) { + if (executionResultText != null && !executionResultText.isDisposed()) { + executionResultText.addText(ControlPlugin.getStackMessages(ex) + "\n\n", SWT.NORMAL, SWT.COLOR_RED); + } + } + + localLocation = new File(Platform.getInstallLocation().getURL().getFile()); + } + + public Control getControl() { + return control; + } + + public void dispose() { + if (control != null && !control.isDisposed()) { + control.dispose(); + } + if (groupSelector != null) { + groupSelector.dispose(); + } + displayHelper.disposeProcessHandling(); + } + + public void refresh() { + getEclipseInformation(); + serviceInfoText.clearTextArea(); + + serviceInfoText.addText("\tService Name:\t", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + serviceInfoText.addText(serviceInfo.getServiceItem().getName() + "\n"); + serviceInfoText.addText("\tPlugin:\t", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + serviceInfoText.addText((latestPlugin != null ? latestPlugin.toString() : "<Plugin Not Available>") + "\n"); + serviceInfoText.addText("\tEclipse Install Location:\t", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + serviceInfoText.addText(localLocation.toString() + "\n"); + serviceInfoText.addText("\tExecution String:\t", SWT.BOLD, SWT.COLOR_DARK_BLUE, true); + + String execString = serviceInfo.getServiceItem().getLocalExecution().replaceAll(ServiceItem.EXEC_SEPARATOR, " "); + execString = execString.replace("java", "<JAVA_COMPILER>"); + + serviceInfoText.addText(execString + "\n"); + } +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/ILaunchWidget.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/ILaunchWidget.java new file mode 100644 index 00000000000..36103a3c029 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/ILaunchWidget.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.widgets; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Roberto E. Escobar + */ +public interface ILaunchWidget { + + void create(Composite parent); + + void refresh(); + + Control getControl(); + + void dispose(); +} diff --git a/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/StandAloneApplicationLaunchWidget.java b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/StandAloneApplicationLaunchWidget.java new file mode 100644 index 00000000000..a699613ea82 --- /dev/null +++ b/org.eclipse.osee.framework.ui.service.control/src/org/eclipse/osee/framework/ui/service/control/wizards/launcher/widgets/StandAloneApplicationLaunchWidget.java @@ -0,0 +1,274 @@ +/******************************************************************************* + * 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.service.control.wizards.launcher.widgets; + +import java.io.File; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.osee.framework.ui.service.control.ControlPlugin; +import org.eclipse.osee.framework.ui.service.control.jobs.StandAloneApplicationLaunchJob; +import org.eclipse.osee.framework.ui.service.control.jobs.TextDisplayHelper; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchWizard; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.ServiceLaunchingInformation; +import org.eclipse.osee.framework.ui.service.control.wizards.launcher.data.JiniGroupSelector; +import org.eclipse.osee.framework.ui.swt.FormattedText; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.ProgressBar; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class StandAloneApplicationLaunchWidget implements ILaunchWidget { + + private Control control; + private StyledText scriptOutputText; + private StyledText javaCompilerText; + private ServiceLaunchingInformation serviceInfo; + // private ServiceLaunchWizard wizard; + private Shell shell; + private FormattedText cmdText; + private String localUnzipLocation; + private String javaCompiler; + private ProgressBar progress; + private JiniGroupSelector groupSelector; + private TextDisplayHelper displayHelper; + + public StandAloneApplicationLaunchWidget(ServiceLaunchingInformation serviceInfo, ServiceLaunchWizard wizard) { + this.serviceInfo = serviceInfo; + // this.wizard = wizard; + this.localUnzipLocation = ""; + this.javaCompiler = ""; + } + + public void create(Composite parent) { + shell = parent.getShell(); + SashForm composite = new SashForm(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.SASH_WIDTH = 3; + composite.setOrientation(SWT.VERTICAL); + + Composite infoComposite = new Composite(composite, SWT.NONE); + infoComposite.setLayout(new GridLayout()); + infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + createStandaloneComponents(infoComposite); + createJavaCompilerArea(infoComposite); + + createExecutionArea(composite); + + int[] weights = null; + if (false != serviceInfo.getServiceItem().isJiniGroupRequired()) { + groupSelector = new JiniGroupSelector(); + groupSelector.createJiniGroupWidget(infoComposite); + weights = new int[] {4, 6}; + } else { + weights = new int[] {3, 7}; + } + composite.setWeights(weights); + + control = composite; + displayHelper = new TextDisplayHelper(cmdText); + } + + public Control getControl() { + return control; + } + + private void createExecutionArea(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + group.setText("Execution Log"); + + cmdText = new FormattedText(group, SWT.NONE, 200, 400); + cmdText.setTextAreaBackground(SWT.COLOR_WHITE); + cmdText.getStyledText().setEditable(false); + + Composite composite = new Composite(group, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + progress = new ProgressBar(composite, SWT.HORIZONTAL); + progress.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + progress.setEnabled(true); + progress.setMinimum(0); + progress.setMaximum(20); + progress.setSelection(0); + + Composite buttonComposite = new Composite(composite, SWT.NONE); + buttonComposite.setLayout(new GridLayout(2, true)); + buttonComposite.setLayoutData(new GridData(SWT.END, SWT.END, false, false)); + + Button clear = new Button(buttonComposite, SWT.NONE); + clear.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + clear.setText("Clear"); + clear.setToolTipText("Clear the execution status window"); + clear.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + cmdText.clearTextArea(); + progress.setSelection(0); + } + }); + + Button execute = new Button(buttonComposite, SWT.NONE); + execute.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + execute.setText("Execute"); + execute.setToolTipText("Execute the application"); + execute.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + File localLocation = + new File( + localUnzipLocation + File.separator + serviceInfo.getServiceItem().getPlugin() + File.separator); + javaCompiler = javaCompilerText.getText(); + if (null != groupSelector) { + serviceInfo.getServiceItem().setJiniGroup(groupSelector.getJiniGroupVmArg()); + } + Job job = + new StandAloneApplicationLaunchJob("Launch Stand Alone Application", javaCompiler, + localLocation, serviceInfo, displayHelper, progress); + job.setUser(true); + job.setPriority(Job.LONG); + job.schedule(); + } + }); + } + }); + } + + private void createStandaloneComponents(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout(2, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setText("Select a location in the local file system to launch the Application"); + + final String homedir = System.getProperty("user.home") + File.separator + "oseeservices"; + localUnzipLocation = homedir; + + scriptOutputText = new StyledText(group, SWT.BORDER); + scriptOutputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + scriptOutputText.setText(homedir); + + scriptOutputText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + localUnzipLocation = scriptOutputText.getText(); + } + }); + + Button fileDialog = new Button(group, SWT.NONE); + fileDialog.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); + fileDialog.setImage(ControlPlugin.getInstance().getImage("file.gif")); + fileDialog.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); + String defaultDir = scriptOutputText.getText(); + File dir = new File(defaultDir); + if (dir.isFile() || dir.isDirectory()) + dialog.setFilterPath(defaultDir); + else { + dialog.setFilterPath(homedir); + } + + String result = dialog.open(); + if (result != null && !result.equals("")) { + scriptOutputText.setText(result); + localUnzipLocation = result; + } + } + }); + } + + private void createJavaCompilerArea(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout(2, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setText("Select a java compiler location"); + + final String javaHome = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; + javaCompiler = javaHome; + + javaCompilerText = new StyledText(group, SWT.BORDER); + javaCompilerText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + javaCompilerText.setText(javaHome); + + javaCompilerText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + javaCompiler = javaCompilerText.getText(); + } + }); + + Button fileDialog = new Button(group, SWT.NONE); + fileDialog.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); + fileDialog.setImage(ControlPlugin.getInstance().getImage("file.gif")); + fileDialog.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + String defaultDir = javaCompilerText.getText(); + File dir = new File(defaultDir); + if (dir.isFile() || dir.isDirectory()) + dialog.setFilterPath(defaultDir); + else { + dialog.setFilterPath(javaHome); + } + + dialog.setFilterExtensions(new String[] {"java"}); + + dialog.setFilterNames(new String[] {"java"}); + + String result = dialog.open(); + if (result != null && !result.equals("")) { + javaCompilerText.setText(result); + javaCompiler = result; + } + } + }); + } + + public void dispose() { + if (scriptOutputText != null && !scriptOutputText.isDisposed()) { + scriptOutputText.dispose(); + } + if (control != null && !control.isDisposed()) { + control.dispose(); + } + if (groupSelector != null) { + groupSelector.dispose(); + } + displayHelper.disposeProcessHandling(); + } + + public void refresh() { + } +} |