Author: snjeza
Date: 2011-10-04 07:47:23 -0400 (Tue, 04 Oct 2011)
New Revision: 35320
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
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/Project.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/ProjectModelElement.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/model/SiteCategory.java
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/SiteDialog.java
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/wizard/NewProjectExamplesWizardPage.java
Log:
JBIDE-9708 project examples should resolve its path relative to the location of the
projectexample.xml file by default
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -14,7 +14,6 @@
import java.util.List;
import org.jboss.tools.project.examples.Messages;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
/**
* @author snjeza
@@ -24,6 +23,7 @@
private String name;
private List<Project> projects = new ArrayList<Project>();
+ private IProjectExampleSite site;
public static Category OTHER = new Category(Messages.Category_Other);
public Category(String name) {
@@ -80,8 +80,13 @@
return getName();
}
- public String getSite() {
- return ProjectExamplesActivator.ALL_SITES;
+ public IProjectExampleSite getSite() {
+ return site;
}
+ @Override
+ public void setSite(IProjectExampleSite site) {
+ this.site = site;
+ }
+
}
Modified:
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IProjectExampleSite.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -1,5 +1,21 @@
package org.jboss.tools.project.examples.model;
+import java.net.URL;
+
public interface IProjectExampleSite {
public String getName();
+
+ public void setEditable(boolean editable);
+
+ public boolean isEditable();
+
+ public void setExperimental(boolean experimental);
+
+ public boolean isExperimental();
+
+ public void setName(String name);
+
+ public void setUrl(URL url);
+
+ public URL getUrl();
}
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -12,9 +12,12 @@
import java.io.File;
import java.math.BigDecimal;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
/**
@@ -23,6 +26,8 @@
*/
public class Project implements ProjectModelElement {
+ private static final String SEP = "/"; //$NON-NLS-1$
+ private static String[] PREFIXES = { "file:" , "http:",
"https:" , "ftp:" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
private String name;
private String shortDescription;
private String description;
@@ -33,7 +38,6 @@
private boolean welcome;
private String type;
private String welcomeURL;
- private String site;
private List<ProjectFix> fixes = new ArrayList<ProjectFix>();
private List<ProjectFix> unsatisfiedFixes;
private String perspectiveId;
@@ -41,6 +45,7 @@
private String importTypeDescription;
private ArchetypeModel archetypeModel = new ArchetypeModel();
private File file;
+ private IProjectExampleSite site;
public Project() {
name=""; //$NON-NLS-1$
@@ -78,7 +83,35 @@
}
public String getUrl() {
- return url;
+ if (url == null) {
+ return url;
+ }
+ url = url.trim();
+ for (String prefix:PREFIXES) {
+ if (url.startsWith(prefix)) {
+ return url;
+ }
+ }
+ if (site == null) {
+ return url;
+ }
+ URL siteURL = site.getUrl();
+ if (siteURL == null) {
+ return url;
+ }
+ String urlString = siteURL.toString();
+ if (urlString.endsWith(SEP)) {
+ urlString = urlString.substring(0, urlString.length() - 1);
+ } else {
+ int index = urlString.lastIndexOf(SEP);
+ if (index > 0) {
+ urlString = urlString.substring(0, index);
+ }
+ }
+ if (url.startsWith(SEP)) {
+ return urlString + url;
+ }
+ return urlString + SEP + url;
}
public void setUrl(String url) {
@@ -148,7 +181,7 @@
this.welcomeURL = welcomeURL;
}
- public String getSite() {
+ public IProjectExampleSite getSite() {
/*if (site == null) {
if (getUrl().startsWith("http://anonsvn.jboss.org")) { //$NON-NLS-1$
site = Messages.Project_JBoss_Tools_Team_from_jboss_org;
@@ -161,7 +194,7 @@
return site;
}
- public void setSite(String site) {
+ public void setSite(IProjectExampleSite site) {
this.site = site;
}
Modified:
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleSite.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -11,34 +11,42 @@
public ProjectExampleSite() {
}
+ @Override
public URL getUrl() {
return url;
}
+ @Override
public void setUrl(URL url) {
this.url = url;
}
+ @Override
public String getName() {
return name;
}
+ @Override
public void setName(String name) {
this.name = name;
}
+ @Override
public boolean isExperimental() {
return experimental;
}
+ @Override
public void setExperimental(boolean experimental) {
this.experimental = experimental;
}
+ @Override
public boolean isEditable() {
return editable;
}
+ @Override
public void setEditable(boolean editable) {
this.editable = editable;
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -19,5 +19,6 @@
public String getName();
public String getDescription();
public String getShortDescription();
- public String getSite();
+ public IProjectExampleSite getSite();
+ public void setSite(IProjectExampleSite site);
}
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -245,6 +245,7 @@
for (int i = 0; i < len; i++) {
Node node = projects.item(i);
Project project = new Project();
+ project.setSite(site);
Category category = other;
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
@@ -271,6 +272,7 @@
}
if (!found) {
category = new Category(value);
+ category.setSite(site);
list.add(category);
}
project.setCategory(category);
@@ -278,9 +280,6 @@
if (nodeName.equals(NAME)) {
project.setName(getContent(child));
}
- if (nodeName.equals("site")) { //$NON-NLS-1$
- project.setSite(getContent(child));
- }
if (nodeName.equals("shortDescription")) { //$NON-NLS-1$
project
.setShortDescription(getContent(child));
@@ -344,13 +343,6 @@
}
}
}
- if (project.getSite() == null) {
- String siteName = site.getName();
- if (siteName == null) {
- siteName = Messages.Project_Unknown;
- }
- project.setSite(siteName);
- }
category.getProjects().add(project);
}
}
Modified:
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/SiteCategory.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -10,6 +10,7 @@
************************************************************************************/
package org.jboss.tools.project.examples.model;
+import java.net.URL;
import java.util.Set;
/**
@@ -37,4 +38,28 @@
public void setSites(Set<ProjectExampleSite> sites) {
this.sites = sites;
}
+
+ public void setEditable(boolean editable) {
+ }
+
+ public boolean isEditable() {
+ return false;
+ }
+
+ public void setExperimental(boolean experimental) {
+ }
+
+ public boolean isExperimental() {
+ return false;
+ }
+
+ public void setName(String name) {
+ }
+
+ public void setUrl(URL url) {
+ }
+
+ public URL getUrl() {
+ return null;
+ }
}
Modified:
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -179,7 +179,7 @@
Object object = treeSelection.getFirstElement();
if (object instanceof ProjectExampleSite) {
selectedSite = (ProjectExampleSite) object;
- boolean editable = ((ProjectExampleSite) object).isEditable();
+ boolean editable = ((IProjectExampleSite) object).isEditable();
editButton.setEnabled(editable);
removeButton.setEnabled(editable);
}
Modified:
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -35,6 +35,7 @@
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.IProjectExampleSite;
import org.jboss.tools.project.examples.model.ProjectExampleSite;
/**
@@ -175,7 +176,7 @@
return updateButton(false);
}
Set<ProjectExampleSite> siteList = sites.getSites();
- for(ProjectExampleSite site:siteList) {
+ for(IProjectExampleSite site:siteList) {
if (site != selectedSite && nameText.getText().equals(site.getName())) {
setErrorMessage(Messages.SiteDialog_The_site_already_exists);
return updateButton(false);
Modified:
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/Sites.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -14,6 +14,7 @@
import java.util.Set;
import org.jboss.tools.project.examples.Messages;
+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;
@@ -46,7 +47,7 @@
return siteCategories;
}
- public void remove(ProjectExampleSite site) {
+ public void remove(IProjectExampleSite site) {
userSite.getSites().remove(site);
sites.remove(site);
}
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 2011-10-04
10:53:42 UTC (rev 35319)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2011-10-04
11:47:23 UTC (rev 35320)
@@ -441,7 +441,8 @@
for (Category category:categories) {
List<Project> projects = category.getProjects();
for (Project project:projects) {
- sites.add(project.getSite());
+ String name = project.getSite() == null ? ProjectExamplesActivator.ALL_SITES :
project.getSite().getName();
+ sites.add(name);
}
}
String[] items = sites.toArray(new String[0]);