Author: snjeza
Date: 2010-02-07 18:54:50 -0500 (Sun, 07 Feb 2010)
New Revision: 20167
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/FixDialog.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/PluginFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/ProjectExamplesFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/SeamRuntimeFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectFix.java
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
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/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/NewProjectExamplesWizard.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
workspace/examples/project-examples-3.1.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-5700 Simplify project examples update process
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2010-02-07
23:03:31 UTC (rev 20166)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2010-02-07
23:54:50 UTC (rev 20167)
@@ -21,7 +21,11 @@
org.eclipse.wst.validation,
org.eclipse.ui.views,
org.eclipse.ui.cheatsheets,
- org.eclipse.jdt.core
+ org.eclipse.jdt.core,
+ org.eclipse.wst.server.core,
+ org.jboss.tools.seam.core,
+ org.eclipse.wst.common.project.facet.core,
+ org.jboss.tools.common
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.jboss.tools.project.examples,
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 2010-02-07
23:03:31 UTC (rev 20166)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -11,7 +11,9 @@
package org.jboss.tools.project.examples;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.StringTokenizer;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@@ -26,6 +28,7 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wst.validation.internal.operations.ValidationBuilder;
import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
import org.osgi.framework.BundleContext;
/**
@@ -154,4 +157,33 @@
}
return markers;
}
+
+ public static IProject[] getEclipseProject(Project project,
+ ProjectFix fix) {
+ String pName = fix.getProperties().get(
+ ProjectFix.ECLIPSE_PROJECTS);
+ if (pName == null) {
+ List<String> projectNames = project.getIncludedProjects();
+ List<IProject> projects = new ArrayList<IProject>();
+ for (String projectName:projectNames) {
+ IProject eclipseProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (eclipseProject != null && eclipseProject.isOpen()) {
+ projects.add(eclipseProject);
+ }
+ }
+ return projects.toArray(new IProject[0]);
+ }
+ StringTokenizer tokenizer = new StringTokenizer(pName,","); //$NON-NLS-1$
+ List<IProject> projects = new ArrayList<IProject>();
+ while (tokenizer.hasMoreTokens()) {
+ String projectName = tokenizer.nextToken().trim();
+ if (projectName != null && projectName.length() > 0) {
+ IProject eclipseProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (eclipseProject != null && eclipseProject.isOpen()) {
+ projects.add(eclipseProject);
+ }
+ }
+ }
+ return projects.toArray(new IProject[0]);
+ }
}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/FixDialog.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/FixDialog.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/FixDialog.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -0,0 +1,161 @@
+package org.jboss.tools.project.examples.dialog;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
+
+public class FixDialog extends Dialog {
+
+ private TableViewer tableViewer;
+ private List<ProjectFix> fixes;
+
+ public FixDialog(Shell parentShell, IStructuredSelection selection) {
+ super(parentShell);
+ Iterator iterator = selection.iterator();
+ fixes = new ArrayList<ProjectFix>();
+ while (iterator.hasNext()) {
+ Object object = iterator.next();
+ if (object instanceof Project) {
+ Project project = (Project) object;
+ fixes.addAll(project.getUnsatisfiedFixes());
+ }
+
+ }
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite contents = new Composite(area, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 300;
+ contents.setLayoutData(gd);
+ contents.setLayout(new GridLayout());
+ getShell().setText("Fixes");
+ applyDialogFont(contents);
+ initializeDialogUnits(area);
+
+ Label fixesLabel = new Label(contents, SWT.NULL);
+ fixesLabel.setText("Fixes:");
+ tableViewer = new TableViewer(contents, SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.BORDER | SWT.SINGLE);
+ Table table = tableViewer.getTable();
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 100;
+ table.setLayoutData(gd);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ String[] columnNames = new String[] { "Type", "Short description"
};
+ int[] columnWidths = new int[] { 200, 350 };
+
+ for (int i = 0; i < columnNames.length; i++) {
+ TableColumn tc = new TableColumn(table, SWT.LEFT);
+ tc.setText(columnNames[i]);
+ tc.setWidth(columnWidths[i]);
+ }
+
+ tableViewer.setLabelProvider(new FixLabelProvider());
+ tableViewer.setContentProvider(new FixContentProvider(fixes));
+ tableViewer.setInput(fixes);
+
+ Label descriptionLabel = new Label(contents, SWT.NONE);
+ descriptionLabel.setText("Description:");
+ final Text description = new Text(contents, SWT.BORDER | SWT.MULTI | SWT.WRAP |
SWT.READ_ONLY);
+ gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL |
GridData.GRAB_VERTICAL);
+ gd.heightHint=50;
+ description.setLayoutData(gd);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ description.setText(""); //$NON-NLS-1$
+ ISelection selection = event.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Object fix = ((IStructuredSelection) selection).getFirstElement();
+ if (fix instanceof ProjectFix) {
+ description.setText(((ProjectFix)
fix).getProperties().get(ProjectFix.DESCRIPTION));
+ }
+ }
+ }
+
+ });
+
+ return area;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+ true);
+ }
+
+ private class FixLabelProvider extends LabelProvider implements
+ ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof ProjectFix) {
+ ProjectFix fix = (ProjectFix) element;
+ if (columnIndex == 0) {
+ return fix.getType();
+ }
+ if (columnIndex == 1) {
+ return fix.getProperties().get(ProjectFix.SHORT_DESCRIPTION);
+ }
+ }
+ return null;
+ }
+ }
+
+ private class FixContentProvider implements IStructuredContentProvider {
+
+ private List<ProjectFix> fixes;
+
+ public FixContentProvider(List<ProjectFix> fixes) {
+ this.fixes = fixes;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return fixes.toArray();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/PluginFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/PluginFix.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/PluginFix.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -0,0 +1,31 @@
+package org.jboss.tools.project.examples.fixes;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
+import org.osgi.framework.Bundle;
+
+public class PluginFix implements ProjectExamplesFix {
+
+ public boolean canFix(Project project, ProjectFix fix) {
+ if (!ProjectFix.PLUGIN_TYPE.equals(fix.getType())) {
+ return false;
+ }
+ String symbolicName = fix.getProperties().get(ProjectFix.ID);
+ if (symbolicName == null) {
+ ProjectExamplesActivator.log("Invalid plugin fix in " + project.getName() +
".");
+ return true;
+ }
+ Bundle bundle = Platform.getBundle(symbolicName);
+ return bundle != null;
+ }
+
+ public boolean fix(Project project, ProjectFix fix,
+ IProgressMonitor monitor) {
+ // can't be fixed
+ return false;
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/ProjectExamplesFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/ProjectExamplesFix.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/ProjectExamplesFix.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -0,0 +1,11 @@
+package org.jboss.tools.project.examples.fixes;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
+
+public interface ProjectExamplesFix {
+
+ boolean canFix(Project project, ProjectFix fix);
+ boolean fix(Project project, ProjectFix fix, IProgressMonitor monitor);
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/SeamRuntimeFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/SeamRuntimeFix.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/SeamRuntimeFix.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -0,0 +1,100 @@
+package org.jboss.tools.project.examples.fixes;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.osgi.service.prefs.BackingStoreException;
+
+public class SeamRuntimeFix implements ProjectExamplesFix {
+
+ public boolean canFix(Project project, ProjectFix fix) {
+ if (!ProjectFix.SEAM_RUNTIME.equals(fix.getType())) {
+ return false;
+ }
+ return getBestRuntime(project, fix) != null;
+ }
+
+ private SeamRuntime getBestRuntime(Project project, ProjectFix fix) {
+ String allowedVersions = fix.getProperties().get(ProjectFix.ALLOWED_VERSIONS);
+ if (allowedVersions == null) {
+ ProjectExamplesActivator.log("Invalid Seam runtime fix in " +
project.getName() + ".");
+ return null;
+ }
+ StringTokenizer tokenizer = new StringTokenizer(allowedVersions,",");
//$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ String allowedVersion = tokenizer.nextToken().trim();
+ if (allowedVersion.length() <= 0) {
+ continue;
+ }
+ SeamRuntime[] seamRuntimes = SeamRuntimeManager.getInstance().getRuntimes();
+ if (seamRuntimes == null) {
+ return null;
+ }
+ if (seamRuntimes.length > 0 && ProjectFix.ANY.equals(allowedVersion)) {
+ return seamRuntimes[0];
+ }
+ for (int i = 0; i < seamRuntimes.length; i++) {
+ SeamRuntime seamRuntime = seamRuntimes[i];
+ if (seamRuntime.getVersion().toString().equals(allowedVersion.substring(0, 3))) {
+ return seamRuntime;
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean fix(Project project, ProjectFix fix,
+ IProgressMonitor monitor) {
+ if (!canFix(project, fix)) {
+ return false;
+ }
+ IProject[] eclipseProjects = ProjectExamplesActivator.getEclipseProject(project, fix);
+ if (eclipseProjects.length == 0) {
+ return false;
+ }
+ boolean ret = true;
+ for (int i = 0; i < eclipseProjects.length; i++) {
+ IProject eclipseProject = eclipseProjects[i];
+ if (!fix(project, fix, eclipseProject)) {
+ ret = false;
+ }
+ }
+ return ret;
+ }
+
+ private boolean fix(Project project, ProjectFix fix,
+ IProject eclipseProject) {
+ IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(eclipseProject);
+ String seamRuntimeName = prefs.get(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,
null);
+ SeamRuntime[] seamRuntimes = SeamRuntimeManager.getInstance().getRuntimes();
+ if (seamRuntimeName != null) {
+ for (int i1 = 0; i1 < seamRuntimes.length; i1++) {
+ if (seamRuntimeName.equals(seamRuntimes[i1])) {
+ return true;
+ }
+ }
+ }
+ SeamRuntime seamRuntime = getBestRuntime(project, fix);
+ if (seamRuntime != null) {
+ prefs.put(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME, seamRuntime.getName());
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e) {
+ ProjectExamplesActivator.log(e);
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -0,0 +1,110 @@
+package org.jboss.tools.project.examples.fixes;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IRuntimeType;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
+
+public class WTPRuntimeFix implements ProjectExamplesFix {
+
+ public boolean canFix(Project project, ProjectFix fix) {
+ if (!ProjectFix.WTP_RUNTIME.equals(fix.getType())) {
+ return false;
+ }
+ return getBestRuntime(project, fix) != null;
+ }
+
+ public boolean fix(Project project, ProjectFix fix,
+ IProgressMonitor monitor) {
+ if (!canFix(project, fix)) {
+ return false;
+ }
+ IProject[] eclipseProjects = ProjectExamplesActivator.getEclipseProject(project, fix);
+ if (eclipseProjects.length == 0) {
+ return false;
+ }
+ boolean ret = true;
+ for (int i = 0; i < eclipseProjects.length; i++) {
+ IProject eclipseProject = eclipseProjects[i];
+ try {
+ IFacetedProject facetedProject = ProjectFacetsManager.create(eclipseProject);
+ org.eclipse.wst.common.project.facet.core.runtime.IRuntime wtpRuntime =
facetedProject.getPrimaryRuntime();
+ if (wtpRuntime != null) {
+ IRuntime runtime = getRuntime(wtpRuntime);
+ if (runtime == null) {
+ runtime = getBestRuntime(project, fix);
+ if (runtime != null) {
+ facetedProject.removeTargetedRuntime(wtpRuntime, monitor);
+ wtpRuntime = RuntimeManager.getRuntime(runtime.getId());
+ facetedProject.addTargetedRuntime(wtpRuntime, monitor);
+ facetedProject.setPrimaryRuntime(wtpRuntime, monitor);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ ProjectExamplesActivator.log(e);
+ ret = false;
+ }
+ }
+ return ret;
+ }
+
+ private IRuntime getBestRuntime(Project project, ProjectFix fix) {
+ String allowedTypes = fix.getProperties().get(
+ ProjectFix.ALLOWED_TYPES);
+ if (allowedTypes == null) {
+ ProjectExamplesActivator.log("Invalid WTP runtime fix in "
+ + project.getName() + ".");
+ return null;
+ }
+ StringTokenizer tokenizer = new StringTokenizer(allowedTypes, ",");
//$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ String allowedType = tokenizer.nextToken().trim();
+ if (allowedType.length() <= 0) {
+ continue;
+ }
+ IRuntime[] runtimes = ServerCore.getRuntimes();
+ if (runtimes.length > 0
+ && ProjectFix.ANY.equals(allowedType)) {
+ return runtimes[0];
+ }
+ for (int i = 0; i < runtimes.length; i++) {
+ IRuntime runtime = runtimes[i];
+ IRuntimeType runtimeType = runtime.getRuntimeType();
+ if (runtimeType.getId().equals(allowedType)) {
+ return runtime;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static IRuntime getRuntime(
+ org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime) {
+ if (runtime == null)
+ throw new IllegalArgumentException();
+
+ String id = runtime.getProperty("id"); //$NON-NLS-1$
+ if (id == null)
+ return null;
+
+ IRuntime[] runtimes = ServerCore.getRuntimes();
+ for (IRuntime r : runtimes) {
+ if (id.equals(r.getId()))
+ return r;
+ }
+
+ return null;
+ }
+}
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 2010-02-07
23:03:31 UTC (rev 20166)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -11,6 +11,7 @@
package org.jboss.tools.project.examples.model;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -30,7 +31,10 @@
private String type;
private String welcomeURL;
private String site;
+ private List<ProjectFix> fixes = new ArrayList<ProjectFix>();
+ private List<ProjectFix> unsatisfiedFixes;
+
public Project() {
name=""; //$NON-NLS-1$
shortDescription=""; //$NON-NLS-1$
@@ -151,4 +155,20 @@
public void setSite(String site) {
this.site = site;
}
+
+ public List<ProjectFix> getFixes() {
+ return fixes;
+ }
+
+ public void setFixes(List<ProjectFix> fixes) {
+ this.fixes = fixes;
+ }
+
+ public List<ProjectFix> getUnsatisfiedFixes() {
+ return unsatisfiedFixes;
+ }
+
+ public void setUnsatisfiedFixes(List<ProjectFix> unsatisfiedFixes) {
+ this.unsatisfiedFixes = unsatisfiedFixes;
+ }
}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectFix.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectFix.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -0,0 +1,37 @@
+package org.jboss.tools.project.examples.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ProjectFix {
+
+ public final static String WTP_RUNTIME = "wtpruntime"; //$NON-NLS-1$
+ public final static String SEAM_RUNTIME = "seam"; //$NON-NLS-1$
+ public final static String DROOLS_RUNTIME = "drools"; //$NON-NLS-1$
+ public final static String PLUGIN_TYPE = "plugin"; //$NON-NLS-1$
+ public final static String ALLOWED_VERSIONS = "allowed-versions";
//$NON-NLS-1$
+ public final static String ECLIPSE_PROJECTS = "eclipse-projects";
//$NON-NLS-1$
+ public final static String ALLOWED_TYPES = "allowed-types"; //$NON-NLS-1$
+ public final static String ID = "id"; //$NON-NLS-1$
+ public final static String VERSION = "VERSION"; //$NON-NLS-1$
+ public final static String DESCRIPTION = "description"; //$NON-NLS-1$
+ public final static String SHORT_DESCRIPTION = "short-description";
//$NON-NLS-1$
+ public final static String ANY = "any"; //$NON-NLS-1$
+
+ private String type;
+ private Map<String,String> properties = new HashMap<String,String>();
+
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+ public void setProperties(Map<String, String> properties) {
+ this.properties = properties;
+ }
+
+}
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 2010-02-07
23:03:31 UTC (rev 20166)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -242,6 +242,10 @@
if (cNode.getNodeType() == Node.ELEMENT_NODE) {
Element child = (Element) cNode;
String nodeName = child.getNodeName();
+ if (nodeName.equals("fixes")) { //$NON-NLS-1$
+ parseFixes(project, child);
+ }
+
if (nodeName.equals("category")) { //$NON-NLS-1$
String value = getContent(child);
boolean found = false;
@@ -334,9 +338,52 @@
return list;
}
+ private static void parseFixes(Project project, Element node) {
+ NodeList children = node.getChildNodes();
+ int cLen = children.getLength();
+ for (int i = 0; i < cLen; i++) {
+ Node cNode = children.item(i);
+ if (cNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element child = (Element) cNode;
+ String nodeName = child.getNodeName();
+ if (nodeName.equals("fix")) { //$NON-NLS-1$
+ parseFix(project,child);
+ }
+ }
+ }
+ }
+
+ private static void parseFix(Project project, Element node) {
+ String type = node.getAttribute("type"); //$NON-NLS-1$
+ if (type == null || type.trim().length() <= 0) {
+ ProjectExamplesActivator.log("Invalid fix.");
+ return;
+ }
+ ProjectFix fix = new ProjectFix();
+ fix.setType(type);
+ NodeList children = node.getChildNodes();
+ int cLen = children.getLength();
+ for (int i = 0; i < cLen; i++) {
+ Node cNode = children.item(i);
+ if (cNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element child = (Element) cNode;
+ String nodeName = child.getNodeName();
+ if (nodeName.equals("property")) { //$NON-NLS-1$
+ String name = child.getAttribute("name"); //$NON-NLS-1$
+ if (name == null || name.trim().length() <= 0) {
+ ProjectExamplesActivator.log("Invalid property.");
+ return;
+ }
+ String value = getContent(child);
+ fix.getProperties().put(name, value);
+ }
+ }
+ }
+ project.getFixes().add(fix);
+ }
+
private static String getProjectExamplesXml() {
- String projectXML = System
- .getProperty("org.jboss.tools.project.examples.xml"); //$NON-NLS-1$
+ String projectXML =
System.getProperty("org.jboss.tools.project.examples.xml"); //$NON-NLS-1$
if (projectXML != null && projectXML.length() > 0) {
return projectXML;
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2010-02-07
23:03:31 UTC (rev 20166)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -73,7 +73,10 @@
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.dialog.MarkerDialog;
+import org.jboss.tools.project.examples.fixes.SeamRuntimeFix;
+import org.jboss.tools.project.examples.fixes.WTPRuntimeFix;
import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
import org.jboss.tools.project.examples.model.ProjectUtil;
public class NewProjectExamplesWizard extends Wizard implements INewWizard {
@@ -155,7 +158,9 @@
setName(Messages.NewProjectExamplesWizard_Importing);
for (Project project : projects) {
importProject(project, files.get(i++), monitor);
+ fix(project, monitor);
}
+
} catch (final Exception e) {
Display.getDefault().syncExec(new Runnable() {
@@ -305,6 +310,19 @@
});
}
+ public static void fix(Project project, IProgressMonitor monitor) {
+ List<ProjectFix> fixes = project.getFixes();
+ for (ProjectFix fix:fixes) {
+ if (ProjectFix.WTP_RUNTIME.equals(fix.getType())) {
+ new WTPRuntimeFix().fix(project, fix, monitor);
+ }
+ if (ProjectFix.SEAM_RUNTIME.equals(fix.getType())) {
+ new SeamRuntimeFix().fix(project, fix, monitor);
+ }
+ }
+ }
+
+
public static void importProject(Project projectDescription, File file,
IProgressMonitor monitor) throws Exception {
if (projectDescription.getIncludedProjects() == null) {
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 2010-02-07
23:03:31 UTC (rev 20166)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2010-02-07
23:54:50 UTC (rev 20167)
@@ -11,12 +11,15 @@
package org.jboss.tools.project.examples.wizard;
-import java.util.HashSet;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.StringTokenizer;
import java.util.TreeSet;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -39,13 +42,24 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.FilteredTree;
-import org.eclipse.ui.internal.dialogs.WizardPatternFilter;
import org.eclipse.ui.model.AdaptableList;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IRuntimeType;
+import org.eclipse.wst.server.core.ServerCore;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.dialog.FixDialog;
+import org.jboss.tools.project.examples.fixes.PluginFix;
+import org.jboss.tools.project.examples.fixes.SeamRuntimeFix;
+import org.jboss.tools.project.examples.fixes.WTPRuntimeFix;
import org.jboss.tools.project.examples.model.Category;
import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectFix;
import org.jboss.tools.project.examples.model.ProjectUtil;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
+import org.osgi.framework.Bundle;
/**
* @author snjeza
@@ -56,6 +70,11 @@
private IStructuredSelection selection;
private Button showQuickFixButton;
private Combo siteCombo;
+ private Text noteText;
+ private Button details;
+ private PageBook notesPageBook;
+ private Composite noteEmptyComposite;
+ private Composite noteComposite;
public NewProjectExamplesWizardPage() {
super("org.jboss.tools.project.examples"); //$NON-NLS-1$
@@ -167,6 +186,27 @@
Object object = iterator.next();
if (object instanceof Project) {
canFinish=true;
+ Project project = (Project) object;
+ if (project.getUnsatisfiedFixes() == null) {
+ List<ProjectFix> fixes = project.getFixes();
+ List<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
+ project.setUnsatisfiedFixes(unsatisfiedFixes);
+ for (ProjectFix fix:fixes) {
+ if (!canFix(project, fix)) {
+ unsatisfiedFixes.add(fix);
+ }
+ }
+ }
+ if (project.getUnsatisfiedFixes().size() > 0) {
+ notesPageBook.showPage(noteComposite);
+ noteComposite.setVisible(true);
+ noteEmptyComposite.setVisible(false);
+ } else {
+ notesPageBook.showPage(noteEmptyComposite);
+ noteComposite.setVisible(false);
+ noteEmptyComposite.setVisible(true);
+ }
+
} else {
canFinish=false;
break;
@@ -177,6 +217,49 @@
});
+ notesPageBook = new PageBook( internal , SWT.NONE );
+ notesPageBook.setLayout(new GridLayout(1,false));
+ gd=new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan=2;
+ notesPageBook.setLayoutData( gd );
+
+ noteEmptyComposite = new Composite( notesPageBook, SWT.NONE );
+ noteEmptyComposite.setLayout( new GridLayout(1, false));
+ //notesEmptyComposite.setVisible( false );
+ gd=new GridData(GridData.FILL_HORIZONTAL);
+ noteEmptyComposite.setLayoutData(gd);
+
+ noteComposite = new Composite(notesPageBook, SWT.NONE);
+ noteComposite.setLayout(new GridLayout(2,false));
+ //notesComposite.setText("Note");
+ gd=new GridData(GridData.FILL_HORIZONTAL);
+ noteComposite.setLayoutData(gd);
+ noteComposite.setVisible(false);
+
+ notesPageBook.showPage(noteEmptyComposite);
+
+ Label noteLabel = new Label(noteComposite,SWT.NONE);
+ gd=new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ noteLabel.setText("Note:");
+ noteLabel.setLayoutData(gd);
+ noteText = new Text(noteComposite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
+ noteText.setText(""); //$NON-NLS-1$
+ gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL |
GridData.GRAB_VERTICAL);
+ gd.heightHint=50;
+ noteText.setLayoutData(gd);
+ noteText.setText("You could face a problem when importing this project example.
For more details click the Details button.");
+
+ details = new Button(noteComposite, SWT.PUSH);
+ details.setText("Details...");
+ details.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Dialog dialog = new FixDialog(getShell(), getSelection());
+ dialog.open();
+ }
+ });
+
showQuickFixButton = new Button(internal,SWT.CHECK);
showQuickFixButton.setText(Messages.NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog);
showQuickFixButton.setSelection(true);
@@ -221,6 +304,23 @@
setControl(composite);
}
+ private boolean canFix(Project project,ProjectFix fix) {
+ String type = fix.getType();
+ if (ProjectFix.PLUGIN_TYPE.equals(type)) {
+ return new PluginFix().canFix(project, fix);
+ }
+
+ if (ProjectFix.WTP_RUNTIME.equals(type)) {
+ return new WTPRuntimeFix().canFix(project, fix);
+ }
+
+ if (ProjectFix.SEAM_RUNTIME.equals(type)) {
+ return new SeamRuntimeFix().canFix(project, fix);
+ }
+ ProjectExamplesActivator.log("Invalid fix in " + project.getName() +
".");
+ return true;
+ }
+
private void refresh(final TreeViewer viewer) {
AdaptableList input = new AdaptableList(getCategories());
viewer.setInput(input);
Modified: workspace/examples/project-examples-3.1.xml
===================================================================
--- workspace/examples/project-examples-3.1.xml 2010-02-07 23:03:31 UTC (rev 20166)
+++ workspace/examples/project-examples-3.1.xml 2010-02-07 23:54:50 UTC (rev 20167)
@@ -135,7 +135,6 @@
</fix>
<fix type="seam">
- <!-- support version ranges ? -->
<property name="allowed-versions">2.2.0</property>
<property name="short-description">Missing Seam
Runtime</property>
<property name="eclipse-projects">booking22</property>