Author: snjeza
Date: 2009-05-12 16:02:47 -0400 (Tue, 12 May 2009)
New Revision: 15236
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IProjectExampleSite.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleSite.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/SiteCategory.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencesInitializer.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/Sites.java
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties
trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4292 Users should be able to add example sites
without adding a plugin (externalized)
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties 2009-05-12
19:14:40 UTC (rev 15235)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties 2009-05-12
20:02:47 UTC (rev 15236)
@@ -4,4 +4,7 @@
JBoss_Tools_category = JBoss Tools
Project_Examples_wizard = Project Examples
Project_Examples_command =Project Examples...
-ProjectExamples=Project Examples file
\ No newline at end of file
+ProjectExamples=Project Examples file
+JBoss_Developer_Studio_Examples = JBoss Developer Studio Examples
+JBoss_Tools_Community_Examples = JBoss Tools Community Examples
+Project_Examples = Project Examples
\ No newline at end of file
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml 2009-05-12 19:14:40
UTC (rev 15235)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml 2009-05-12 20:02:47
UTC (rev 15236)
@@ -42,8 +42,30 @@
</menuContribution>
</extension>
<extension
- point="org.jboss.tools.project.examples.projectExamplesXml">
+ point="org.jboss.tools.project.examples.projectExamplesXml"
+ name="%JBoss_Developer_Studio_Examples">
<
url>http://download.jboss.org/jbosstools/examples/project-examples-3.0...
+ <experimental>false</experimental>
</extension>
+
+ <extension
+ point="org.jboss.tools.project.examples.projectExamplesXml"
+ name="%JBoss_Tools_Community_Examples">
+
<
url>http://anonsvn.jboss.org/repos/jbosstools/workspace/examples/proje...
</url>
+ <experimental>true</experimental>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.jboss.tools.common.model.ui.MainPreferencePage"
+
class="org.jboss.tools.project.examples.preferences.ProjectExamplesPreferencePage"
+
id="org.jboss.tools.project.examples.preferences.projectExamplesPreferencePage"
+ name="%Project_Examples"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
class="org.jboss.tools.project.examples.preferences.ProjectExamplesPreferencesInitializer"/>
+ </extension>
</plugin>
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd 2009-05-12
20:02:47 UTC (rev 15236)
@@ -2,9 +2,9 @@
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jboss.tools.project.examples"
xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
- <appinfo>
+ <appInfo>
<meta.schema plugin="org.jboss.tools.project.examples"
id="projectExamplesXml" name="Project Examples file"/>
- </appinfo>
+ </appInfo>
<documentation>
Adds a new Project Examples xml file
</documentation>
@@ -12,13 +12,14 @@
<element name="extension">
<annotation>
- <appinfo>
+ <appInfo>
<meta.element />
- </appinfo>
+ </appInfo>
</annotation>
<complexType>
<sequence>
- <element ref="url" minOccurs="1"
maxOccurs="unbounded"/>
+ <element ref="url"/>
+ <element ref="experimental"/>
</sequence>
<attribute name="point" type="string"
use="required">
<annotation>
@@ -39,9 +40,9 @@
<documentation>
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute translatable="true"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
</complexType>
@@ -50,19 +51,22 @@
<element name="url" type="string">
</element>
+ <element name="experimental" type="string">
+ </element>
+
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="since"/>
- </appinfo>
+ </appInfo>
<documentation>
3.0.0
</documentation>
</annotation>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="examples"/>
- </appinfo>
+ </appInfo>
<documentation>
<extension
point="org.jboss.tools.project.examples.projectExamplesXml">
@@ -72,27 +76,27 @@
</annotation>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="apiinfo"/>
- </appinfo>
+ </appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="implementation"/>
- </appinfo>
+ </appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="copyright"/>
- </appinfo>
+ </appInfo>
<documentation>
JBoss, a division of Red Hat
</documentation>
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -22,7 +22,6 @@
public static String ECFExamplesTransport_Loading;
public static String ECFExamplesTransport_ReceivedSize_Of_FileSize_At_RatePerSecond;
public static String ECFExamplesTransport_Server_redirected_too_many_times;
- public static String
ECFExamplesTransport_Unexpected_interrupt_while_waiting_on_ECF_transfer;
public static String MarkerDialog_Description;
public static String MarkerDialog_Finish;
public static String MarkerDialog_Markers;
@@ -46,13 +45,29 @@
public static String NewProjectExamplesWizardPage_Projects;
public static String NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog;
public static String NewProjectExamplesWizardPage_URL;
- public static String Project_JBoss_Tools_Team_from_jboss_org;
- public static String Project_Local;
public static String Project_Unknown;
public static String ProjectExamplesActivator_All;
public static String ProjectExamplesActivator_Waiting;
+ public static String ProjectExamplesPreferencePage_Add;
+ public static String ProjectExamplesPreferencePage_Edit;
+ public static String ProjectExamplesPreferencePage_Remove;
+ public static String ProjectExamplesPreferencePage_Show_experimental_sites;
+ public static String ProjectExamplesPreferencePage_Sites;
+ public static String ProjectUtil_Invalid_preferences;
public static String ProjectUtil_Invalid_URL;
public static String ProjectUtil_Invalid_welcome_element;
+ public static String ProjectUtil_Test;
+ public static String SiteDialog_Add_Project_Example_Site;
+ public static String SiteDialog_Browse;
+ public static String SiteDialog_Edit_Project_Example_Site;
+ public static String SiteDialog_Invalid_URL;
+ public static String SiteDialog_Name;
+ public static String SiteDialog_The_name_field_is_required;
+ public static String SiteDialog_The_site_already_exists;
+ public static String SiteDialog_The_url_field_is_required;
+ public static String SiteDialog_URL;
+ public static String Sites_Plugin_provided_sites;
+ public static String Sites_User_sites;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -36,6 +36,9 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.project.examples";
//$NON-NLS-1$
public static final String ALL_SITES = Messages.ProjectExamplesActivator_All;
+ public static final String SHOW_EXPERIMENTAL_SITES = "showExperimentalSites";
//$NON-NLS-1$
+ public static final String USER_SITES = "userSites"; //$NON-NLS-1$
+ public static final boolean SHOW_EXPERIMENTAL_SITES_VALUE = false;
// The shared instance
private static ProjectExamplesActivator plugin;
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2009-05-12
20:02:47 UTC (rev 15236)
@@ -9,7 +9,6 @@
# eg 241.73 KB of 30.95 MB (at 34.18 KB/s)
ECFExamplesTransport_ReceivedSize_Of_FileSize_At_RatePerSecond={0} of {1} (at {2}/s)
ECFExamplesTransport_Server_redirected_too_many_times=Server redirected too many times
-ECFExamplesTransport_Unexpected_interrupt_while_waiting_on_ECF_transfer=Unexpected
interrupt while waiting on ECF transfer
MarkerDialog_Description=Description
MarkerDialog_Finish=Finish
MarkerDialog_Markers=Markers:
@@ -33,11 +32,27 @@
NewProjectExamplesWizardPage_Projects=Projects:
NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog=Show the Quick Fix dialog
NewProjectExamplesWizardPage_URL=URL:
-Project_JBoss_Tools_Team_from_jboss_org=JBoss Tools Team from
jboss.org
-Project_Local=Local
Project_Unknown=Unknown
ProjectExamplesActivator_All=All
ProjectExamplesActivator_Waiting=Waiting...
+ProjectExamplesPreferencePage_Add=Add
+ProjectExamplesPreferencePage_Edit=Edit
+ProjectExamplesPreferencePage_Remove=Remove
+ProjectExamplesPreferencePage_Show_experimental_sites=Show experimental sites
+ProjectExamplesPreferencePage_Sites=Sites
+ProjectUtil_Invalid_preferences=Invalid preferences.
ProjectUtil_Invalid_URL=Invalid URL\: {0}
ProjectUtil_Invalid_welcome_element=The welcome element has invalid the url attribute
-NewProjectExamplesWizardPage_Site=Site\:
\ No newline at end of file
+ProjectUtil_Test=Test
+NewProjectExamplesWizardPage_Site=Site\:
+SiteDialog_Add_Project_Example_Site=Add Project Example Site
+SiteDialog_Browse=Browse...
+SiteDialog_Edit_Project_Example_Site=Edit Project Example Site
+SiteDialog_Invalid_URL=Invalid url.
+SiteDialog_Name=Name:
+SiteDialog_The_name_field_is_required=The name field is required.
+SiteDialog_The_site_already_exists=The site already exists.
+SiteDialog_The_url_field_is_required=The url field is required.
+SiteDialog_URL=URL:
+Sites_Plugin_provided_sites=Plugin provided sites
+Sites_User_sites=User sites
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IProjectExampleSite.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IProjectExampleSite.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IProjectExampleSite.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,5 @@
+package org.jboss.tools.project.examples.model;
+
+public interface IProjectExampleSite {
+ public String getName();
+}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -13,9 +13,6 @@
import java.math.BigDecimal;
import java.util.List;
-import org.jboss.tools.project.examples.Messages;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
-
/**
* @author snjeza
*
@@ -139,7 +136,7 @@
}
public String getSite() {
- if (site == null) {
+ /*if (site == null) {
if (getUrl().startsWith("http://anonsvn.jboss.org")) { //$NON-NLS-1$
site = Messages.Project_JBoss_Tools_Team_from_jboss_org;
} else if (getUrl().startsWith("file:")) { //$NON-NLS-1$
@@ -147,7 +144,7 @@
} else {
site = Messages.Project_Unknown;
}
- }
+ }*/
return site;
}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleSite.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleSite.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleSite.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,76 @@
+package org.jboss.tools.project.examples.model;
+
+import java.net.URL;
+
+public class ProjectExampleSite implements IProjectExampleSite {
+ private URL url;
+ private String name;
+ private boolean experimental;
+ private boolean editable = false;
+
+ public ProjectExampleSite() {
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isExperimental() {
+ return experimental;
+ }
+
+ public void setExperimental(boolean experimental) {
+ this.experimental = experimental;
+ }
+
+ public boolean isEditable() {
+ return editable;
+ }
+
+ public void setEditable(boolean editable) {
+ this.editable = editable;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ProjectExampleSite other = (ProjectExampleSite) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "ProjectExampleSite [name=" + name + ", url=" + url +
"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -11,19 +11,33 @@
package org.jboss.tools.project.examples.model;
import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -32,6 +46,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
@@ -40,6 +55,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.helpers.DefaultHandler;
/**
* @author snjeza
@@ -47,21 +63,34 @@
*/
public class ProjectUtil {
+ private static final String URL = "url"; //$NON-NLS-1$
+
+ private static final String NAME = "name"; //$NON-NLS-1$
+
+ private static final String SITES = "sites"; //$NON-NLS-1$
+
+ private static final String SITE = "site"; //$NON-NLS-1$
+
private static final String EDITOR = "editor"; //$NON-NLS-1$
public static final String CHEATSHEETS = "cheatsheets"; //$NON-NLS-1$
- private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
+ public static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
private static final String PROJECT_EXAMPLES_XML_EXTENSION_ID =
"org.jboss.tools.project.examples.projectExamplesXml"; //$NON-NLS-1$
- private static List<URL> URLs;
+
+ private static String URL_EXT = URL;
+
+ private static String EXPERIMENTAL_EXT = "experimental"; //$NON-NLS-1$
+ private static Set<ProjectExampleSite> pluginSites;
+
private ProjectUtil() {
}
- private static List<URL> getURLs() {
- if (URLs == null) {
- URLs = new ArrayList<URL>();
+ public static Set<ProjectExampleSite> getPluginSites() {
+ if (pluginSites == null) {
+ pluginSites = new HashSet<ProjectExampleSite>();
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry
.getExtensionPoint(PROJECT_EXAMPLES_XML_EXTENSION_ID);
@@ -70,23 +99,101 @@
IExtension extension = extensions[i];
IConfigurationElement[] configurationElements = extension
.getConfigurationElements();
+ ProjectExampleSite site = new ProjectExampleSite();
+ site.setName(extension.getLabel());
for (int j = 0; j < configurationElements.length; j++) {
IConfigurationElement configurationElement = configurationElements[j];
- String urlString = configurationElement.getValue();
- URL url = getURL(urlString);
- if (url != null) {
- URLs.add(url);
+ if (URL_EXT.equals(configurationElement.getName())) {
+ String urlString = configurationElement.getValue();
+ URL url = getURL(urlString);
+ if (url != null) {
+ site.setUrl(url);
+ }
+ } else if (EXPERIMENTAL_EXT.equals(configurationElement.getName())) {
+ String experimental = configurationElement.getValue();
+ if ("true".equals(experimental)) { //$NON-NLS-1$
+ site.setExperimental(true);
+ }
}
}
+ if (site.getUrl() != null) {
+ pluginSites.add(site);
+ }
}
- URL url = getURL(getProjectExamplesXml());
- if (url != null) {
- URLs.add(url);
+
+ }
+ return pluginSites;
+ }
+
+ public static Set<ProjectExampleSite> getUserSites() {
+ Set<ProjectExampleSite> sites = new HashSet<ProjectExampleSite>();
+ ProjectExampleSite site = getSite(getProjectExamplesXml());
+ if (site != null) {
+ sites.add(site);
+ }
+ IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
+ String sitesAsXml = store.getString(ProjectExamplesActivator.USER_SITES);
+ if (sitesAsXml != null && sitesAsXml.trim().length() > 0) {
+ Element rootElement = parseDocument(sitesAsXml);
+ if (!rootElement.getNodeName().equals(SITES)) {
+ ProjectExamplesActivator.log(Messages.ProjectUtil_Invalid_preferences);
+ return sites;
}
+ NodeList list = rootElement.getChildNodes();
+ int length = list.getLength();
+ for (int i = 0; i < length; ++i) {
+ Node node = list.item(i);
+ short type = node.getNodeType();
+ if (type == Node.ELEMENT_NODE) {
+ Element entry = (Element) node;
+ if(entry.getNodeName().equals(SITE)){
+ String name = entry.getAttribute(NAME);
+ String urlString = entry.getAttribute(URL);
+ if (name != null && name.trim().length() > 0 && urlString !=
null && urlString.trim().length() > 0) {
+ URL url = null;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(Messages.ProjectUtil_Invalid_preferences);
+ continue;
+ }
+ site = new ProjectExampleSite();
+ site.setName(name);
+ site.setUrl(url);
+ site.setExperimental(true);
+ site.setEditable(true);
+ sites.add(site);
+ }
+ }
+ }
+ }
}
- return URLs;
+ return sites;
}
+
+ private static Set<ProjectExampleSite> getSites() {
+ Set<ProjectExampleSite> sites = new HashSet<ProjectExampleSite>();
+ sites.addAll(getPluginSites());
+ sites.addAll(getUserSites());
+ return sites;
+ }
+ private static ProjectExampleSite getSite(String url) {
+ if (url != null) {
+ ProjectExampleSite site = new ProjectExampleSite();
+ try {
+ site.setUrl(new URL(url));
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ return null;
+ }
+ site.setExperimental(true);
+ site.setName(Messages.ProjectUtil_Test);
+ return site;
+ }
+ return null;
+ }
+
private static URL getURL(String urlString) {
if (urlString != null && urlString.trim().length() > 0) {
urlString = urlString.trim();
@@ -101,15 +208,19 @@
}
public static List<Category> getProjects() {
- getURLs();
+ Set<ProjectExampleSite> sites = getSites();
List<Category> list = new ArrayList<Category>();
Category other = Category.OTHER;
try {
- for (URL url : URLs) {
- File file = getProjectExamplesFile(url,
+ for (ProjectExampleSite site : sites) {
+ boolean showExperimentalSites =
ProjectExamplesActivator.getDefault().getPreferenceStore().getBoolean(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES);
+ if (!showExperimentalSites && site.isExperimental()) {
+ continue;
+ }
+ File file = getProjectExamplesFile(site.getUrl(),
"projectExamples", ".xml", null); //$NON-NLS-1$ //$NON-NLS-2$
if (file == null || !file.exists() || !file.isFile()) {
- ProjectExamplesActivator.log(NLS.bind(Messages.ProjectUtil_Invalid_URL,url.toString()));
+ ProjectExamplesActivator.log(NLS.bind(Messages.ProjectUtil_Invalid_URL,site.getUrl().toString()));
continue;
}
DocumentBuilderFactory dbf = DocumentBuilderFactory
@@ -147,7 +258,7 @@
}
project.setCategory(category);
}
- if (nodeName.equals("name")) { //$NON-NLS-1$
+ if (nodeName.equals(NAME)) { //$NON-NLS-1$
project.setName(getContent(child));
}
if (nodeName.equals("site")) { //$NON-NLS-1$
@@ -160,7 +271,7 @@
if (nodeName.equals("description")) { //$NON-NLS-1$
project.setDescription(getContent(child));
}
- if (nodeName.equals("url")) { //$NON-NLS-1$
+ if (nodeName.equals(URL)) { //$NON-NLS-1$
project.setUrl(getContent(child));
}
if (nodeName.equals("size")) { //$NON-NLS-1$
@@ -195,7 +306,7 @@
} else {
project.setType(EDITOR);
}
- attribute = child.getAttribute("url"); //$NON-NLS-1$
+ attribute = child.getAttribute(URL); //$NON-NLS-1$
if (attribute == null || attribute.trim().length() <= 0) {
project.setWelcome(false);
ProjectExamplesActivator.log(Messages.ProjectUtil_Invalid_welcome_element);
@@ -206,6 +317,13 @@
}
}
}
+ if (project.getSite() == null) {
+ String siteName = site.getName();
+ if (siteName == null) {
+ siteName = Messages.Project_Unknown;
+ }
+ project.setSite(siteName);
+ }
category.getProjects().add(project);
}
}
@@ -273,4 +391,59 @@
private static ECFExamplesTransport getTransport() {
return ECFExamplesTransport.getInstance();
}
+
+ public static Document getDocument() throws ParserConfigurationException {
+ DocumentBuilderFactory dfactory= DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder= dfactory.newDocumentBuilder();
+ Document doc= docBuilder.newDocument();
+ return doc;
+ }
+
+ public static String getAsXML(Set<ProjectExampleSite> sites)
+ throws ParserConfigurationException, TransformerException,
+ UnsupportedEncodingException {
+ if (sites == null || sites.size() == 0) {
+ return ""; //$NON-NLS-1$
+ }
+ Document doc = getDocument();
+ Element sitesElement = doc.createElement(SITES); //$NON-NLS-1$
+ doc.appendChild(sitesElement);
+ for (ProjectExampleSite site : sites) {
+ Element siteElement = doc.createElement(SITE);
+ siteElement.setAttribute(NAME, site.getName());
+ siteElement.setAttribute(URL, site.getUrl().toString());
+ sitesElement.appendChild(siteElement);
+ }
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ DOMSource source = new DOMSource(doc);
+ StreamResult outputTarget = new StreamResult(s);
+ transformer.transform(source, outputTarget);
+ return s.toString("UTF8"); //$NON-NLS-1$
+ }
+
+ public static Element parseDocument(String document) {
+ Element root = null;
+ InputStream stream = null;
+ try{
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ parser.setErrorHandler(new DefaultHandler());
+ stream = new ByteArrayInputStream(document.getBytes("UTF8")); //$NON-NLS-1$
+ root = parser.parse(stream).getDocumentElement();
+ } catch (Exception e) {
+ ProjectExamplesActivator.log(e);
+ } finally {
+ try{
+ if (stream != null) {
+ stream.close();
+ }
+ } catch(IOException e) {
+ ProjectExamplesActivator.log(e);
+ }
+ }
+ return root;
+ }
}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/SiteCategory.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/SiteCategory.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/SiteCategory.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,25 @@
+package org.jboss.tools.project.examples.model;
+
+import java.util.Set;
+
+public class SiteCategory implements IProjectExampleSite {
+
+ private String name;
+ private Set<ProjectExampleSite> sites;
+
+ public SiteCategory(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Set<ProjectExampleSite> getSites() {
+ return sites;
+ }
+
+ public void setSites(Set<ProjectExampleSite> sites) {
+ this.sites = sites;
+ }
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,249 @@
+package org.jboss.tools.project.examples.preferences;
+
+import java.net.URL;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Group;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.IProjectExampleSite;
+import org.jboss.tools.project.examples.model.ProjectExampleSite;
+import org.jboss.tools.project.examples.model.ProjectUtil;
+import org.jboss.tools.project.examples.model.SiteCategory;
+
+public class ProjectExamplesPreferencePage extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private Button button;
+ private Sites sites;
+ private TreeViewer viewer;
+ private ProjectExampleSite selectedSite;
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ composite.setLayout(layout);
+
+ button = new Button(composite,SWT.CHECK);
+ button.setText(Messages.ProjectExamplesPreferencePage_Show_experimental_sites);
+ IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
+ button.setSelection(store.getBoolean(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES));
+ Group sitesGroup = new Group(composite,SWT.NONE);
+ sitesGroup.setText(Messages.ProjectExamplesPreferencePage_Sites);
+ GridLayout gl = new GridLayout(2,false);
+ sitesGroup.setLayout(gl);
+ sitesGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ viewer = new TreeViewer(sitesGroup,SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ viewer.setContentProvider(new SitesContentProvider());
+ viewer.setLabelProvider(new SitesLabelProvider());
+ sites = new Sites();
+ viewer.setInput(sites);
+ viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
+ viewer.expandAll();
+
+ Composite buttonComposite = new Composite(sitesGroup, SWT.NONE);
+ buttonComposite.setLayout(new GridLayout(1,false));
+ buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+
+ Button addButton = new Button(buttonComposite, SWT.PUSH);
+ addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ addButton.setText(Messages.ProjectExamplesPreferencePage_Add);
+ addButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ SiteDialog dialog = new SiteDialog(getShell(),null,sites);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ String name = dialog.getName();
+ if (name != null) {
+ URL url = dialog.getURL();
+ ProjectExampleSite site = new ProjectExampleSite();
+ site.setUrl(url);
+ site.setName(name);
+ site.setEditable(true);
+ sites.add(site);
+ viewer.refresh();
+ }
+ }
+ }
+
+
+ });
+ final Button editButton = new Button(buttonComposite, SWT.PUSH);
+ editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ editButton.setText(Messages.ProjectExamplesPreferencePage_Edit);
+ editButton.setEnabled(false);
+ editButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ if (selectedSite == null) {
+ return;
+ }
+ SiteDialog dialog = new SiteDialog(getShell(),selectedSite,sites);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ String name = dialog.getName();
+ if (name != null) {
+ URL url = dialog.getURL();
+ ProjectExampleSite site = selectedSite;
+ site.setUrl(url);
+ site.setName(name);
+ site.setEditable(true);
+ viewer.refresh();
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+ final Button removeButton = new Button(buttonComposite, SWT.PUSH);
+ removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ removeButton.setText(Messages.ProjectExamplesPreferencePage_Remove);
+ removeButton.setEnabled(false);
+
+ removeButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ if (selectedSite != null) {
+ sites.remove(selectedSite);
+ viewer.refresh();
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener(){
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ editButton.setEnabled(false);
+ removeButton.setEnabled(false);
+ selectedSite = null;
+ ISelection selection = event.getSelection();
+ if (selection instanceof ITreeSelection) {
+ ITreeSelection treeSelection = (ITreeSelection) selection;
+ Object object = treeSelection.getFirstElement();
+ if (object instanceof ProjectExampleSite) {
+ selectedSite = (ProjectExampleSite) object;
+ boolean editable = ((ProjectExampleSite) object).isEditable();
+ editButton.setEnabled(editable);
+ removeButton.setEnabled(editable);
+ }
+ }
+ }
+ });
+
+ return composite;
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ protected void performDefaults() {
+ button.setSelection(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES_VALUE);
+ sites.getUserSites().clear();
+ storeSites();
+ super.performDefaults();
+ }
+
+ @Override
+ public boolean performOk() {
+ storeSites();
+ return super.performOk();
+ }
+
+ private void storeSites() {
+ IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
+ store.setValue(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES,
button.getSelection());
+ try {
+ String userSites = ProjectUtil.getAsXML(sites.getUserSites());
+ store.setValue(ProjectExamplesActivator.USER_SITES, userSites);
+ } catch (Exception e) {
+ ProjectExamplesActivator.log(e);
+ }
+ }
+
+ class SitesContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Sites) {
+ return ((Sites)parentElement).getSiteCategories();
+ }
+ if (parentElement instanceof SiteCategory) {
+ return ((SiteCategory) parentElement).getSites().toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return element instanceof Sites || element instanceof SiteCategory;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ }
+
+ class SitesLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ return super.getImage(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IProjectExampleSite) {
+ return ((IProjectExampleSite) element).getName();
+ }
+ return super.getText(element);
+ }
+
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencesInitializer.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencesInitializer.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencesInitializer.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,21 @@
+package org.jboss.tools.project.examples.preferences;
+
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+
+public class ProjectExamplesPreferencesInitializer extends
+ AbstractPreferenceInitializer {
+
+ @Override
+ public void initializeDefaultPreferences() {
+ IEclipsePreferences node = new
DefaultScope().getNode("org.jboss.tools.project.examples"); //$NON-NLS-1$
+
+ node.putBoolean(
+ ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES,
+ ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES_VALUE);
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,208 @@
+package org.jboss.tools.project.examples.preferences;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+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.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.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.ProjectExampleSite;
+
+public class SiteDialog extends TitleAreaDialog {
+
+ private static final String ADD_PROJECT_EXAMPLE_SITE =
Messages.SiteDialog_Add_Project_Example_Site;
+ private static final String EDIT_PROJECT_EXAMPLE_SITE =
Messages.SiteDialog_Edit_Project_Example_Site;
+ private Image dlgTitleImage;
+ private ProjectExampleSite selectedSite;
+ private String name;
+ private URL url;
+ private Text nameText;
+ private Text urlText;
+ private Button okButton;
+ private Sites sites;
+
+ protected SiteDialog(Shell parentShell, ProjectExampleSite site, Sites sites) {
+ super(parentShell);
+ this.selectedSite = site;
+ this.sites = sites;
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+
+ Control contents = super.createContents(parent);
+ if (selectedSite == null) {
+ setTitle(ADD_PROJECT_EXAMPLE_SITE);
+ setMessage(ADD_PROJECT_EXAMPLE_SITE);
+ } else {
+ setTitle(EDIT_PROJECT_EXAMPLE_SITE);
+ setMessage(EDIT_PROJECT_EXAMPLE_SITE);
+ }
+ ImageDescriptor descriptor = ProjectExamplesActivator
+ .imageDescriptorFromPlugin(ProjectExamplesActivator.PLUGIN_ID,
+ "icons/new_wiz.gif"); //$NON-NLS-1$
+ if(descriptor != null) {
+ dlgTitleImage = descriptor.createImage();
+ setTitleImage(dlgTitleImage);
+ }
+
+ return contents;
+ }
+
+ @Override
+ public boolean close() {
+ if (dlgTitleImage != null) {
+ dlgTitleImage.dispose();
+ }
+ return super.close();
+ }
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite parentComposite = (Composite) super.createDialogArea(parent);
+ Composite composite = new Composite(parentComposite, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight =
convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth =
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing =
convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing =
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ composite.setFont(parentComposite.getFont());
+
+ Composite container = new Composite(parentComposite, SWT.FILL);
+ layout = new GridLayout(3,false);
+ layout.marginWidth = layout.marginHeight = 5;
+ container.setLayout(layout);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ container.setLayoutData(gd);
+
+ Label nameLabel = new Label(container, SWT.NONE);
+ nameLabel.setText(Messages.SiteDialog_Name);
+ nameText = new Text(container, SWT.SINGLE|SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan=2;
+ nameText.setLayoutData(gd);
+ nameText.addModifyListener(new ModifyListener(){
+
+ public void modifyText(ModifyEvent e) {
+ validatePage();
+ }
+ });
+
+ Label urlLabel = new Label(container, SWT.NONE);
+ urlLabel.setText(Messages.SiteDialog_URL);
+ urlText = new Text(container, SWT.SINGLE|SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ urlText.setLayoutData(gd);
+ urlText.addModifyListener(new ModifyListener(){
+
+ public void modifyText(ModifyEvent e) {
+ validatePage();
+ }
+
+ });
+ if (selectedSite != null) {
+ urlText.setText(selectedSite.getUrl().toString());
+ nameText.setText(selectedSite.getName());
+ }
+ Button browse = new Button(container,SWT.PUSH);
+ browse.setText(Messages.SiteDialog_Browse);
+ browse.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+
+
+ FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE);
+ dialog.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$;
+
+ String result = dialog.open();
+ if (result == null || result.trim().length() == 0) {
+ return;
+ }
+ urlText.setText("file:/" + result); //$NON-NLS-1$
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return parentComposite;
+ }
+
+ private boolean validatePage() {
+ name = null;
+ url = null;
+ if (nameText.getText().trim().length() <= 0) {
+ setErrorMessage(Messages.SiteDialog_The_name_field_is_required);
+ return updateButton(false);
+ }
+ Set<ProjectExampleSite> siteList = sites.getSites();
+ for(ProjectExampleSite site:siteList) {
+ if (site != selectedSite && nameText.getText().equals(site.getName())) {
+ setErrorMessage(Messages.SiteDialog_The_site_already_exists);
+ return updateButton(false);
+ }
+ }
+ if (urlText.getText().trim().length() <= 0) {
+ setErrorMessage(Messages.SiteDialog_The_url_field_is_required);
+ return updateButton(false);
+ }
+ try {
+ @SuppressWarnings("unused")
+ URL url = new URL(urlText.getText());
+ } catch (MalformedURLException e) {
+ setErrorMessage(Messages.SiteDialog_Invalid_URL);
+ return updateButton(false);
+ }
+ setErrorMessage(null);
+ name = nameText.getText();
+ try {
+ url = new URL(urlText.getText());
+ } catch (MalformedURLException ignore) {}
+ return updateButton(true);
+ }
+
+ private boolean updateButton(boolean enabled) {
+ if (okButton != null) {
+ okButton.setEnabled(enabled);
+ }
+ return false;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ okButton = createButton(parent, IDialogConstants.OK_ID,
+ IDialogConstants.OK_LABEL, true);
+ okButton.setEnabled(selectedSite != null);
+ createButton(parent, IDialogConstants.CANCEL_ID,
+ IDialogConstants.CANCEL_LABEL, false);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public URL getURL() {
+ return url;
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/Sites.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/Sites.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/Sites.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -0,0 +1,51 @@
+package org.jboss.tools.project.examples.preferences;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.model.ProjectExampleSite;
+import org.jboss.tools.project.examples.model.ProjectUtil;
+import org.jboss.tools.project.examples.model.SiteCategory;
+
+public class Sites {
+ private SiteCategory[] siteCategories;
+ private SiteCategory userSite;
+ private Set<ProjectExampleSite> sites;
+
+ public SiteCategory[] getSiteCategories() {
+ if (siteCategories == null) {
+ siteCategories = new SiteCategory[2];
+ userSite = new SiteCategory(Messages.Sites_User_sites);
+ Set<ProjectExampleSite> userSites = ProjectUtil.getUserSites();
+ userSite.setSites(userSites);
+ siteCategories[0]=userSite;
+ SiteCategory pluginSite = new SiteCategory(Messages.Sites_Plugin_provided_sites);
+ Set<ProjectExampleSite> pluginSites = ProjectUtil.getPluginSites();
+ pluginSite.setSites(pluginSites);
+ siteCategories[1]=pluginSite;
+ sites = new HashSet<ProjectExampleSite>();
+ sites.addAll(pluginSites);
+ sites.addAll(userSites);
+ }
+ return siteCategories;
+ }
+
+ public void remove(ProjectExampleSite site) {
+ userSite.getSites().remove(site);
+ sites.remove(site);
+ }
+
+ public void add(ProjectExampleSite site) {
+ userSite.getSites().add(site);
+ sites.add(site);
+ }
+
+ public Set<ProjectExampleSite> getSites() {
+ return sites;
+ }
+
+ public Set<ProjectExampleSite> getUserSites() {
+ return userSite.getSites();
+ }
+}
\ No newline at end of file
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2009-05-12
19:14:40 UTC (rev 15235)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2009-05-12
20:02:47 UTC (rev 15236)
@@ -100,7 +100,7 @@
final ProjectExamplesPatternFilter filter = new ProjectExamplesPatternFilter();
int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
- final FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter);
+ final FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter,true);
filteredTree.setBackground(parent.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
final TreeViewer viewer = filteredTree.getViewer();