Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Eisenberg2013-09-22 00:13:33 -0400
committerIgor Fedorenko2013-09-24 13:24:45 -0400
commit647f33a68489084f2021742dc4bfde8acb139cd9 (patch)
tree5ae058bbba5586fe445aba67406b19a10544f688
parentca8878d7b261bab75cd86e00176c387dd90fc88b (diff)
downloadm2e-core-647f33a68489084f2021742dc4bfde8acb139cd9.tar.gz
m2e-core-647f33a68489084f2021742dc4bfde8acb139cd9.tar.xz
m2e-core-647f33a68489084f2021742dc4bfde8acb139cd9.zip
408042 Automatically create a new working set based on root project name on maven project import.
1. place new checkbox below existing working set creation area so as to make the two buttons look connected 2. Update label on new button with working set name when a new root project is selected. See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=408042#c7 Signed-off-by: Igor Fedorenko <igor@ifedorenko.com> Signed-off-by: Andrew Eisenberg <andrew@eisenberg.as>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java2
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties1
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java27
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java39
4 files changed, 65 insertions, 4 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
index be568c01..3086eeaa 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
@@ -229,6 +229,8 @@ public class Messages extends NLS {
public static String MavenImportWizard_title;
+ public static String MavenImportWizardPage_createWorkingSet;
+
public static String MavenImportWizardPage_desc;
public static String MavenImportWizardPage_inherited;
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
index ebe9d71a..746947e0 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
@@ -117,6 +117,7 @@ MavenGoalSelectionDialog_btnQualified=Use &Qualified Name
MavenGoalSelectionDialog_error=Should select at least one goal
MavenGoalSelectionDialog_lblSelect=&Select Goal\:
MavenGoalSelectionDialog_message=Select goal\:
+MavenImportWizardPage_createWorkingSet=Create working set based on root project name ({0})
MavenImportWizardPage_btnDeselectTree_text=Deselect Tree
MavenImportWizardPage_btnSelectTree_text=Select Tree
MavenImportWizardPage_desc=Select Maven projects
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java
index 76641dfe..fd755132 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java
@@ -29,6 +29,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -46,6 +47,9 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
@@ -85,7 +89,7 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
private static final Logger LOG = LoggerFactory.getLogger(MavenImportWizard.class);
- private MavenImportWizardPage page;
+ MavenImportWizardPage page;
private LifecycleMappingPage lifecycleMappingPage;
@@ -192,6 +196,22 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
}
if(doImport) {
+
+ String workingSetName = getRootProjectName();
+ if(page.shouldCreateWorkingSetForRoot() && projects.size() > 0 && workingSetName != null) {
+ IWorkingSetManager wsm = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = wsm.getWorkingSet(workingSetName);
+ if(workingSet == null) {
+ workingSet = wsm.createWorkingSet(workingSetName, new IAdaptable[0]);
+ // TODO is there a constant we should be setting here?
+ workingSet.setId("org.eclipse.ui.resourceWorkingSetPage");
+ wsm.addWorkingSet(workingSet);
+ }
+ if(!workingSets.contains(workingSet)) {
+ workingSets.add(workingSet);
+ }
+ }
+
final IRunnableWithProgress ignoreJob = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
@@ -273,6 +293,11 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
return doImport;
}
+ private String getRootProjectName() {
+ MavenProjectInfo rootProject = page.getRootProject();
+ return rootProject != null ? importConfiguration.getProjectName(rootProject.getModel()) : null;
+ }
+
@Override
public boolean canFinish() {
IWizardPage currentPage = getContainer().getCurrentPage();
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
index 90bac74c..5bdf86fe 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
@@ -114,6 +114,10 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
private Button btnDeselectTree;
+ protected boolean createDefaultWorkingSet = true;
+
+ private Button createWorkingSet;
+
protected MavenImportWizardPage(ProjectImportConfiguration importConfiguration, List<IWorkingSet> workingSets) {
super("MavenProjectImportWizardPage", importConfiguration); //$NON-NLS-1$
this.workingSets = workingSets;
@@ -377,6 +381,16 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
this.workingSetGroup = new WorkingSetGroup(composite, workingSets, getShell());
+ createWorkingSet = new Button(composite, SWT.CHECK);
+ createWorkingSet.setText(NLS.bind(Messages.MavenImportWizardPage_createWorkingSet, "")); //$NON-NLS-2$
+ createWorkingSet.setSelection(true);
+ createWorkingSet.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
+ createWorkingSet.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ createDefaultWorkingSet = ((Button) e.widget).getSelection();
+ }
+ });
+
createAdvancedSettings(composite, new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1));
resolverConfigurationComponent.template.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent arg0) {
@@ -436,6 +450,16 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
loadingErrorMessage = null;
LifecycleMappingConfiguration config = ((MavenImportWizard) getWizard()).getMappingConfiguration();
+ // update name of working set
+ MavenProjectInfo rootProject = getRootProject();
+ if(rootProject != null) {
+ createWorkingSet.setText(NLS.bind(Messages.MavenImportWizardPage_createWorkingSet, getImportConfiguration()
+ .getProjectName(rootProject.getModel())));
+ createWorkingSet.pack();
+ } else {
+ createWorkingSet.setText(NLS.bind(Messages.MavenImportWizardPage_createWorkingSet, ""));
+ }
+
//mkleint: XXX this sort of error handling is rather unfortunate
List<Throwable> errors = new ArrayList<Throwable>(projectScanner.getErrors());
@@ -470,7 +494,7 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
msg = e.getMessage();
log.error(msg, e);
} else {
- msg = "Scanning error " + projectScanner.getDescription() + "; " + e.toString(); //$NON-NLS-2$
+ msg = "Scanning error " + projectScanner.getDescription() + "; " + e.toString(); //$NON-NLS-1$//$NON-NLS-2$
log.error(msg, e);
}
projectTreeViewer.setInput(null);
@@ -560,6 +584,10 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
return false;
}
+ boolean shouldCreateWorkingSetForRoot() {
+ return createDefaultWorkingSet;
+ }
+
protected AbstractProjectScanner<MavenProjectInfo> getProjectScanner() {
File root = workspaceRoot.getLocation().toFile();
MavenModelManager modelManager = MavenPlugin.getMavenModelManager();
@@ -597,6 +625,11 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
return checkedProjects;
}
+ public MavenProjectInfo getRootProject() {
+ Object[] elements = projectTreeViewer.getExpandedElements();
+ return elements == null || elements.length == 0 ? null : (MavenProjectInfo) elements[0];
+ }
+
/**
* @param info
* @return
@@ -736,10 +769,10 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
if(element instanceof MavenProjectInfo) {
MavenProjectInfo info = (MavenProjectInfo) element;
StyledString ss = new StyledString();
- ss.append(info.getLabel() + " ");
+ ss.append(info.getLabel() + " "); //$NON-NLS-1$
ss.append(getId(info), StyledString.DECORATIONS_STYLER);
if(!info.getProfiles().isEmpty()) {
- ss.append(" - " + info.getProfiles(), StyledString.QUALIFIER_STYLER);
+ ss.append(" - " + info.getProfiles(), StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
}
return ss;
}

Back to the top