Author: snjeza
Date: 2008-11-10 13:44:11 -0500 (Mon, 10 Nov 2008)
New Revision: 11644
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/dialog/MarkerDialog.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
Log:
JBIDE-3063 Make the project examples support download of one zip for multiple projects
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 2008-11-10
18:43:00 UTC (rev 11643)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2008-11-10
18:44:11 UTC (rev 11644)
@@ -40,7 +40,7 @@
private static ProjectExamplesActivator plugin;
private static BundleContext context;
-
+
public static Job waitForBuildAndValidation = new Job("Waiting...") {
@Override
@@ -113,14 +113,15 @@
public static List<IMarker> getMarkers(List<Project> projects) {
List<IMarker> markers = new ArrayList<IMarker>();
- for(Project project:projects) {
+ for (Project project : projects) {
try {
- String projectName = project.getName();
- IProject eclipseProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- IMarker[] projectMarkers = eclipseProject.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
- for (int i = 0; i < projectMarkers.length; i++) {
- if (projectMarkers[i].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) ==
IMarker.SEVERITY_ERROR) {
- markers.add(projectMarkers[i]);
+ if (project.getIncludedProjects() == null) {
+ String projectName = project.getName();
+ getMarkers(markers, projectName);
+ } else {
+ List<String> includedProjects = project.getIncludedProjects();
+ for (String projectName:includedProjects) {
+ getMarkers(markers, projectName);
}
}
} catch (CoreException e) {
@@ -129,4 +130,19 @@
}
return markers;
}
+
+ private static List<IMarker> getMarkers(List<IMarker> markers,
+ String projectName) throws CoreException {
+ IProject eclipseProject = ResourcesPlugin.getWorkspace()
+ .getRoot().getProject(projectName);
+ IMarker[] projectMarkers = eclipseProject.findMarkers(
+ IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ for (int i = 0; i < projectMarkers.length; i++) {
+ if (projectMarkers[i].getAttribute(IMarker.SEVERITY,
+ IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR) {
+ markers.add(projectMarkers[i]);
+ }
+ }
+ return markers;
+ }
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/MarkerDialog.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/MarkerDialog.java 2008-11-10
18:43:00 UTC (rev 11643)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/MarkerDialog.java 2008-11-10
18:44:11 UTC (rev 11644)
@@ -24,6 +24,7 @@
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -70,9 +71,9 @@
import org.jboss.tools.project.examples.model.Project;
/**
-* @author snjeza
-*
-*/
+ * @author snjeza
+ *
+ */
public class MarkerDialog extends TitleAreaDialog {
private static final String QUICK_FIX = "Quick Fix";
@@ -83,7 +84,7 @@
private Button finishButton;
private TableViewer tableViewer;
private IResourceChangeListener resourceChangeListener;
-
+
private class QuickFixWizardDialog extends WizardDialog {
/**
@@ -93,12 +94,11 @@
public QuickFixWizardDialog(Shell parentShell, IWizard newWizard) {
super(parentShell, newWizard);
setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
- | SWT.MODELESS | SWT.RESIZE | getDefaultOrientation());
+ | SWT.MODELESS | SWT.RESIZE | getDefaultOrientation());
}
}
-
public MarkerDialog(Shell parentShell, List<Project> projects) {
super(parentShell);
this.projects = projects;
@@ -126,8 +126,8 @@
Label markersLabel = new Label(contents, SWT.NULL);
markersLabel.setText("Markers:");
- tableViewer = new TableViewer(contents, SWT.H_SCROLL
- | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE);
+ tableViewer = new TableViewer(contents, SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.BORDER | SWT.SINGLE);
Table table = tableViewer.getTable();
gd = new GridData(GridData.FILL_BOTH);
table.setLayoutData(gd);
@@ -165,15 +165,16 @@
Display.getDefault().asyncExec(new Runnable() {
public void run() {
- if (tableViewer != null && !tableViewer.getTable().isDisposed()) {
+ if (tableViewer != null
+ && !tableViewer.getTable().isDisposed()) {
refreshTableViewer();
}
}
-
+
});
}
-
+
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(
resourceChangeListener);
@@ -186,7 +187,8 @@
_dlgTitleImage.dispose();
}
if (resourceChangeListener != null) {
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(
+ resourceChangeListener);
resourceChangeListener = null;
}
return super.close();
@@ -219,13 +221,18 @@
try {
quickFixButton.setSelection(false);
openQuickFixWizard(selected);
- for (Project project:projects) {
- IProject eclipseProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(project.getName());
- if (eclipseProject != null && eclipseProject.isOpen()) {
- eclipseProject.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
+ for (Project project : projects) {
+ if (project.getIncludedProjects() == null) {
+ buildProject(project.getName());
+ } else {
+ List<String> includedProjects = project.getIncludedProjects();
+ for (String projectName:includedProjects) {
+ buildProject(projectName);
+ }
}
}
- ProjectExamplesActivator.waitForBuildAndValidation.schedule();
+ ProjectExamplesActivator.waitForBuildAndValidation
+ .schedule();
ProjectExamplesActivator.waitForBuildAndValidation.join();
} catch (Exception e) {
ProjectExamplesActivator.log(e);
@@ -236,6 +243,16 @@
}
}
+ private void buildProject(String projectName) throws CoreException {
+ IProject eclipseProject = ResourcesPlugin
+ .getWorkspace().getRoot().getProject(projectName);
+ if (eclipseProject != null
+ && eclipseProject.isOpen()) {
+ eclipseProject.build(
+ IncrementalProjectBuilder.CLEAN_BUILD,
+ null);
+ }
+ }
private void refreshTableViewer() {
tableViewer.setInput(projects);
@@ -248,9 +265,10 @@
}
}
- private void openQuickFixWizard(final IMarker selected) throws ExecutionException {
+ private void openQuickFixWizard(final IMarker selected)
+ throws ExecutionException {
final Map resolutions = new LinkedHashMap();
-
+
IRunnableWithProgress resolutionsRunnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor
@@ -258,7 +276,8 @@
MarkerMessages.resolveMarkerAction_computationManyAction,
100);
- IMarker[] allMarkers = (IMarker[])
ProjectExamplesActivator.getMarkers(projects).toArray(new IMarker[0]);
+ IMarker[] allMarkers = (IMarker[]) ProjectExamplesActivator
+ .getMarkers(projects).toArray(new IMarker[0]);
monitor.worked(20);
IMarkerResolution[] found = IDE.getMarkerHelpRegistry()
.getResolutions(selected);
@@ -289,8 +308,8 @@
Object service = null;
- IRunnableContext context = new
ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getShell());
+ IRunnableContext context = new ProgressMonitorDialog(PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getShell());
try {
if (service == null) {
@@ -330,22 +349,23 @@
markerDescription);
Wizard wizard = new QuickFixWizard(description, resolutions);
- wizard.setWindowTitle(MarkerMessages.resolveMarkerAction_dialogTitle);
- WizardDialog dialog = new
QuickFixWizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
wizard);
+ wizard
+ .setWindowTitle(MarkerMessages.resolveMarkerAction_dialogTitle);
+ WizardDialog dialog = new QuickFixWizardDialog(PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getShell(),
+ wizard);
dialog.open();
}
}
private IMarkerResolution[] getMarkerResolutions(ISelection source) {
IStructuredSelection selection = (IStructuredSelection) source;
- IMarker marker = (IMarker) selection
- .getFirstElement();
+ IMarker marker = (IMarker) selection.getFirstElement();
if (marker == null) {
return EMPTY_ARRAY;
}
- IMarkerResolution[] resolutions = IDE
- .getMarkerHelpRegistry().getResolutions(
- marker);
+ IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry()
+ .getResolutions(marker);
return resolutions;
}
}
\ No newline at end of file
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 2008-11-10
18:43:00 UTC (rev 11643)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2008-11-10
18:44:11 UTC (rev 11644)
@@ -11,6 +11,7 @@
package org.jboss.tools.project.examples.model;
import java.math.BigDecimal;
+import java.util.List;
/**
* @author snjeza
@@ -24,6 +25,7 @@
private String url;
private long size;
private Category category;
+ private List<String> includedProjects;
public Project() {
name="";
@@ -95,4 +97,12 @@
}
return sizeString;
}
+
+ public List<String> getIncludedProjects() {
+ return includedProjects;
+ }
+
+ public void setIncludedProjects(List<String> includedProjects) {
+ this.includedProjects = includedProjects;
+ }
}
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 2008-11-10
18:43:00 UTC (rev 11643)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2008-11-10
18:44:11 UTC (rev 11644)
@@ -20,6 +20,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -169,6 +170,18 @@
}
project.setSize(size);
}
+ if (nodeName.equals("includedProjects")) {
+ String includedProjects = getContent(child);
+ if (includedProjects != null) {
+ includedProjects = includedProjects.trim();
+ StringTokenizer tokenizer = new
StringTokenizer(includedProjects,",");
+ List<String> projectList = new ArrayList<String>();
+ while (tokenizer.hasMoreTokens()) {
+ projectList.add(tokenizer.nextToken());
+ }
+ project.setIncludedProjects(projectList);
+ }
+ }
}
}
}
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 2008-11-10
18:43:00 UTC (rev 11643)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2008-11-10
18:44:11 UTC (rev 11644)
@@ -15,9 +15,14 @@
*
*/
import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IMarker;
@@ -28,11 +33,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
@@ -45,9 +48,10 @@
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.internal.services.SourceProviderService;
+import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
-import org.eclipse.wst.validation.internal.operations.ValidationBuilder;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.dialog.MarkerDialog;
import org.jboss.tools.project.examples.model.Project;
@@ -159,8 +163,10 @@
public void done(IJobChangeEvent event) {
try {
- ProjectExamplesActivator.waitForBuildAndValidation.schedule();
- ProjectExamplesActivator.waitForBuildAndValidation.join();
+ ProjectExamplesActivator.waitForBuildAndValidation
+ .schedule();
+ ProjectExamplesActivator.waitForBuildAndValidation
+ .join();
} catch (InterruptedException e) {
return;
@@ -208,6 +214,60 @@
private void importProject(Project projectDescription, File file,
IProgressMonitor monitor) throws Exception {
+ if (projectDescription.getIncludedProjects() == null) {
+ importSingleProject(projectDescription, file, monitor);
+ } else {
+ List<String> projects = projectDescription.getIncludedProjects();
+ for (final String projectName : projects) {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject project = workspace.getRoot().getProject(projectName);
+ if (project.exists()) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ overwrite = MessageDialog.openQuestion(getShell(),
+ "Question", "Overwrite project '"
+ + projectName + "'");
+ }
+
+ });
+ if (!overwrite) {
+ return;
+ }
+ project.delete(true, true, monitor);
+ }
+ project.create(monitor);
+ project.open(monitor);
+ ZipFile sourceFile = new ZipFile(file);
+ ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
+ sourceFile);
+
+ Enumeration<? extends ZipEntry> entries = sourceFile.entries();
+ ZipEntry entry = null;
+ List<ZipEntry> filesToImport = new ArrayList<ZipEntry>();
+ String prefix = projectName + "/";
+ while (entries.hasMoreElements()) {
+ entry = entries.nextElement();
+ if (entry.getName().startsWith(prefix)) {
+ filesToImport.add(entry);
+ }
+ }
+ //ZipEntry entry = sourceFile.getEntry(projectName);
+
+ //List filesToImport = prepareFileList(structureProvider, entry, null);
+
+ ImportOperation operation = new ImportOperation(workspace
+ .getRoot().getFullPath(), structureProvider.getRoot(),
+ structureProvider, OVERWRITE_ALL_QUERY, filesToImport);
+ operation.setContext(getShell());
+ operation.run(monitor);
+ }
+ }
+ }
+
+ private void importSingleProject(Project projectDescription, File file,
+ IProgressMonitor monitor) throws CoreException, ZipException,
+ IOException, InvocationTargetException, InterruptedException {
final String projectName = projectDescription.getName();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
@@ -237,7 +297,6 @@
OVERWRITE_ALL_QUERY);
operation.setContext(getShell());
operation.run(monitor);
-
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
@@ -260,4 +319,25 @@
addPage(page);
}
+ private static List prepareFileList(IImportStructureProvider structure,
+ ZipEntry entry, List list) {
+ if (structure == null || entry == null)
+ return null;
+ if (list == null) {
+ list = new ArrayList();
+ }
+ List son = structure.getChildren(entry);
+ if (son == null)
+ return list;
+ Iterator it = son.iterator();
+ while (it.hasNext()) {
+ ZipEntry temp = (ZipEntry) it.next();
+ if (temp.isDirectory()) {
+ prepareFileList(structure, temp, list);
+ } else {
+ list.add(temp);
+ }
+ }
+ return list;
+ }
}