Author: bfitzpat
Date: 2012-02-02 12:33:19 -0500 (Thu, 02 Feb 2012)
New Revision: 38397
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/horizontalTreeLayout.gif
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/radialLayout.gif
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/refresh.gif
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/verticalTreeLayout.gif
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBDomParser.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNode.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNodeWithChildren.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBVisualizerView.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/FileSelectionGroup.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ViewerFileFilter.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/WorkbenchFileSelectionDialog.java
Modified:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/META-INF/MANIFEST.MF
trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.properties
trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.xml
trunk/esb/plugins/org.jboss.tools.esb.project.ui/pom.xml
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/ESBProjectPlugin.java
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java
Log:
[JBIDE-10726] Moving the ESB visualizer into the project.ui project
Modified: trunk/esb/plugins/org.jboss.tools.esb.project.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/esb/plugins/org.jboss.tools.esb.project.ui/META-INF/MANIFEST.MF 2012-02-02
15:31:46 UTC (rev 38396)
+++ trunk/esb/plugins/org.jboss.tools.esb.project.ui/META-INF/MANIFEST.MF 2012-02-02
17:33:19 UTC (rev 38397)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.jboss.tools.esb.project.ui;singleton:=true
-Bundle-Version: 1.5.1.qualifier
+Bundle-Version: 1.5.2.qualifier
Bundle-Activator: org.jboss.tools.esb.project.ui.ESBProjectPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
@@ -36,7 +36,9 @@
org.jboss.ide.eclipse.as.ui;bundle-version="1.0.0",
org.jboss.ide.eclipse.as.wtp.core;bundle-version="1.0.0",
org.jboss.ide.eclipse.as.core;bundle-version="1.0.0",
- org.jboss.tools.common.ui;bundle-version="3.1.0"
+ org.jboss.tools.common.ui;bundle-version="3.1.0",
+ org.eclipse.zest.core,
+ org.eclipse.zest.layouts
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor.0
Eclipse-RegisterBuddy: org.eclipse.jst.ws.annotations.core
Added: trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/horizontalTreeLayout.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/horizontalTreeLayout.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/radialLayout.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/radialLayout.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/refresh.gif
===================================================================
(Binary files differ)
Property changes on: trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/refresh.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/verticalTreeLayout.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/icons/verticalTreeLayout.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.properties
===================================================================
--- trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.properties 2012-02-02 15:31:46
UTC (rev 38396)
+++ trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.properties 2012-02-02 17:33:19
UTC (rev 38397)
@@ -3,4 +3,12 @@
Preference_Page_Runtimes=JBoss ESB Runtimes
Bundle-Vendor.0 = JBoss by Red Hat
Bundle-Name.0 = JBoss ESB Project UI Plugin
-annotations-category = JBoss ESB
\ No newline at end of file
+annotations-category = JBoss ESB
+esb.project.wizard.name = ESB Project
+esb.file.decorator.label = JBoss ESB Project Decorator
+esb.file.classpathContainerPage.name = JBoss ESB Libraries
+esb.file.category.name = ESB
+esb.file.wizard.name = ESB File
+esb.file.wizard.description = ESB File
+visualizer.view.category = JBoss ESB
+visualizer.view.name = JBoss ESB Configuration Visualizer
\ No newline at end of file
Modified: trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.xml
===================================================================
--- trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.xml 2012-02-02 15:31:46 UTC
(rev 38396)
+++ trunk/esb/plugins/org.jboss.tools.esb.project.ui/plugin.xml 2012-02-02 17:33:19 UTC
(rev 38397)
@@ -8,7 +8,7 @@
class="org.jboss.tools.esb.project.ui.wizards.ESBProjectWizard"
icon="$nl$/icons/wizards/esb.gif"
id="JBoss.ESB.Project.Wizard"
- name="ESB Project"
+ name="%esb.project.wizard.name"
project="true">
</wizard>
</extension>
@@ -52,7 +52,7 @@
<decorator
class="org.jboss.tools.esb.project.ui.ESBProjectDecorator"
id="org.jboss.tools.esb.project.ui.decorator"
- label="JBoss ESB Project Decorator"
+ label="%esb.file.decorator.label"
lightweight="true"
location="TOP_LEFT"
state="true">
@@ -73,7 +73,7 @@
<classpathContainerPage
class="org.jboss.tools.esb.project.ui.wizards.pages.JBossESBRuntimeContainerPage"
id="org.jboss.esb.runtime.classpath"
- name="JBoss ESB Libraries">
+ name="%esb.file.classpathContainerPage.name">
</classpathContainerPage>
</extension>
@@ -81,17 +81,17 @@
<extension
point="org.eclipse.ui.exportWizards">
<category
- name="ESB"
+ name="%esb.file.category.name"
id="org.jboss.tools.esb.category">
</category>
<wizard
- name="ESB File"
+ name="%esb.file.wizard.name"
icon="icons/obj16/esb_module.gif"
class="org.jboss.tools.esb.project.ui.wizards.export.ESBComponentExportWizard"
category="org.jboss.tools.esb.category"
id="org.jboss.tools.esb.project.ui.wizards.temp.ESBExportWizard">
<description>
- ESB File
+ %esb.file.wizard.description
</description>
<selection
class="org.eclipse.core.resources.IResource">
@@ -154,5 +154,41 @@
name="AttachmentParam">
</annotation>
</extension>
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.jboss.tools.esb.visualizer"
+ name="%visualizer.view.category">
+ </category>
+ <view
+ allowMultiple="false"
+ category="org.jboss.tools.esb.visualizer"
+
class="org.jboss.tools.esb.project.ui.visualizer.ESBVisualizerView"
+ icon="icons/esb/esb_file.gif"
+ id="org.jboss.tools.esb.visualizer.views.ESBVisualizerView"
+ name="%visualizer.view.name">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension
+ targetID="org.eclipse.ui.resourcePerspective">
+ <showInPart
+ id="org.jboss.tools.esb.visualizer.views.ESBVisualizerView">
+ </showInPart>
+ </perspectiveExtension>
+ <perspectiveExtension
+ targetID="org.eclipse.jst.j2ee.J2EEPerspective">
+ <showInPart
+ id="org.jboss.tools.esb.visualizer.views.ESBVisualizerView">
+ </showInPart>
+ </perspectiveExtension>
+ <perspectiveExtension
+ targetID="org.jboss.tools.common.ui.JBossPerspective">
+ <showInPart
+ id="org.jboss.tools.esb.visualizer.views.ESBVisualizerView">
+ </showInPart>
+ </perspectiveExtension>
+ </extension>
</plugin>
Modified: trunk/esb/plugins/org.jboss.tools.esb.project.ui/pom.xml
===================================================================
--- trunk/esb/plugins/org.jboss.tools.esb.project.ui/pom.xml 2012-02-02 15:31:46 UTC (rev
38396)
+++ trunk/esb/plugins/org.jboss.tools.esb.project.ui/pom.xml 2012-02-02 17:33:19 UTC (rev
38397)
@@ -9,7 +9,7 @@
</parent>
<groupId>org.jboss.tools.esb.plugins</groupId>
<artifactId>org.jboss.tools.esb.project.ui</artifactId>
- <version>1.5.1-SNAPSHOT</version>
+ <version>1.5.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
Modified:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/ESBProjectPlugin.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/ESBProjectPlugin.java 2012-02-02
15:31:46 UTC (rev 38396)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/ESBProjectPlugin.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.esb.project.ui;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -60,4 +62,22 @@
return plugin;
}
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+ /**
+ * Log a message
+ * @param ex
+ */
+ public static void log(Throwable ex) {
+ plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, Status.OK, "No
message", ex));
+ }
}
Modified:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties 2012-02-02
15:31:46 UTC (rev 38396)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties 2012-02-02
17:33:19 UTC (rev 38397)
@@ -51,6 +51,8 @@
JBossRuntimeListFieldEditor_ErrorMessageAtLeastOneJar=The library must contain at least
one jar.
+ESBDomParser_Providers_Label=Providers
+ESBDomParser_Services_Label=Services
ESBFacetInstallationPage_Button_Text_New=New
ESBFacetInstallationPage_Default_SRC_Folder=src
ESBFacetInstallationPage_Description=Configure project structure and classpath
@@ -78,4 +80,14 @@
ESBExportWizard_NotValidProject=Project "{0}" is not a valid ESB Project
ESBExportWizard_Title=ESB Export
ESBExportWizard_Description=Export an ESB project to the local file system.
-ESBExportWizard_ESBProject=ESB Project\:
\ No newline at end of file
+ESBExportWizard_ESBProject=ESB Project\:
+ESBVisualizerView_Change_Layout_Action_Label=Change Layout
+ESBVisualizerView_EmptyNodeLabel=Select an ESB Configuration file in the navigator\n or
use the 'Open JBoss ESB Configuration' view menu\n to show a configuration
graphically.
+ESBVisualizerView_Open_ESB_Config_Action_Label=Open ESB Configuration
+ESBVisualizerView_Open_ESB_Config_Dialog_Field_Text=Select ESB file:
+ESBVisualizerView_Open_ESB_Config_Dialog_Title=Open ESB Configuration
+ESBVisualizerView_Refresh_Layout_Action_Label=Refresh Layout
+ESBVisualizerView_Select_ESB_File_Warning=Please select an ESB configuration file.
+ESBVisualizerView_Use_Horizontal_Tree_Layout_Action_Label=Use Horizontal Tree Layout
+ESBVisualizerView_Use_Radial_Layout_Action_Label=Use Radial Layout
+ESBVisualizerView_Use_Vertical_Tree_Layout_Action_Label=Use Vertical Tree Layout
Modified:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java 2012-02-02
15:31:46 UTC (rev 38396)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -55,6 +55,10 @@
public static String JBoss_ESBRuntime_Classpath_Container_5;
public static String JBoss_Runtime_List_Field_Editor_Configuration;
+ public static String ESBDomParser_Providers_Label;
+
+ public static String ESBDomParser_Services_Label;
+
public static String ESBRuntimeContainerPage_Button_Text;
public static String JBoss_ESBRuntime_Classpath_Container_Description;
@@ -137,6 +141,27 @@
public static String ESBExportWizard_ESBProject;
+ public static String ESBVisualizerView_Change_Layout_Action_Label;
+
+ public static String ESBVisualizerView_EmptyNodeLabel;
+
+ public static String ESBVisualizerView_Open_ESB_Config_Action_Label;
+
+ public static String ESBVisualizerView_Open_ESB_Config_Dialog_Field_Text;
+
+ public static String ESBVisualizerView_Open_ESB_Config_Dialog_Title;
+
+ public static String ESBVisualizerView_Refresh_Layout_Action_Label;
+
+ public static String ESBVisualizerView_Select_ESB_File_Warning;
+
+ public static String ESBVisualizerView_Use_Horizontal_Tree_Layout_Action_Label;
+
+ public static String ESBVisualizerView_Use_Radial_Layout_Action_Label;
+
+ public static String ESBVisualizerView_Use_Vertical_Tree_Layout_Action_Label;
+
+
static {
NLS.initializeMessages(BUNDLE_NAME, JBossESBUIMessages.class);
}
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBDomParser.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBDomParser.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBDomParser.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collections;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.esb.project.ui.ESBProjectPlugin;
+import org.jboss.tools.esb.project.ui.messages.JBossESBUIMessages;
+import org.jboss.tools.esb.project.ui.visualizer.ESBNode.ESBType;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Take an incoming jboss-esb config file and parse it into nodes for the graphical view
+ * @author bfitzpat
+ *
+ */
+public class ESBDomParser {
+
+ Document dom;
+ ESBNodeWithChildren root;
+
+ /**
+ * Utility method to verify that a file is an ESB config
+ * @param filepath
+ * @return
+ */
+ public boolean isFileESBConfig ( String filepath ) {
+ //get the factory
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
+ try {
+
+ //Using factory get an instance of document builder
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ //parse using builder to get DOM representation of the XML file
+ dom = db.parse(filepath);
+
+ dom.getDocumentElement().normalize();
+
+ if (dom.getDocumentElement().getTagName().equalsIgnoreCase("jbossesb")) {
//$NON-NLS-1$
+ return true;
+ }
+ }catch(ParserConfigurationException pce) {
+ pce.printStackTrace();
+ }catch(SAXException se) {
+ se.printStackTrace();
+ }catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+
+ return false;
+ }
+
+ /**
+ * Parse the file into the nodes
+ * @param filepath
+ */
+ public void parseXmlFile(String filepath){
+
+ root = new ESBNodeWithChildren("Invisible Root"); //$NON-NLS-1$
+
+ //get the factory
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
+ try {
+
+ //Using factory get an instance of document builder
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ try {
+ if (filepath == null) {
+ Bundle bundle = ESBProjectPlugin.getDefault().getBundle();
+ IPath path = new Path("META-INF/jboss-esb.xml"); //$NON-NLS-1$
+ URL setupUrl = FileLocator.find(bundle, path, Collections.EMPTY_MAP);
+ File setupFile = new File(FileLocator.toFileURL(setupUrl).toURI());
+ if (setupFile.exists() && setupFile.canRead())
+ filepath = setupFile.getAbsolutePath();
+ else
+ return;
+ }
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+
+ //parse using builder to get DOM representation of the XML file
+ dom = db.parse(filepath);
+ dom.getDocumentElement().normalize();
+ root.setName(dom.getDocumentElement().getTagName());
+ root.setEsbObjectType(ESBType.ESB);
+
+ parseDocument();
+
+ }catch(ParserConfigurationException pce) {
+ pce.printStackTrace();
+ }catch(SAXException se) {
+ se.printStackTrace();
+ }catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+
+ /*
+ * Work through the configuration
+ */
+ private void parseDocument(){
+ //get the root elememt
+ Element docEle = dom.getDocumentElement();
+
+ //get a nodelist of <providers> elements
+ NodeList nl = docEle.getElementsByTagName("providers"); //$NON-NLS-1$
+ if(nl != null && nl.getLength() > 0) {
+ Element providersElement= null;
+ for (int j = 0; j < nl.getLength(); j++) {
+ if (nl.item(j) instanceof Element) {
+ providersElement = (Element) nl.item(j);
+ break;
+ }
+ }
+ if(providersElement != null) {
+ ESBNodeWithChildren providersRoot = new
ESBNodeWithChildren(JBossESBUIMessages.ESBDomParser_Providers_Label);
+ providersRoot.setEsbObjectType(ESBNode.ESBType.PROVIDER);
+ processChildren(providersRoot, providersElement);
+ root.addChild(providersRoot);
+ }
+ }
+
+ //get a nodelist of <services> elements
+ NodeList nl2 = docEle.getElementsByTagName("services"); //$NON-NLS-1$
+ if(nl2 != null && nl2.getLength() > 0) {
+ Element servicesElement= null;
+ for (int j = 0; j < nl2.getLength(); j++) {
+ if (nl2.item(j) instanceof Element) {
+ servicesElement = (Element) nl2.item(j);
+ break;
+ }
+ }
+ if(servicesElement != null) {
+ ESBNodeWithChildren servicesRoot = new
ESBNodeWithChildren(JBossESBUIMessages.ESBDomParser_Services_Label);
+ servicesRoot.setEsbObjectType(ESBNode.ESBType.SERVICE);
+ processChildren(servicesRoot, servicesElement);
+ root.addChild(servicesRoot);
+ }
+ }
+ }
+
+ /*
+ * Work down the children tree
+ * @param parent
+ * @param el
+ */
+ private void processChildren ( ESBNodeWithChildren parent, Element el ) {
+ el.normalize();
+ parent.setData(el);
+
+ if (parent.getEsbObjectType() == null) {
+ String tag = el.getTagName();
+ if (tag.endsWith("-bus") && el.getAttribute("busid") !=
null) { //$NON-NLS-1$ //$NON-NLS-2$
+ parent.setEsbObjectType(ESBType.BUS);
+ } else if (tag.endsWith("-listener") &&
el.getAttribute("busidref") != null) { //$NON-NLS-1$ //$NON-NLS-2$
+ parent.setEsbObjectType(ESBType.LISTENER);
+ } else if (tag.endsWith("-provider")) { //$NON-NLS-1$
+ parent.setEsbObjectType(ESBType.PROVIDER);
+ } else if (tag.equalsIgnoreCase("service")) { //$NON-NLS-1$
+ parent.setEsbObjectType(ESBType.SERVICE);
+ } else if (tag.equalsIgnoreCase("listeners")) { //$NON-NLS-1$
+ parent.setEsbObjectType(ESBType.LISTENER);
+ } else if (tag.equalsIgnoreCase("actions")) { //$NON-NLS-1$
+ parent.setEsbObjectType(ESBType.ACTION);
+ } else if (tag.equalsIgnoreCase("action")) { //$NON-NLS-1$
+ parent.setEsbObjectType(ESBType.ACTION);
+ } else if (tag.equalsIgnoreCase("property")) { //$NON-NLS-1$
+ parent.setEsbObjectType(ESBType.PROPERTY);
+ return;
+ }
+ }
+ NodeList children = el.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ if (children.item(i) instanceof Element) {
+ Element child = (Element) children.item(i);
+ String name = child.getAttribute("name"); //$NON-NLS-1$
+ if (name == null || name.trim().length() == 0) {
+ name = child.getAttribute("busid"); //$NON-NLS-1$
+ }
+ if (name == null || name.trim().length() == 0) {
+ name = child.getAttribute("dest-name"); //$NON-NLS-1$
+ }
+ if (name == null || name.trim().length() == 0) {
+ name = child.getTagName();
+ }
+
+ ESBNodeWithChildren childNode = new ESBNodeWithChildren(name);
+ String ref = child.getAttribute("busidref"); //$NON-NLS-1$
+ if (ref != null && ref.trim().length() > 0) {
+ childNode.setRef(ref);
+ }
+ processChildren(childNode, child);
+ if (childNode.getEsbObjectType() != null &&
!childNode.getEsbObjectType().equals(ESBType.PROPERTY)) {
+ parent.addChild(childNode);
+ childNode.setEsbObjectType(parent.getEsbObjectType());
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the actual root
+ * @return
+ */
+ public ESBNodeWithChildren getRoot() {
+ return this.root;
+ }
+
+}
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBDomParser.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNode.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNode.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNode.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * Simple container node
+ * @author bfitzpat
+ *
+ */
+public class ESBNode implements IAdaptable {
+
+ private String name;
+ private ESBNodeWithChildren parent;
+ private String ref;
+ private boolean isLockedFlag = false;
+ private ESBType esbObjectType;
+ private Object data;
+
+ /**
+ * Enumerated list of node types
+ * @author bfitzpat
+ */
+ public enum ESBType {
+ ACTION, BUS, LISTENER, PROVIDER,
+ ESB, PROPERTY, SERVICE
+ }
+
+ /**
+ * Constructor
+ * @param name
+ */
+ public ESBNode(String name) {
+ this.name = name;
+ }
+ /**
+ * Get the name (basic string)
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * Set the name (basic string)
+ * @param newName
+ */
+ public void setName(String newName) {
+ this.name = newName;
+ }
+ /**
+ * Add the parent node so we can claw back up the chain
+ * @param parent
+ */
+ public void setParent(ESBNodeWithChildren parent) {
+ this.parent = parent;
+ }
+ /**
+ * Get the parent node
+ * @return
+ */
+ public ESBNodeWithChildren getParent() {
+ return parent;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return getName();
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class key) {
+ return null;
+ }
+ /**
+ * Get the referenced node
+ * @return
+ */
+ public String getRef() {
+ return ref;
+ }
+ /**
+ * Set the referenced node
+ * @param ref
+ */
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+ /**
+ * Is this node locked for movement?
+ * @return
+ */
+ protected boolean isMovementLocked() {
+ return isLockedFlag;
+ }
+ /**
+ * Set the "isLocked" flag
+ * @param isLocked
+ */
+ protected void setIsMovementLocked(boolean isLocked) {
+ this.isLockedFlag = isLocked;
+ }
+ /**
+ * Get the node type
+ * @return
+ */
+ protected ESBType getEsbObjectType() {
+ return esbObjectType;
+ }
+ /**
+ * @param esbObjectType
+ */
+ protected void setEsbObjectType(ESBType esbObjectType) {
+ this.esbObjectType = esbObjectType;
+ }
+ /**
+ * Return the stashed Java object
+ * @return
+ */
+ protected Object getData() {
+ return data;
+ }
+ /**
+ * Stash a java object
+ * @param data
+ */
+ protected void setData(Object data) {
+ this.data = data;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNode.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNodeWithChildren.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNodeWithChildren.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNodeWithChildren.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import java.util.ArrayList;
+
+/**
+ * Extend the base node so it can track a list of children
+ * @author bfitzpat
+ */
+public class ESBNodeWithChildren extends ESBNode {
+
+ private ArrayList<ESBNode> children;
+ /**
+ * Constructor
+ * @param name
+ */
+ public ESBNodeWithChildren(String name) {
+ super(name);
+ children = new ArrayList<ESBNode>();
+ }
+ /**
+ * Add a child to the child list
+ * @param child
+ */
+ public void addChild(ESBNode child) {
+ children.add(child);
+ child.setParent(this);
+ }
+ /**
+ * Remove a child from the child list
+ * @param child
+ */
+ public void removeChild(ESBNode child) {
+ children.remove(child);
+ child.setParent(null);
+ }
+ /**
+ * Get the list of children
+ * @return
+ */
+ public ESBNode [] getChildren() {
+ return (ESBNode [])children.toArray(new ESBNode[children.size()]);
+ }
+ /**
+ * Does the node have children?
+ * @return
+ */
+ public boolean hasChildren() {
+ return children.size()>0;
+ }
+}
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBNodeWithChildren.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBVisualizerView.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBVisualizerView.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBVisualizerView.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,590 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+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.resource.ImageDescriptor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.dialogs.ISelectionValidator;
+import org.eclipse.ui.part.IShowInTarget;
+import org.eclipse.ui.part.ShowInContext;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
+import org.eclipse.zest.core.viewers.GraphViewer;
+import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
+import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
+import org.eclipse.zest.core.widgets.ConstraintAdapter;
+import org.eclipse.zest.core.widgets.Graph;
+import org.eclipse.zest.core.widgets.GraphConnection;
+import org.eclipse.zest.core.widgets.GraphNode;
+import org.eclipse.zest.core.widgets.ZestStyles;
+import org.eclipse.zest.layouts.LayoutAlgorithm;
+import org.eclipse.zest.layouts.LayoutStyles;
+import org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm;
+import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm;
+import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
+import org.eclipse.zest.layouts.constraints.BasicEntityConstraint;
+import org.eclipse.zest.layouts.constraints.LayoutConstraint;
+import org.jboss.tools.esb.project.ui.ESBProjectPlugin;
+import org.jboss.tools.esb.project.ui.messages.JBossESBUIMessages;
+import org.jboss.tools.esb.project.ui.visualizer.ESBNode.ESBType;
+
+/**
+ * This class serves as a simple read-only way to visualize an ESB configuration
+ * graphically.
+ *
+ * @author bfitzpat
+ *
+ */
+public class ESBVisualizerView extends ViewPart implements IZoomableWorkbenchPart,
IShowInTarget {
+
+ /**
+ * The ID of the view as specified by the extension.
+ */
+ public static final String ID =
"org.jboss.tools.esb.visualizer.views.ESBVisualizerView";//$NON-NLS-1$
+
+ private static final String ACTION_ICON_TAG =
"/icons/esb/action.gif";//$NON-NLS-1$
+ private static final String SERVICE_ICON_TAG =
"/icons/esb/service.gif";//$NON-NLS-1$
+ private static final String PROVIDER_ICON_TAG =
"/icons/esb/provider.gif";//$NON-NLS-1$
+ private static final String BUS_ICON_TAG = "/icons/esb/bus.gif";//$NON-NLS-1$
+ private static final String PROPERTY_ICON_TAG =
"/icons/esb/property.gif";//$NON-NLS-1$
+ private static final String LISTENER_ICON_TAG =
"/icons/esb/listener.gif";//$NON-NLS-1$
+ private static final String ESB_FILE_ICON_TAG =
"/icons/esb/esb_file.gif";//$NON-NLS-1$
+ private static final String REFRESH_ICON_TAG =
"/icons/refresh.gif";//$NON-NLS-1$
+ private static final String HORIZONTAL_TREE_LAYOUT_ICON_TAG =
"/icons/horizontalTreeLayout.gif";//$NON-NLS-1$
+ private static final String VERTICAL_TREE_LAYOUT_ICON_TAG =
"/icons/verticalTreeLayout.gif";//$NON-NLS-1$
+ private static final String RADIAL_LAYOUT_ICON_TAG =
"/icons/radialLayout.gif";//$NON-NLS-1$
+
+ private GraphViewer gv;
+
+ // Some stashed colors
+ private Color defaultBorder;
+
+ // menu items
+ private Action openESBFileAction;
+
+ // toolbar buttons for different layouts
+ private IAction horizontalLayoutAction;
+ private IAction verticalLayoutAction;
+ private IAction radialLayoutAction;
+ private Action refreshLayoutAction;
+
+ // the listener we register with the selection service
+ private ISelectionListener listener = new ISelectionListener() {
+ public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
+ // we ignore our own selections
+ if (sourcepart != ESBVisualizerView.this) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ssel = (IStructuredSelection) selection;
+ if (ssel.getFirstElement() instanceof IFile) {
+ IFile selectedFile = (IFile) ssel.getFirstElement();
+ String path = selectedFile.getLocation().toOSString();
+ ESBDomParser parser = new ESBDomParser();
+ if (parser.isFileESBConfig(path)) {
+ if (!gv.getGraphControl().isDisposed()) {
+ visualizeESB(path);
+ refreshLayoutAction.run();
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+
+ /**
+ * The constructor.
+ */
+ public ESBVisualizerView() {
+ // empty
+ }
+
+ /**
+ * This is a callback that will allow us
+ * to create the viewer and initialize it.
+ */
+ public void createPartControl(Composite parent) {
+ this.gv = new GraphViewer(parent, SWT.NONE);
+ gv.getGraphControl().addConstraintAdapter(new ESBViewerConstraintAdapter());
+ gv.addDoubleClickListener(new FixNodeDoubleClickListener());
+ makeActions();
+ hookContextMenu();
+ fillToolBar();
+// visualizeESB(null);
+ setEmptyGraph();
+ horizontalLayoutAction.setChecked(true);
+ horizontalLayoutAction.run();
+ getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);
+ }
+
+ /*
+ * Clear all the graph nodes and connections
+ */
+ private void clearGraph() {
+ while (gv.getGraphControl().getNodes().size() > 0) {
+ GraphNode node = (GraphNode) gv.getGraphControl().getNodes().remove(0);
+ node.dispose();
+ }
+ while (gv.getGraphControl().getConnections().size() > 0) {
+ GraphConnection node = (GraphConnection)
gv.getGraphControl().getConnections().remove(0);
+ node.dispose();
+ }
+ }
+
+ /*
+ * Clear the graph and add a default node
+ */
+ private void setEmptyGraph() {
+ clearGraph();
+ new GraphNode (gv.getGraphControl(), ZestStyles.NODES_CACHE_LABEL,
+ JBossESBUIMessages.ESBVisualizerView_EmptyNodeLabel);
+// refreshLayoutAction.run();
+ }
+
+ /**
+ * Import the esb XML file and render nodes and connections
+ * @param filepath
+ */
+ public void visualizeESB ( String filepath ) {
+ ESBDomParser parser = new ESBDomParser();
+ parser.parseXmlFile(filepath);
+ clearGraph();
+ ESBNodeWithChildren root = parser.getRoot();
+ root.setEsbObjectType(ESBType.ESB);
+ GraphNode rootnode = new GraphNode(gv.getGraphControl(),
+ ZestStyles.NODES_CACHE_LABEL,
+ root.getName());
+ rootnode.setImage(getImageFromPlugin("/icons/esb/esb_file.gif"));
//$NON-NLS-1$
+ this.defaultBorder = rootnode.getBorderColor();
+ rootnode.setData(root);
+ drawNodes(rootnode, root);
+ drawRefs(rootnode);
+ if (horizontalLayoutAction.isChecked()) {
+ horizontalLayoutAction.run();
+ } else if (verticalLayoutAction.isChecked()) {
+ verticalLayoutAction.run();
+ } else if (radialLayoutAction.isChecked()) {
+ radialLayoutAction.run();
+ }
+ }
+
+ /*
+ * Simple image management
+ * @param path
+ * @return
+ */
+ private Image getImageFromPlugin( String path ) {
+ if (ESBProjectPlugin.getDefault().getImageRegistry().get(path) == null) {
+ ImageDescriptor descriptor = ESBProjectPlugin.getImageDescriptor(path);
+ if (descriptor != null) {
+ ESBProjectPlugin.getDefault().getImageRegistry().put(path, descriptor);
+ return ESBProjectPlugin.getDefault().getImageRegistry().get(path);
+ }
+ }
+ return ESBProjectPlugin.getDefault().getImageRegistry().get(path);
+ }
+
+ /*
+ * Actually draw the nodes and connections from the parsed ESB xml file
+ * @param root
+ * @param parent
+ */
+ private void drawNodes ( GraphNode root, ESBNodeWithChildren parent ) {
+ if (parent.hasChildren()) {
+ for (int i = 0; i < parent.getChildren().length; i++) {
+ ESBNodeWithChildren tp = (ESBNodeWithChildren) parent.getChildren()[i];
+ GraphNode p = new GraphNode(gv.getGraphControl(), SWT.NONE, tp.getName());
+ if (tp.getEsbObjectType() != null) {
+ switch (tp.getEsbObjectType()) {
+ case ACTION:
+ p.setImage(getImageFromPlugin(ACTION_ICON_TAG));
+ break;
+ case SERVICE:
+ p.setImage(getImageFromPlugin(SERVICE_ICON_TAG));
+ break;
+ case PROVIDER:
+ p.setImage(getImageFromPlugin(PROVIDER_ICON_TAG));
+ break;
+ case BUS:
+ p.setImage(getImageFromPlugin(BUS_ICON_TAG));
+ break;
+ case PROPERTY:
+ p.setImage(getImageFromPlugin(PROPERTY_ICON_TAG));
+ break;
+ case LISTENER:
+ p.setImage(getImageFromPlugin(LISTENER_ICON_TAG));
+ break;
+ case ESB:
+ p.setImage(getImageFromPlugin(ESB_FILE_ICON_TAG));
+ break;
+ default:
+ break;
+ }
+ }
+ p.setData(tp);
+ drawNodes(p, tp);
+ new GraphConnection(gv.getGraphControl(), ZestStyles.CONNECTIONS_DASH, root, p);
+ }
+ }
+ }
+
+ /*
+ * Draw any references between items
+ * @param root
+ */
+ private void drawRefs ( GraphNode root ) {
+ if (gv.getGraphControl().getGraphModel().getNodes() != null &&
gv.getGraphControl().getGraphModel().getNodes().size() > 0) {
+ @SuppressWarnings("unchecked")
+ Iterator<GraphNode> nodeIter =
gv.getGraphControl().getGraphModel().getNodes().iterator();
+ while (nodeIter.hasNext()) {
+ GraphNode node = nodeIter.next();
+ if (node.getData() != null && node.getData() instanceof ESBNodeWithChildren)
{
+ ESBNodeWithChildren tp = (ESBNodeWithChildren) node.getData();
+ if (tp.getRef() != null && tp.getRef().trim().length() > 0) {
+ GraphNode refNode = findNode(tp.getRef(), root);
+ if (refNode != null) {
+ GraphConnection refConnection =
+ new GraphConnection(gv.getGraphControl(), ZestStyles.CONNECTIONS_DIRECTED, node,
refNode);
+ refConnection.changeLineColor(gv.getGraphControl().getDisplay().getSystemColor(
+ SWT.COLOR_BLUE));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * Look for a node by name (for reference connections)
+ * @param name
+ * @param root
+ * @return
+ */
+ private GraphNode findNode ( String name, GraphNode root ) {
+ if (name != null && name.trim().length() > 0) {
+ if (gv.getGraphControl().getGraphModel().getNodes() != null &&
gv.getGraphControl().getGraphModel().getNodes().size() > 0) {
+ @SuppressWarnings("unchecked")
+ Iterator<GraphNode> nodeIter =
gv.getGraphControl().getGraphModel().getNodes().iterator();
+ while (nodeIter.hasNext()) {
+ GraphNode node = nodeIter.next();
+ if (node.getText().equalsIgnoreCase(name)) {
+ return node;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Passing the focus request to the viewer's control.
+ */
+ public void setFocus() {
+ gv.getGraphControl().setFocus();
+ }
+
+ /*
+ * Fill the view menu
+ */
+ private void hookContextMenu() {
+ MenuManager menuMgr = new MenuManager("#PopupMenu");//$NON-NLS-1$
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ ESBVisualizerView.this.fillContextMenu(manager);
+ }
+ });
+ Menu menu = menuMgr.createContextMenu(gv.getGraphControl());
+ gv.getGraphControl().setMenu(menu);
+
+ // if we decide to add a popup menu...
+// getSite().registerContextMenu(menuMgr, );
+ }
+
+ /*
+ * Add any menus
+ * @param manager
+ */
+ private void fillContextMenu(IMenuManager manager) {
+ manager.add(openESBFileAction);
+ }
+
+ /*
+ * Make the few actions we have
+ */
+ private void makeActions() {
+
+ refreshLayoutAction = new Action() {
+ @Override
+ public void run() {
+ if (gv != null && gv.getGraphControl().getLayoutAlgorithm() != null) {
+ gv.setLayoutAlgorithm(gv.getGraphControl().getLayoutAlgorithm(), true);
+ }
+ }
+ };
+
+ refreshLayoutAction.setText(JBossESBUIMessages.ESBVisualizerView_Refresh_Layout_Action_Label);
+ refreshLayoutAction.setToolTipText(JBossESBUIMessages.ESBVisualizerView_Refresh_Layout_Action_Label);
+ refreshLayoutAction.setImageDescriptor(ESBProjectPlugin.getImageDescriptor(REFRESH_ICON_TAG));
+
+ openESBFileAction = new Action() {
+ public void run() {
+
+ WorkbenchFileSelectionDialog dialog = new WorkbenchFileSelectionDialog(
+ ESBVisualizerView.this.getSite().getShell().getShell(),
+ null,
+ JBossESBUIMessages.ESBVisualizerView_Open_ESB_Config_Dialog_Field_Text,
+ ".xml");//$NON-NLS-1$
+ dialog.setTitle(JBossESBUIMessages.ESBVisualizerView_Open_ESB_Config_Dialog_Title);
+ dialog.setImage(getImageFromPlugin(ESB_FILE_ICON_TAG));
+ dialog.setValidator(new ISelectionValidator() {
+
+ public String isValid(Object selection) {
+ if (selection instanceof IPath) {
+ IPath selectedpath = (IPath) selection;
+ IPath totalPath =
ResourcesPlugin.getWorkspace().getRoot().getLocation().append(selectedpath);
+ String path = totalPath.toOSString();
+ ESBDomParser parser = new ESBDomParser();
+ if (parser.isFileESBConfig(path)) {
+ return null;
+ }
+ return JBossESBUIMessages.ESBVisualizerView_Select_ESB_File_Warning;
+ } else if (selection == null) {
+ return JBossESBUIMessages.ESBVisualizerView_Select_ESB_File_Warning;
+ }
+ return null;
+ }
+ });
+ int rtn_code = dialog.open();
+
+ if (rtn_code == WorkbenchFileSelectionDialog.OK) {
+ IPath resultPath = dialog.getFullPath();
+ IPath totalPath =
ResourcesPlugin.getWorkspace().getRoot().getLocation().append(resultPath);
+ String path = totalPath.toOSString();
+ visualizeESB(path);
+ }
+ }
+ };
+ openESBFileAction.setText(JBossESBUIMessages.ESBVisualizerView_Open_ESB_Config_Action_Label);
+ openESBFileAction.setToolTipText(JBossESBUIMessages.ESBVisualizerView_Open_ESB_Config_Action_Label);
+ openESBFileAction.setImageDescriptor(ESBProjectPlugin.getImageDescriptor(ESB_FILE_ICON_TAG));
+
+ }
+
+ /*
+ * Fill the toolbar with a few buttons
+ */
+ private void fillToolBar() {
+ ZoomContributionViewItem toolbarZoomContributionViewItem = new
ZoomContributionViewItem(
+ this);
+ IActionBars bars = getViewSite().getActionBars();
+ bars.getMenuManager().add(openESBFileAction);
+
+ IToolBarManager toolbar = bars.getToolBarManager();
+
+ toolbar.add(refreshLayoutAction);
+
+ horizontalLayoutAction = new LayoutAction(gv, new
HorizontalTreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
+ horizontalLayoutAction.setImageDescriptor(ESBProjectPlugin.getImageDescriptor(HORIZONTAL_TREE_LAYOUT_ICON_TAG));
+ horizontalLayoutAction.setToolTipText(JBossESBUIMessages.ESBVisualizerView_Use_Horizontal_Tree_Layout_Action_Label);
+ horizontalLayoutAction.addPropertyChangeListener(new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getProperty().equalsIgnoreCase("checked")) {//$NON-NLS-1$
+ Boolean state = (Boolean)event.getNewValue();
+ if (state.equals(Boolean.TRUE)) {
+ verticalLayoutAction.setChecked(false);
+ radialLayoutAction.setChecked(false);
+ } else {
+ if (!verticalLayoutAction.isChecked() &&
+ !radialLayoutAction.isChecked())
+ horizontalLayoutAction.setChecked(true);
+ }
+ }
+ }
+ });
+ toolbar.add(horizontalLayoutAction);
+
+ verticalLayoutAction = new LayoutAction(gv, new
TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
+ verticalLayoutAction.setImageDescriptor(ESBProjectPlugin.getImageDescriptor(VERTICAL_TREE_LAYOUT_ICON_TAG));
+ verticalLayoutAction.setToolTipText(JBossESBUIMessages.ESBVisualizerView_Use_Vertical_Tree_Layout_Action_Label);
+ verticalLayoutAction.addPropertyChangeListener(new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getProperty().equalsIgnoreCase("checked")) {//$NON-NLS-1$
+ Boolean state = (Boolean)event.getNewValue();
+ if (state.equals(Boolean.TRUE)) {
+ horizontalLayoutAction.setChecked(false);
+ radialLayoutAction.setChecked(false);
+ } else {
+ if (!horizontalLayoutAction.isChecked() &&
+ !radialLayoutAction.isChecked())
+ verticalLayoutAction.setChecked(true);
+ }
+ }
+ }
+ });
+ toolbar.add(verticalLayoutAction);
+
+ radialLayoutAction = new LayoutAction(gv, new
RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
+ radialLayoutAction.setImageDescriptor(ESBProjectPlugin.getImageDescriptor(RADIAL_LAYOUT_ICON_TAG));
+ radialLayoutAction.setToolTipText(JBossESBUIMessages.ESBVisualizerView_Use_Radial_Layout_Action_Label);
+ radialLayoutAction.addPropertyChangeListener(new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getProperty().equalsIgnoreCase("checked")) {//$NON-NLS-1$
+ Boolean state = (Boolean)event.getNewValue();
+ if (state.equals(Boolean.TRUE)) {
+ horizontalLayoutAction.setChecked(false);
+ verticalLayoutAction.setChecked(false);
+ } else {
+ if (!horizontalLayoutAction.isChecked() &&
+ !verticalLayoutAction.isChecked())
+ radialLayoutAction.setChecked(true);
+ }
+ }
+ }
+ });
+ toolbar.add(radialLayoutAction);
+
+ toolbar.add(toolbarZoomContributionViewItem);
+ }
+
+ public AbstractZoomableViewer getZoomableViewer() {
+ return gv;
+ }
+
+ /*
+ * @author bfitzpat
+ * Check to see if the node has been "frozen" and if so, don't move it
+ * when we redo the layout
+ */
+ private class ESBViewerConstraintAdapter implements ConstraintAdapter {
+ public void populateConstraint(Object object, LayoutConstraint constraint) {
+ if (constraint instanceof BasicEntityConstraint) {
+
+ BasicEntityConstraint basicEntityConstraint = (BasicEntityConstraint) constraint;
+ GraphNode graphnode = (GraphNode) object;
+
+ Object data = graphnode.getData();
+ if (data != null && data instanceof ESBNode) {
+ boolean wasMoved = ((ESBNode)data).isMovementLocked();
+ basicEntityConstraint.hasPreferredLocation = wasMoved;
+ }
+ }
+ }
+ }
+
+ /*
+ * @author bfitzpat
+ * If the user double-clicks on a node, "fix" it in place. If they double-
+ * click again, un-"fix" it.
+ */
+ private class FixNodeDoubleClickListener implements IDoubleClickListener {
+ public void doubleClick(DoubleClickEvent e) {
+ if (e.getSource() instanceof GraphViewer) {
+ Graph graph = ((GraphViewer) e.getSource()).getGraphControl();
+ if (!graph.getSelection().isEmpty()) {
+ GraphNode node = (GraphNode) graph.getSelection().get(0);
+ if (node.getData() != null && node.getData() instanceof ESBNode) {
+ ESBNode to = (ESBNode)node.getData();
+ to.setIsMovementLocked(!to.isMovementLocked());
+ if (to.isMovementLocked()) {
+ node.setBorderWidth(3);
+ node.setBorderColor(gv.getGraphControl().getDisplay().getSystemColor(
+ SWT.COLOR_BLUE));
+ } else {
+ node.setBorderWidth(1);
+ node.setBorderColor(defaultBorder);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * @author bfitzpat
+ * Handle layout duties
+ */
+ private class LayoutAction extends Action {
+
+ private LayoutAlgorithm[] layouts;
+ private int currentLayout = 0;
+ private GraphViewer gv;
+
+ public LayoutAction(GraphViewer gv, LayoutAlgorithm layout) {
+ super(JBossESBUIMessages.ESBVisualizerView_Change_Layout_Action_Label);
+ this.gv = gv;
+ layouts = new LayoutAlgorithm[1];
+ layouts[0] = layout;
+ }
+
+ @Override
+ public void run() {
+ super.run();
+ int temp = currentLayout + 1;
+ if (temp == layouts.length)
+ temp = 0;
+ currentLayout = temp;
+ if (gv.getGraphControl().getLayoutAlgorithm() == null ||
+ !gv.getGraphControl().getLayoutAlgorithm().equals(layouts[currentLayout]))
+ gv.setLayoutAlgorithm(layouts[currentLayout], true);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
+ */
+ public boolean show(ShowInContext context) {
+ if (gv == null || context == null)
+ return false;
+ ISelection sel = context.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)sel;
+ Object first = ss.getFirstElement();
+ if (first instanceof IFile) {
+ String path = ((IFile)first).getLocation().toOSString();
+ ESBDomParser parser = new ESBDomParser();
+ if (parser.isFileESBConfig(path)) {
+ visualizeESB(path);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+
+}
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ESBVisualizerView.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/FileSelectionGroup.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/FileSelectionGroup.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/FileSelectionGroup.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+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.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.part.DrillDownComposite;
+
+public class FileSelectionGroup extends Composite {
+
+ // The listener to notify of events
+ private Listener listener;
+
+ private String message;
+
+ // Last selection made by user
+ private IResource selectedResource;
+
+ // handle on parts
+ private TreeViewer treeViewer;
+
+ // Filters
+ private ViewerFileFilter viewerFileFilter;
+ // private ViewerFileFilterMatcher viewerFileFilterMatcher
+ private String filterPatterns;
+ // sizing constants
+ private static final int SIZING_SELECTION_PANE_HEIGHT = 175;
+ private static final int SIZING_SELECTION_PANE_WIDTH = 200;
+ /**
+ * Creates a new instance of the widget.
+ */
+ public FileSelectionGroup(
+ Composite parent,
+ Listener listener,
+ String message) {
+ this(parent, listener, message, null);
+ }
+ public FileSelectionGroup(
+ Composite parent,
+ Listener listener,
+ String message,
+ String filterPatterns) {
+ super(parent, SWT.NONE);
+
+ this.filterPatterns = filterPatterns;
+ this.listener = listener;
+ this.message = message;
+ this.setFont(parent.getFont());
+
+ createViewerFileFilter();
+ createContents();
+ }
+ public void setFileFilter(String filter) {
+ filterPatterns = filter;
+ createViewerFileFilter();
+ treeViewer.setFilters(new ViewerFilter[] {viewerFileFilter});
+ treeViewer.setInput(ResourcesPlugin.getWorkspace());
+ }
+ /**
+ * Creates ViewerFileFilter using array of objects.
+ */
+ public void createViewerFileFilter() {
+ if (filterPatterns != null) {
+ viewerFileFilter = new ViewerFileFilter(filterPatterns);
+ }
+ }
+ /**
+ * Creates the contents of the composite.
+ */
+ public void createContents() {
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ setLayout(layout);
+ setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Label label = new Label(this, SWT.WRAP);
+ label.setText(message != null ? message : ""); //$NON-NLS-1$
+ label.setFont(this.getFont());
+
+ createTreeViewer();
+ }
+ /**
+ * Returns a new drill down viewer for this dialog.
+ */
+ protected void createTreeViewer() {
+
+ // Create drill down.
+ DrillDownComposite drillDown = new DrillDownComposite(this, SWT.BORDER);
+ GridData spec =
+ new GridData(
+ GridData.VERTICAL_ALIGN_FILL
+ | GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL);
+ spec.widthHint = SIZING_SELECTION_PANE_WIDTH;
+ spec.heightHint = SIZING_SELECTION_PANE_HEIGHT;
+ drillDown.setLayoutData(spec);
+
+ // Create tree viewer inside drill down.
+ treeViewer = new TreeViewer(drillDown, SWT.NONE);
+ drillDown.setChildTree(treeViewer);
+ treeViewer.setContentProvider(new WorkbenchContentProvider());
+ treeViewer.setLabelProvider(new WorkbenchLabelProvider());
+ treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ resourceSelectionChanged((IResource) selection.getFirstElement());
+ // allow null
+ }
+ });
+ treeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ ISelection selection = event.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Object item = ((IStructuredSelection) selection).getFirstElement();
+ if (treeViewer.getExpandedState(item))
+ treeViewer.collapseToLevel(item, 1);
+ else
+ treeViewer.expandToLevel(item, 1);
+ }
+ }
+ });
+
+ if (viewerFileFilter != null)
+ treeViewer.addFilter(viewerFileFilter);
+ // This has to be done after the viewer has been laid out
+ treeViewer.setInput(ResourcesPlugin.getWorkspace());
+ }
+ /**
+ * Returns the "full path" (i.e. first segment is project name) of the
currently selected file.
+ */
+ public IPath getResourceFullPath() {
+ if (selectedResource == null) return null;
+ return selectedResource.getFullPath();
+ }
+
+
+ public IResource getSelectedResource () {
+ return selectedResource;
+ }
+
+
+ /**
+ * Returns the tree viewer.
+ */
+ public TreeViewer getTreeViewer() {
+ return treeViewer;
+ }
+ /**
+ * The file selection has changed in the
+ * tree view. Update the file name field
+ * value and notify all listeners.
+ */
+ public void resourceSelectionChanged(IResource resource) {
+ selectedResource = resource;
+
+ // fire an event so the parent can update its controls
+ if (listener != null) {
+ Event changeEvent = new Event();
+ changeEvent.type = SWT.Selection;
+ changeEvent.widget = this;
+ listener.handleEvent(changeEvent);
+ }
+ }
+ /**
+ * Gives focus to one of the widgets in the group, as determined by the group.
+ */
+ public void setInitialFocus() {
+ treeViewer.getTree().setFocus();
+ }
+ /**
+ * Sets the selected existing file.
+ */
+ public void setSelectedResource(IResource resource) {
+ //
https://issues.jboss.org/browse/JBIDE-8738
+ if (resource==null)
+ return;
+ selectedResource = resource;
+
+ //expand to and select the specified file
+ List<IContainer> itemsToExpand = new ArrayList<IContainer>();
+ IContainer parent = resource.getParent();
+ while (parent != null) {
+ itemsToExpand.add(0, parent);
+ parent = parent.getParent();
+ }
+ treeViewer.setExpandedElements(itemsToExpand.toArray());
+ treeViewer.setSelection(new StructuredSelection(resource), true);
+ }
+}
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/FileSelectionGroup.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ViewerFileFilter.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ViewerFileFilter.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ViewerFileFilter.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+public class ViewerFileFilter extends ViewerFilter {
+
+ private String[] patterns;
+
+ static String COMMA_SEPARATOR = ","; //$NON-NLS-1$
+
+ public ViewerFileFilter() {
+ this(null);
+ }
+ /**
+ * Creates a new resource pattern filter.
+ */
+ public ViewerFileFilter(String patterns) {
+ super();
+
+ if (patterns != null) {
+ //Get the strings separated by a comma and filter them from the currently
+ //defined ones
+ StringTokenizer entries = new StringTokenizer(patterns, COMMA_SEPARATOR);
+ List<String> localPatterns = new ArrayList<String>();
+
+ while (entries.hasMoreElements()) {
+ String nextToken = entries.nextToken();
+ if (patterns.indexOf(nextToken) > -1)
+ localPatterns.add(nextToken);
+ }
+
+ //Convert to an array of Strings
+ String[] patternArray = new String[localPatterns.size()];
+ localPatterns.toArray(patternArray);
+ setPatterns(patternArray);
+ }
+ }
+ /**
+ * Return the currently configured StringMatchers. If there aren't any look
+ * them up.
+ */
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ IResource resource = null;
+ if (element instanceof IFile) {
+ resource = (IFile) element;
+ }
+ else
+ return true;
+ String name = resource.getName();
+ for (int i = 0; i < patterns.length; i++) {
+ if (name.endsWith(patterns[i]))
+ return true;
+ }
+ return false;
+ }
+ /**
+ * Sets the patterns to filter out for the receiver.
+ */
+ public void setPatterns(String[] newPatterns) {
+
+ this.patterns = newPatterns;
+ }
+}
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/ViewerFileFilter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/WorkbenchFileSelectionDialog.java
===================================================================
---
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/WorkbenchFileSelectionDialog.java
(rev 0)
+++
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/WorkbenchFileSelectionDialog.java 2012-02-02
17:33:19 UTC (rev 38397)
@@ -0,0 +1,224 @@
+/*******************************************************************************
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.esb.project.ui.visualizer;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class WorkbenchFileSelectionDialog
+ extends org.eclipse.ui.dialogs.SelectionDialog {
+
+ // the initial selection
+ private IResource initialSelection;
+
+ // message and title
+ private String title;
+ private String message;
+
+ // image
+ private Image image;
+
+ // Filters
+ private String filterPatterns;
+ // the result
+ private IPath resultPath;
+
+ // the validation message
+ private Label statusMessage;
+
+ //for validating the selection
+ private org.eclipse.ui.dialogs.ISelectionValidator validator;
+
+ // the widget group;
+ private FileSelectionGroup resourceGroup;
+ /**
+ * A WorkbenchFileSelectionDialog takes the following arguments:
+ * <ul>
+ * <li> parentShell, the parent shell of the caller.(required)</li>
+ * <li> initialSelection, (resuired)</li>
+ * = null, takes the initial selection of the file from store, where it was
memorizaed
+ * != null, starts the selection right from the specified path.
+ * <li> message, shows the message on titel bar for this
dialog.(required)</li>
+ * <li> filterPatterns, a string of extentions separated with "," as
deliminator (eg; "wsdl, xsd, java")(optional)
+ */
+ public WorkbenchFileSelectionDialog(
+ Shell parentShell,
+ IPath initialSelection,
+ String message) {
+ this(parentShell, initialSelection, message, null);
+ }
+ /**
+ * A WorkbenchFileSelectionDialog takes the following arguments:
+ * <ul>
+ * <li> parentShell, the parent shell of the caller.(required)</li>
+ * <li> initialSelection, (resuired)</li>
+ * = null, takes the initial selection of the file from store, where it was
memorizaed
+ * != null, starts the selection right from the specified path.
+ * <li> message, shows the message on titel bar for this
dialog.(required)</li>
+ * <li> filterPatterns, a string of extentions separated with "," as
deliminator (eg; "wsdl, xsd, java")(optional)
+ */
+ public WorkbenchFileSelectionDialog(
+ Shell parentShell,
+ IPath initialSelection,
+ String message,
+ String filterPatterns) {
+ super(parentShell);
+
+ IPath initial = initialSelection;
+ if (initial == null) {
+ // Before launch the dialog, get the path in WorkbenchSlectionDialogStore, which is
the path recently selected
+ //String pathString =
(String)WorkbenchSlectionDialogStore.getInstance().getPreferences(workbenchFileSlectionStoreID);
+ //if (pathString.length()>0) {
+ // initial=(IPath)new Path(pathString);
+ //}
+ }
+ try {
+ if (initial != null) {
+ this.initialSelection =
+ ResourcesPlugin.getWorkspace().getRoot().getFile(initial);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ this.title = "Some fun title";
+ this.message = message;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.filterPatterns = filterPatterns;
+ }
+
+ /* (non-Javadoc)
+ * Method declared in Window.
+ */
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(title);
+ if (image != null)
+ shell.setImage(image);
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(
+ parent,
+ IDialogConstants.CANCEL_ID,
+ IDialogConstants.CANCEL_LABEL,
+ false);
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ // create composite
+ Composite dialogArea = (Composite) super.createDialogArea(parent);
+
+ Listener listener = new Listener() {
+ public void handleEvent(Event event) {
+ if (statusMessage != null && validator != null) {
+ String errorMsg =
+ validator.isValid(resourceGroup.getResourceFullPath());
+ if (errorMsg == null || errorMsg.equals("")) { //$NON-NLS-1$
+ statusMessage.setText(""); //$NON-NLS-1$
+ getOkButton().setEnabled(true);
+ } else {
+ statusMessage.setForeground(
+ statusMessage.getDisplay().getSystemColor(SWT.COLOR_RED));
+ statusMessage.setText(errorMsg);
+ getOkButton().setEnabled(false);
+ }
+ }
+ }
+ };
+
+ // file selection group
+ resourceGroup =
+ new FileSelectionGroup(dialogArea, listener, message, filterPatterns);
+ resourceGroup.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
+
+ public void doubleClick(DoubleClickEvent event) {
+ ISelection selection = event.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ if (!selection.isEmpty()) {
+ if (((IStructuredSelection) selection).getFirstElement() instanceof IFile) {
+ IFile resultFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
+ resultPath = resultFile.getFullPath();
+ okPressed();
+ }
+ }
+ }
+ }
+ });
+
+ if (initialSelection != null) {
+ resourceGroup.setSelectedResource(initialSelection);
+ }
+
+ statusMessage = new Label(parent, SWT.NONE);
+ statusMessage.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ return dialogArea;
+ }
+
+ /**
+ * Returns the "full path" (i.e. first segment is project name) of the
selected file.
+ */
+ public IPath getFullPath() {
+ return resultPath;
+ }
+ /**
+ * Closes this dialog.
+ */
+ @Override
+ protected void okPressed() {
+ resultPath = resourceGroup.getResourceFullPath();
+ // after file selected, save the path to WorkbenchSlectionDialogStore
+ //WorkbenchSlectionDialogStore.getInstance().setPreferences(workbenchFileSlectionStoreID,result.toString());
+
+ super.okPressed();
+ }
+ /**
+ * Sets the validator to use.
+ */
+ public void setValidator(org.eclipse.ui.dialogs.ISelectionValidator validator) {
+ this.validator = validator;
+ }
+ @Override
+ public void setTitle(String title) {
+ super.setTitle(title);
+ this.title = title;
+ }
+ public void setImage(Image image) {
+ this.image = image;
+ }
+}
Property changes on:
trunk/esb/plugins/org.jboss.tools.esb.project.ui/src/org/jboss/tools/esb/project/ui/visualizer/WorkbenchFileSelectionDialog.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain