[jbosstools-commits] JBoss Tools SVN: r43929 - in trunk: maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks and 1 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Sep 21 10:04:45 EDT 2012
Author: fbricon
Date: 2012-09-21 10:04:45 -0400 (Fri, 21 Sep 2012)
New Revision: 43929
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java
Log:
JBIDE-12472 : Use JDF stacks to manage different archetype/runtime versions
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java 2012-09-21 13:53:50 UTC (rev 43928)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java 2012-09-21 14:04:45 UTC (rev 43929)
@@ -3,6 +3,7 @@
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -74,8 +75,8 @@
protected Text projectSize;
protected WizardContext wizardContext;
protected TableViewer tableViewer;
- private List<ProjectFix> fixes = new ArrayList<ProjectFix>();
- private ArrayList<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
+ protected List<ProjectFix> fixes = new ArrayList<ProjectFix>();
+ protected ArrayList<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
private Image checkboxOn;
private Image checkboxOff;
private Link link;
@@ -92,36 +93,6 @@
checkboxOff = RuntimeUIActivator.imageDescriptorFromPlugin(RuntimeUIActivator.PLUGIN_ID, "/icons/xpl/incomplete_tsk.gif").createImage();
}
- protected void setDescriptionArea(Composite composite) {
- Label descriptionLabel = new Label(composite,SWT.NONE);
- descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
- GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
- gd.horizontalSpan = 2;
- descriptionLabel.setLayoutData(gd);
- descriptionText = new Text(composite, SWT.H_SCROLL | SWT.V_SCROLL
- | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- GC gc = new GC(composite.getParent());
- gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
- .getFontMetrics(), 6);
- gc.dispose();
- gd.horizontalSpan = 2;
- gd.widthHint = 250;
- descriptionText.setLayoutData(gd);
- }
-
- protected void setSelectionArea(Composite composite) {
- projectSizeLabel = new Label(composite,SWT.NULL);
- projectSizeLabel.setText(Messages.NewProjectExamplesWizardPage_Project_size);
- projectSize = new Text(composite,SWT.READ_ONLY);
- projectSize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- Label label = new Label(composite, SWT.NONE);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- gd.horizontalSpan = 2;
- label.setLayoutData(gd);
- }
-
protected void setTitleAndDescription(ProjectExample projectExample) {
setTitle( "Requirements" );
setDescription( "Project Example Requirements" );
@@ -209,6 +180,8 @@
gd.horizontalSpan=2;
link.setLayoutData(gd);
+ setAdditionalControls(composite);
+
setPageComplete(true);
setControl(composite);
if (projectExample != null) {
@@ -217,6 +190,39 @@
}
+ protected void setDescriptionArea(Composite composite) {
+ Label descriptionLabel = new Label(composite,SWT.NONE);
+ descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
+ GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
+ gd.horizontalSpan = 2;
+ descriptionLabel.setLayoutData(gd);
+ descriptionText = new Text(composite, SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
+ gd = new GridData(SWT.FILL, SWT.FILL, false, false);
+ GC gc = new GC(composite.getParent());
+ gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
+ .getFontMetrics(), 6);
+ gc.dispose();
+ gd.horizontalSpan = 2;
+ gd.widthHint = 250;
+ descriptionText.setLayoutData(gd);
+ }
+
+ protected void setSelectionArea(Composite composite) {
+ projectSizeLabel = new Label(composite,SWT.NULL);
+ projectSizeLabel.setText(Messages.NewProjectExamplesWizardPage_Project_size);
+ projectSize = new Text(composite,SWT.READ_ONLY);
+ projectSize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label label = new Label(composite, SWT.NONE);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gd.horizontalSpan = 2;
+ label.setLayoutData(gd);
+ }
+
+ protected void setAdditionalControls(Composite composite) {
+ }
+
private void createButtons(Composite parent, final TableViewer viewer) {
Composite buttonComposite = new Composite(parent, SWT.NONE);
buttonComposite.setLayout(new GridLayout(1,false));
@@ -298,8 +304,8 @@
public void widgetSelected(SelectionEvent e) {
ProjectFix fix = getSelectedProjectFix();
if (fix != null) {
- DownloadRuntime runtime = getDownloadRuntime(fix);
- DownloadRuntimeDialog dialog = new DownloadRuntimeDialog(getShell(), runtime);
+ List<DownloadRuntime> runtimes = getDownloadRuntimes(fix);
+ DownloadRuntimeDialog dialog = new DownloadRuntimeDialog(getShell(), runtimes);
dialog.open();
refreshFixes();
}
@@ -347,10 +353,18 @@
}
if (ProjectFix.WTP_RUNTIME.equals(fixType)
|| ProjectFix.SEAM_RUNTIME.equals(fixType)) {
- DownloadRuntime downloadRuntime = getDownloadRuntime(fix);
- downloadAndInstall.setEnabled(downloadRuntime != null);
- if (downloadRuntime != null) {
- downloadAndInstall.setToolTipText("Download and install " + downloadRuntime.getName());
+ List<DownloadRuntime> downloadRuntimes = getDownloadRuntimes(fix);
+ if (downloadRuntimes != null && !downloadRuntimes.isEmpty()) {
+ StringBuilder tooltip = new StringBuilder("Download and install ");
+ if (downloadRuntimes.size() > 1) {
+ tooltip.append("a runtime");
+ } else {
+ tooltip.append(downloadRuntimes.get(0).getName());
+ }
+ downloadAndInstall.setToolTipText(tooltip.toString());
+ downloadAndInstall.setEnabled(true);
+ } else {
+ downloadAndInstall.setEnabled(false);
}
install.setEnabled(true);
install.setToolTipText("JBoss Runtime Detection");
@@ -378,10 +392,11 @@
return null;
}
- private DownloadRuntime getDownloadRuntime(ProjectFix fix) {
+ protected List<DownloadRuntime> getDownloadRuntimes(ProjectFix fix) {
final String downloadId = fix.getProperties().get(ProjectFix.DOWNLOAD_ID);
if (downloadId != null) {
- return RuntimeCoreActivator.getDefault().getDownloadRuntimes().get(downloadId);
+ DownloadRuntime dr = RuntimeCoreActivator.getDefault().getDownloadRuntimes().get(downloadId);
+ return Collections.singletonList(dr);
}
return null;
}
@@ -589,7 +604,10 @@
if (longDescription == null) {
longDescription = "";
}
- descriptionText.setText(longDescription);
+ if (!longDescription.equals(descriptionText.getText())) {
+ //only change text if necessary to avoid flickering
+ descriptionText.setText(longDescription);
+ }
}
}
Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java 2012-09-21 13:53:50 UTC (rev 43928)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java 2012-09-21 14:04:45 UTC (rev 43929)
@@ -9,47 +9,76 @@
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
package org.jboss.tools.maven.project.examples.stacks;
+
import static org.jboss.tools.project.examples.model.ProjectExampleUtil.getProjectExamplesFile;
import java.io.File;
import java.io.FileInputStream;
-import java.net.MalformedURLException;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
+import java.util.Properties;
+import org.codehaus.plexus.util.IOUtil;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.jdf.stacks.client.StacksClient;
+import org.jboss.jdf.stacks.client.StacksClientConfiguration;
import org.jboss.jdf.stacks.model.Stacks;
import org.jboss.jdf.stacks.parser.Parser;
+import org.jboss.tools.maven.project.examples.MavenProjectExamplesActivator;
-
public class StacksManager {
private static final String STACKS_URL;
-
+
static {
- String defaultUrl = "http://raw.github.com/jboss-jdf/jdf-stack/1.0.0.CR1/stacks.yaml"; //$NON-NLS-1$
- STACKS_URL = System.getProperty("org.jboss.examples.stacks.url", defaultUrl); //$NON-NLS-1$
+ String defaultUrl = getStacksUrlFromJar(); //$NON-NLS-1$
+ STACKS_URL = System.getProperty(
+ "org.jboss.examples.stacks.url", defaultUrl); //$NON-NLS-1$
}
-
- public Stacks getStacks(IProgressMonitor monitor) throws MalformedURLException {
+
+ public Stacks getStacks(IProgressMonitor monitor) {
Stacks stacks = null;
- File f = getProjectExamplesFile(new URL(STACKS_URL), "stacks", "yaml", monitor); //$NON-NLS-1$ //$NON-NLS-2$
- if (f != null && f.exists()) {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(f);
- Parser p = new Parser();
- stacks = p.parse(fis);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
+ try {
+ File f = getProjectExamplesFile(new URL(STACKS_URL),
+ "stacks", "yaml", monitor);//$NON-NLS-1$ //$NON-NLS-2$
+ if (f != null && f.exists()) {
+ FileInputStream fis = null;
try {
- fis.close();
- } catch(Exception e) {
- //ignore
+ fis = new FileInputStream(f);
+ Parser p = new Parser();
+ stacks = p.parse(fis);
+ } finally {
+ IOUtil.close(fis);
}
}
+ } catch (Exception e) {
+ MavenProjectExamplesActivator.log(e,
+ "Can't access or parse " + STACKS_URL //$NON-NLS-1$
+ + ", falling back on default Stacks Client values"); //$NON-NLS-1$
+ StacksClient client = new StacksClient();
+ stacks = client.getStacks();
}
+
return stacks;
-
+
}
+
+ private static String getStacksUrlFromJar() {
+ InputStream is = null;
+ try {
+ is = Stacks.class.getResourceAsStream("config.properties");
+ Properties p = new Properties();
+ p.load(is);
+ return p.getProperty(StacksClientConfiguration.REPO_PROPERTY);
+ } catch (IOException ioe) {
+ System.err.println("Can't read stacks url from the stacks-client.jar");
+ ioe.printStackTrace();
+ } finally {
+ IOUtil.close(is);
+ }
+ return null;
+ }
+
+
}
Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java 2012-09-21 13:53:50 UTC (rev 43928)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java 2012-09-21 14:04:45 UTC (rev 43929)
@@ -13,7 +13,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.jboss.jdf.stacks.model.Archetype;
@@ -23,11 +25,26 @@
import org.jboss.tools.project.examples.model.ArchetypeModel;
public class StacksUtil {
- /*
+
+ private static final Map<String, String> RUNTIMES_MAP;
+
+ static {
+
+ Map<String, String> serverIdMap = new HashMap<String, String>();
+
+ serverIdMap.put("org.jboss.ide.eclipse.as.runtime.eap.60","jbosseap6runtime");
+ serverIdMap.put("org.jboss.ide.eclipse.as.runtime.71","jboss-as711runtime");
+ //serverIdMap.put("org.jboss.ide.eclipse.as.runtime.71","jboss-as710runtime");
+ serverIdMap.put("org.jboss.ide.eclipse.as.runtime.70","jboss-as702runtime-web");
+ //serverIdMap.put("org.jboss.ide.eclipse.as.runtime.70","jboss-as702runtime-full");
+
+ RUNTIMES_MAP = Collections.unmodifiableMap(serverIdMap);
+ }
+
public static final String EAP_TYPE = "EAP";
public static final String AS_TYPE = "AS";
- */
+
private StacksUtil() {
// no need for public constructor
}
@@ -86,12 +103,55 @@
return Collections.unmodifiableList(runtimes);
}
+ public static Runtime getRuntime(Stacks fromStacks, String runtimeId) {
+ if (fromStacks == null || runtimeId == null) {
+ return null;
+ }
+
+ for (Runtime runtime : fromStacks.getAvailableRuntimes()) {
+ if (runtimeId.equals(runtime.getId())) {
+ return runtime;
+ }
+ }
+ return null;
+ }
- /*
- public static List<Runtime> getCompatibleRuntimes(Archetype archetype, Stacks fromStacks) {
+ public static Runtime getRuntimeFromWtp(Stacks fromStacks, String wtpRuntimeId) {
+ if (fromStacks == null || wtpRuntimeId == null) {
+ return null;
+ }
+ for (Runtime runtime : fromStacks.getAvailableRuntimes()) {
+ Properties p = runtime.getLabels();
+ if (p != null && wtpRuntimeId.equals(p.get("wtp-runtime-id"))) {
+ return runtime;
+ }
+ }
+ //Fall back on hard coded map
+ String stacksRuntimeId = RUNTIMES_MAP.get(wtpRuntimeId);
+
+ return getRuntime(fromStacks, stacksRuntimeId);
+ }
+
+
+
+ public static Runtime getRuntimeFromWtpId(Stacks fromStacks, String wtpRuntimeId) {
+ if (fromStacks == null || wtpRuntimeId == null) {
+ return null;
+ }
+ for (Runtime runtime : fromStacks.getAvailableRuntimes()) {
+ Properties p = runtime.getLabels();
+ if (p != null && wtpRuntimeId.equals(p.get("wtp-runtime-id"))) {
+ return runtime;
+ }
+ }
+ //Fall back on hard coded map
+ String stacksRuntimeId = RUNTIMES_MAP.get(wtpRuntimeId);
+ return getRuntime(fromStacks, stacksRuntimeId);
+ }
+
+ public static List<Runtime> getCompatibleServerRuntimes(Archetype archetype, Stacks fromStacks) {
return getCompatibleRuntimes(archetype, fromStacks, AS_TYPE, EAP_TYPE);
}
- */
/**
* Returns an unmodifiable {@link List} of compatible {@link ArchetypeVersion} of an {@link Archetype} for a given {@link Runtime}.
@@ -133,11 +193,9 @@
return versions != null && versions.contains(archetypeVersion);
}
- /*
public static boolean isEnterprise(Runtime runtime) {
return EAP_TYPE.equals(getRuntimeType(runtime));
}
- */
public static String getRuntimeType(Runtime runtime) {
if (runtime == null) {
@@ -145,7 +203,7 @@
}
Properties p = runtime.getLabels();
- return (String)p.get("runtimeType");
+ return (String)p.get("runtime-type");
}
public static ArchetypeModel createArchetypeModel(ArchetypeModel archetypeModel, ArchetypeVersion archetypeVersion) throws CloneNotSupportedException {
Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java 2012-09-21 13:53:50 UTC (rev 43928)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java 2012-09-21 14:04:45 UTC (rev 43929)
@@ -13,12 +13,9 @@
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Pattern;
import org.apache.maven.model.Model;
@@ -27,13 +24,11 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.ui.internal.wizards.MavenProjectWizardLocationPage;
import org.eclipse.osgi.util.NLS;
@@ -46,21 +41,12 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkingSet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-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.IRuntimeLifecycleListener;
-import org.eclipse.wst.server.core.ServerCore;
-import org.eclipse.wst.server.core.internal.facets.FacetUtil;
-import org.jboss.ide.eclipse.as.core.util.RuntimeUtils;
import org.jboss.tools.maven.project.examples.MavenProjectExamplesActivator;
import org.jboss.tools.maven.project.examples.Messages;
-import org.jboss.tools.maven.project.examples.utils.MavenArtifactHelper;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.ArchetypeModel;
import org.jboss.tools.project.examples.model.ProjectExample;
@@ -77,17 +63,11 @@
public class ArchetypeExamplesWizardFirstPage extends MavenProjectWizardLocationPage implements IProjectExamplesWizardPage {
private static final String WORKING_SETS = "workingSets"; //$NON-NLS-1$
- private static final String TARGET_RUNTIME = "targetRuntime"; //$NON-NLS-1$
private Label projectNameLabel;
private Combo projectNameCombo;
private Label packageLabel;
private Combo packageCombo;
- private Combo serverTargetCombo;
- private Map<String, IRuntime> serverRuntimes;
- private MissingRepositoryWarningComponent warningComponent;
private boolean initialized;
- private IStatus enterpriseRepoStatus;
- private ProjectExample projectDescription;
private ProjectExample projectExample;
private WizardContext context;
@@ -104,7 +84,7 @@
ProjectImportConfiguration configuration,
ProjectExample projectDescription, List<IWorkingSet> workingSet) {
super(configuration, projectDescription.getShortDescription(),Messages.ArchetypeExamplesWizardFirstPage_Title, workingSet);
- this.projectDescription = projectDescription;
+ this.projectExample = projectDescription;
setPageComplete(false);
}
@@ -116,35 +96,6 @@
@Override
protected void createAdditionalControls(Composite container) {
- listener = new IRuntimeLifecycleListener() {
-
- @Override
- public void runtimeRemoved(IRuntime runtime) {
- runInUIThread();
- }
-
- @Override
- public void runtimeChanged(IRuntime runtime) {
- runInUIThread();
- }
-
- @Override
- public void runtimeAdded(IRuntime runtime) {
- runInUIThread();
- }
-
- private void runInUIThread() {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- configureRuntimeCombo();
- }
- });
- }
-
- };
- ServerCore.addRuntimeLifecycleListener(listener);
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
projectNameLabel = new Label(container, SWT.NONE);
projectNameLabel.setText(Messages.ArchetypeExamplesWizardFirstPage_ProjectName_Label);
@@ -177,81 +128,15 @@
}
});
- createServerTargetComposite(container);
+ //createServerTargetComposite(container);
Label emptyLabel = new Label(container, SWT.NONE);
emptyLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,
3, 1));
- /*
- projectNameCombo.setText(archetypeModel.getArtifactId());
- packageCombo.setText(archetypeModel.getJavaPackage());
- */
}
- @Override
- protected void createAdvancedSettings(Composite composite, GridData gridData) {
- warningComponent = new MissingRepositoryWarningComponent(composite, false);
- }
-
- protected void createServerTargetComposite(Composite parent) {
- Label serverTargetLabel = new Label(parent, SWT.NONE);
- serverTargetLabel.setText(Messages.ArchetypeExamplesWizardFirstPage_Target_Runtime_Label);
-
- GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
- serverTargetCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- serverTargetCombo.setLayoutData(gridData);
- serverTargetCombo.add(Messages.ArchetypeExamplesWizardFirstPage_No_TargetRuntime);
- serverTargetCombo.addModifyListener(new ModifyListener() {
-
- @Override
- public void modifyText(ModifyEvent e) {
- if (isCurrentPage()) {
- context.setProperty(MavenProjectConstants.ENTERPRISE_TARGET, isEnterpriseTargetRuntime());
- }
- validateEnterpriseRepo();
- }
- });
-
- configureRuntimeCombo();
-
- }
-
- protected void configureRuntimeCombo() {
- if (serverTargetCombo == null || serverTargetCombo.isDisposed()) {
- return;
- }
- //TODO read facet version from project example metadata
- IProjectFacetVersion facetVersion;
- try {
- facetVersion = ProjectFacetsManager.getProjectFacet(
- IJ2EEFacetConstants.DYNAMIC_WEB).getLatestVersion();
- } catch (CoreException e) {
- MavenProjectExamplesActivator.log(e);
- return;
- }
-
- int i =0, selectedRuntimeIdx = 0;
- String lastUsedRuntime = dialogSettings.get(TARGET_RUNTIME);
-
- serverRuntimes = getServerRuntimes(facetVersion);
- serverTargetCombo.removeAll();
- serverTargetCombo.add(Messages.ArchetypeExamplesWizardFirstPage_No_TargetRuntime);
- for (Map.Entry<String, IRuntime> entry : serverRuntimes.entrySet()) {
- serverTargetCombo.add(entry.getKey());
- ++i;
- IRuntime runtime = entry.getValue();
- if (lastUsedRuntime != null && lastUsedRuntime.equals(runtime.getId())) {
- selectedRuntimeIdx = i;
- }
- }
-
- if (selectedRuntimeIdx > 0) {
- serverTargetCombo.select(selectedRuntimeIdx);
- }
- }
-
protected void validate() {
if (!initialized) {
return;
@@ -275,7 +160,7 @@
setMessage(null);
setPageComplete(errorMessage == null);
- validateEnterpriseRepo();
+ //validateEnterpriseRepo();
}
@@ -319,34 +204,6 @@
return (projectNameCombo == null) ? null : projectNameCombo.getText();
}
- protected void validateEnterpriseRepo() {
- if (warningComponent != null) {
- boolean isWarningLinkVisible = false;
- if (isEnterpriseTargetRuntime()) {
- if (enterpriseRepoStatus == null) {
- enterpriseRepoStatus = MavenArtifactHelper.checkEnterpriseRequirementsAvailable(projectExample);
- }
- isWarningLinkVisible = !enterpriseRepoStatus.isOK();
- if (isWarningLinkVisible) {
- warningComponent.setLinkText(enterpriseRepoStatus.getMessage());
- //warninglink.setText(enterpriseRepoStatus.getMessage());
- //warningComponent.getParent().layout(true, true);
- }
- }
- warningComponent.setVisible(isWarningLinkVisible);
- }
- }
-
-
- public boolean isEnterpriseTargetRuntime() {
- if (serverTargetCombo == null)
- return false;
- String serverId = serverTargetCombo.getText();
- IRuntime runtime = serverRuntimes.get(serverId);
- return (runtime != null && RuntimeUtils.isEAP(runtime));
- }
-
-
public void setVisible(boolean visible) {
super.setVisible(visible);
@@ -362,7 +219,6 @@
if (projectExample == null || projectNameCombo == null) {
return;
}
- projectDescription = projectExample;
if (archetypeModel != null) {
String projectName = archetypeModel.getArtifactId();
if (StringUtils.isNotBlank(projectName)) {
@@ -380,33 +236,11 @@
packageCombo.setText(packageName);
}
}
- //Force setting of enterprise value
- context.setProperty(MavenProjectConstants.ENTERPRISE_TARGET, isEnterpriseTargetRuntime());
initialized = true;
validate();
}
- protected Map<String, IRuntime> getServerRuntimes(
- IProjectFacetVersion facetVersion) {
- Set<org.eclipse.wst.common.project.facet.core.runtime.IRuntime> runtimesSet;
- if (facetVersion == null) {
- runtimesSet =RuntimeManager.getRuntimes();
- } else {
- runtimesSet = RuntimeManager.getRuntimes(Collections.singleton(facetVersion));
- }
-
- Map<String, IRuntime> runtimesMap = new LinkedHashMap<String, IRuntime>();
- for (org.eclipse.wst.common.project.facet.core.runtime.IRuntime r : runtimesSet) {
- IRuntime serverRuntime = FacetUtil.getRuntime(r);
- if (serverRuntime != null) {
- runtimesMap.put(r.getLocalizedName(), serverRuntime);
- }
- }
- return runtimesMap;
- }
-
-
public void setUseDefaultWorkspaceLocation(boolean value) {
try {
Field field = this.getClass().getSuperclass().getDeclaredField("useDefaultWorkspaceLocationButton"); //$NON-NLS-1$
@@ -479,23 +313,8 @@
}
return file.canWrite();
}
+
@Override
- public void dispose() {
- if (dialogSettings != null && serverRuntimes != null && serverTargetCombo != null) {
- IRuntime lastUsedRuntime = serverRuntimes.get(serverTargetCombo.getText());
- if (lastUsedRuntime != null) {
- dialogSettings.put(TARGET_RUNTIME, lastUsedRuntime.getId());
- }
- }
- if (listener != null) {
- ServerCore.removeRuntimeLifecycleListener(listener);
- listener = null;
- }
- super.dispose();
- }
-
-
- @Override
public boolean finishPage() {
return true;
}
@@ -601,7 +420,6 @@
}
}
-
@Override
public void setWizardContext(WizardContext context) {
this.context = context;
Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2012-09-21 13:53:50 UTC (rev 43928)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2012-09-21 14:04:45 UTC (rev 43929)
@@ -149,7 +149,13 @@
if (resolverConfigurationComponent != null) {
resolverConfigurationComponent.setExpanded(!resolverConfigurationComponent.getResolverConfiguration().getActiveProfileList().isEmpty());
}
- initialized = true;
+ if (propertiesTable != null) {
+ initialized = true;
+ }
+
+ Object enterpriseValue = context.getProperty(MavenProjectConstants.ENTERPRISE_TARGET);
+ Boolean enterprise = (enterpriseValue instanceof Boolean)?(Boolean)enterpriseValue:Boolean.FALSE;
+ updateArchetypeProperty(MavenProjectConstants.ENTERPRISE_TARGET, enterprise.toString());
}
@Override
@@ -284,7 +290,7 @@
checkEnterpriseProperty();
super.validate();
}
-
+
private void checkEnterpriseProperty() {
if (warningComponent == null) {
//Not initialized yet
@@ -337,7 +343,6 @@
MavenProjectExamplesActivator.log("Cannot import maven archetype");
return false;
}
- IPath locationPath = simplePage.getLocationPath();
final ProjectImportConfiguration configuration = getImportConfiguration();
String projectName = configuration.getProjectName(model);
propertiesMap.put(ProjectExamplesActivator.PROPERTY_PROJECT_NAME, projectName);
@@ -479,12 +484,18 @@
setPackageName(packageName);
} else if (MavenProjectConstants.ENTERPRISE_TARGET.equals(key)) {
//Make sure it's a boolean :
- Boolean enterprise = Boolean.parseBoolean(value.toString());
- updateArchetypeProperty("enterprise", enterprise.toString());
+ Boolean enterprise = Boolean.FALSE;
+ if (value instanceof Boolean) {
+ enterprise = (Boolean)value;
+ }
+ updateArchetypeProperty(MavenProjectConstants.ENTERPRISE_TARGET, enterprise.toString());
} else if (MavenProjectConstants.ARCHETYPE_MODEL.equals(key)) {
if (value instanceof ArchetypeModel) {
archetypeModel = (ArchetypeModel)value;
- initializeArchetype();
+ if (getControl() != null) {
+ //reset control contents with archetype data
+ initializeArchetype();
+ }
}
}
}
Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java 2012-09-21 13:53:50 UTC (rev 43928)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java 2012-09-21 14:04:45 UTC (rev 43929)
@@ -13,46 +13,91 @@
import static org.jboss.tools.maven.project.examples.stacks.StacksUtil.createArchetypeModel;
import static org.jboss.tools.maven.project.examples.stacks.StacksUtil.getArchetype;
-import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.DialogSettings;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
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.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+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.IRuntimeLifecycleListener;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.internal.facets.FacetUtil;
+import org.jboss.ide.eclipse.as.core.util.RuntimeUtils;
import org.jboss.jdf.stacks.model.ArchetypeVersion;
+import org.jboss.jdf.stacks.model.Runtime;
import org.jboss.jdf.stacks.model.Stacks;
+import org.jboss.tools.maven.project.examples.MavenProjectExamplesActivator;
+import org.jboss.tools.maven.project.examples.Messages;
import org.jboss.tools.maven.project.examples.stacks.StacksManager;
import org.jboss.tools.maven.project.examples.stacks.StacksUtil;
+import org.jboss.tools.maven.project.examples.utils.MavenArtifactHelper;
import org.jboss.tools.project.examples.model.ArchetypeModel;
import org.jboss.tools.project.examples.model.ProjectExample;
+import org.jboss.tools.project.examples.model.ProjectFix;
import org.jboss.tools.project.examples.wizard.NewProjectExamplesRequirementsPage;
+import org.jboss.tools.runtime.core.model.DownloadRuntime;
public class NewProjectExamplesStacksRequirementsPage extends NewProjectExamplesRequirementsPage {
private static final String PAGE_NAME = "org.jboss.tools.project.examples.stacksrequirements"; //$NON-NLS-1$
- org.jboss.jdf.stacks.model.Archetype stacksArchetype;
+ private static final String TARGET_RUNTIME = "targetRuntime"; //$NON-NLS-1$
+ private MissingRepositoryWarningComponent warningComponent;
+
+ private IStatus enterpriseRepoStatus;
+
+ private org.jboss.jdf.stacks.model.Archetype stacksArchetype;
+
private ArchetypeVersion version;
private Button useBlankArchetype;
private Stacks stacks;
-
+
+ private IRuntimeLifecycleListener listener;
+
+ private Combo serverTargetCombo;
+
+ private Map<String, IRuntime> serverRuntimes;
+
public NewProjectExamplesStacksRequirementsPage() {
this(null);
- try {
- stacks = new StacksManager().getStacks(new NullProgressMonitor());
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
+ stacks = new StacksManager().getStacks(new NullProgressMonitor());
}
public NewProjectExamplesStacksRequirementsPage(ProjectExample projectExample) {
super(PAGE_NAME, projectExample);
+ fieldsWithHistory = new HashMap<String, List<Combo>>();
+ initDialogSettings();
}
@Override
@@ -60,10 +105,6 @@
return "mavenArchetype";
}
- @Override
- protected void setDescriptionArea(Composite composite) {
- super.setDescriptionArea(composite);
- }
@Override
public void setProjectExample(ProjectExample projectExample) {
@@ -72,6 +113,16 @@
String stacksId = projectExample.getStacksId();
stacksArchetype = getArchetype(stacksId, stacks);
setArchetypeVersion();
+ boolean hasBlank = stacksArchetype!=null && null != stacksArchetype.getBlank();
+ if (useBlankArchetype != null) {
+ useBlankArchetype.setVisible(hasBlank);
+ ((GridData) useBlankArchetype.getLayoutData()).exclude = !hasBlank;
+ useBlankArchetype.getParent().layout(true, true);
+ }
+
+ wizardContext.setProperty(MavenProjectConstants.ENTERPRISE_TARGET, isEnterpriseTargetRuntime());
+
+ validateEnterpriseRepo();
}
}
@@ -81,15 +132,39 @@
}
org.jboss.jdf.stacks.model.Archetype a;
-
+
if (useBlankArchetype != null && useBlankArchetype.getSelection()) {
a = stacksArchetype.getBlank();
+
} else {
a = stacksArchetype;
}
- version = StacksUtil.getDefaultArchetypeVersion(a, stacks);
+ version = null;
+ //get selected runtime from combo
+ if (serverTargetCombo != null && !serverTargetCombo.isDisposed()) {
+ String wtpServerId = serverTargetCombo.getText();
+ IRuntime wtpRuntime = serverRuntimes.get(wtpServerId);
+ if (wtpRuntime != null && wtpRuntime.getRuntimeType() != null) {
+ String wtpRuntimeId = wtpRuntime.getRuntimeType().getId();
+ //System.err.println(wtpRuntimeId);
+ Runtime stacksRuntime = StacksUtil.getRuntimeFromWtpId(stacks, wtpRuntimeId );
+ if (stacksRuntime != null) {
+ List<ArchetypeVersion> compatibleVersions = StacksUtil.getCompatibleArchetypeVersions(a, stacksRuntime);
+ if (compatibleVersions != null && !compatibleVersions.isEmpty()) {
+ version = compatibleVersions.get(0);
+ }
+ } else {
+ //No stacks runtime matching that server id
+ }
+ }
+ }
+ //contains wtp runtime id
+ if (version == null) {
+ version = StacksUtil.getDefaultArchetypeVersion(a, stacks);
+ }
+
StringBuilder description = new StringBuilder(version.getArchetype().getDescription());
description.append("\r\n").append("\r\n")
.append("Project based on the ")
@@ -115,11 +190,14 @@
@Override
protected void setSelectionArea(Composite composite) {
+
useBlankArchetype = new Button(composite, SWT.CHECK);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- gd.verticalAlignment = SWT.BOTTOM;
+ GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, true, false, 2, 1);
+ gd.verticalAlignment = SWT.TOP;
+
useBlankArchetype.setLayoutData(gd);
- useBlankArchetype.setText("Create an empty project");
+
+ useBlankArchetype.setText("Create a blank project");
useBlankArchetype.addSelectionListener(new SelectionListener() {
@Override
@@ -132,15 +210,303 @@
widgetSelected(e);
}
});
+
+ listener = new IRuntimeLifecycleListener() {
+
+ @Override
+ public void runtimeRemoved(IRuntime runtime) {
+ runInUIThread();
+ }
+
+ @Override
+ public void runtimeChanged(IRuntime runtime) {
+ runInUIThread();
+ }
+
+ @Override
+ public void runtimeAdded(IRuntime runtime) {
+ runInUIThread();
+ }
+
+ private void runInUIThread() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ configureRuntimeCombo();
+ }
+ });
+ }
+
+ };
+ ServerCore.addRuntimeLifecycleListener(listener);
+
+ createServerTargetComposite(composite);
+
}
@Override
+ protected void setAdditionalControls(Composite composite) {
+ warningComponent = new MissingRepositoryWarningComponent(composite, false);
+ //Yuck!! Necessary evil in order to have the warning component fitting in
+ //the dialog page area, once it's set as visible.
+ //Anybody who can find a proper solution will have my eternal gratitude
+ GridDataFactory.fillDefaults().hint(625, 45).applyTo(warningComponent);
+ }
+
+ @Override
public void setVisible(boolean visible) {
if (visible) {
- useBlankArchetype.setVisible(stacksArchetype != null
- && stacksArchetype.getBlank() != null );
+ if (useBlankArchetype != null) {
+ useBlankArchetype.getParent().layout(true);
+ }
+
+ if(!isHistoryLoaded) {
+ loadInputHistory();
+ isHistoryLoaded = true;
+ } else {
+ saveInputHistory();
+ }
+
+ wizardContext.setProperty(MavenProjectConstants.ENTERPRISE_TARGET, isEnterpriseTargetRuntime());
}
super.setVisible(visible);
}
+ protected void createServerTargetComposite(Composite composite) {
+
+ Composite parent = new Composite(composite, SWT.NONE);
+ parent.setLayout(new GridLayout(2, false));
+ parent.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
+
+ Label serverTargetLabel = new Label(parent, SWT.NONE);
+ serverTargetLabel.setText(Messages.ArchetypeExamplesWizardFirstPage_Target_Runtime_Label);
+
+ GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
+ serverTargetCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
+ serverTargetCombo.setLayoutData(gridData);
+ serverTargetCombo.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (isCurrentPage()) {
+ setArchetypeVersion();
+ wizardContext.setProperty(MavenProjectConstants.ENTERPRISE_TARGET, isEnterpriseTargetRuntime());
+ }
+ validateEnterpriseRepo();
+ }
+ });
+
+ configureRuntimeCombo();
+
+ }
+
+ public boolean isEnterpriseTargetRuntime() {
+ if (serverTargetCombo == null)
+ return false;
+ //server runtime names are unique so name == server id
+ String serverId = serverTargetCombo.getText();
+ IRuntime runtime = serverRuntimes.get(serverId);
+ return (runtime != null && RuntimeUtils.isEAP(runtime));
+ }
+
+
+ protected void configureRuntimeCombo() {
+ if (serverTargetCombo == null || serverTargetCombo.isDisposed()) {
+ return;
+ }
+ //TODO read facet version from project example metadata
+ IProjectFacetVersion facetVersion;
+ try {
+ facetVersion = ProjectFacetsManager.getProjectFacet(
+ IJ2EEFacetConstants.DYNAMIC_WEB).getLatestVersion();
+ } catch (CoreException e) {
+ MavenProjectExamplesActivator.log(e);
+ return;
+ }
+
+ int i =0, selectedRuntimeIdx = 0;
+ String lastUsedRuntime = dialogSettings.get(TARGET_RUNTIME);
+
+ serverRuntimes = getServerRuntimes(facetVersion);
+ serverTargetCombo.removeAll();
+ serverTargetCombo.add(Messages.ArchetypeExamplesWizardFirstPage_No_TargetRuntime);
+ for (Map.Entry<String, IRuntime> entry : serverRuntimes.entrySet()) {
+ serverTargetCombo.add(entry.getKey());
+ ++i;
+ IRuntime runtime = entry.getValue();
+ if (lastUsedRuntime != null && lastUsedRuntime.equals(runtime.getId())) {
+ selectedRuntimeIdx = i;
+ }
+ }
+
+ if (selectedRuntimeIdx > 0) {
+ serverTargetCombo.select(selectedRuntimeIdx);
+ }
+ }
+
+ protected List<DownloadRuntime> getDownloadRuntimes(ProjectFix fix) {
+ if (ProjectFix.WTP_RUNTIME.equals(fix.getType())) {
+ List<Runtime> stacksRuntimes = StacksUtil.getCompatibleServerRuntimes(stacksArchetype, stacks);
+ if (stacksRuntimes != null && !stacksRuntimes.isEmpty()) {
+ List<DownloadRuntime> downloadableRuntimes = new ArrayList<DownloadRuntime>(stacksRuntimes.size());
+ for (Runtime r : stacksRuntimes) {
+ DownloadRuntime dr = new DownloadRuntime(r.getId(),
+ r.getName(),
+ r.getVersion(),
+ r.getDownloadUrl());
+ dr.setDisclaimer(!StacksUtil.isEnterprise(r));
+ dr.setHumanUrl(r.getUrl());
+ downloadableRuntimes.add(dr);
+ }
+ return downloadableRuntimes;
+ }
+ }
+ return super.getDownloadRuntimes(fix);
+ }
+
+
+ protected Map<String, IRuntime> getServerRuntimes(
+ IProjectFacetVersion facetVersion) {
+ Set<org.eclipse.wst.common.project.facet.core.runtime.IRuntime> runtimesSet;
+ if (facetVersion == null) {
+ runtimesSet =RuntimeManager.getRuntimes();
+ } else {
+ runtimesSet = RuntimeManager.getRuntimes(Collections.singleton(facetVersion));
+ }
+
+ Map<String, IRuntime> runtimesMap = new LinkedHashMap<String, IRuntime>();
+ for (org.eclipse.wst.common.project.facet.core.runtime.IRuntime r : runtimesSet) {
+ IRuntime serverRuntime = FacetUtil.getRuntime(r);
+ if (serverRuntime != null) {
+ runtimesMap.put(r.getLocalizedName(), serverRuntime);
+ }
+ }
+ return runtimesMap;
+ }
+
+ protected void validateEnterpriseRepo() {
+ if (warningComponent != null) {
+ boolean isWarningLinkVisible = false;
+ if (isEnterpriseTargetRuntime()) {
+ if (enterpriseRepoStatus == null) {
+ enterpriseRepoStatus = MavenArtifactHelper.checkEnterpriseRequirementsAvailable(projectExample);
+ }
+ isWarningLinkVisible = !enterpriseRepoStatus.isOK();
+ if (isWarningLinkVisible) {
+ warningComponent.setLinkText(enterpriseRepoStatus.getMessage());
+ //warninglink.setText(enterpriseRepoStatus.getMessage());
+ warningComponent.getParent().layout(true, true);
+ }
+ }
+ warningComponent.setVisible(isWarningLinkVisible);
+ }
+ }
+
+ @Override
+ public void dispose() {
+ if (dialogSettings != null && serverRuntimes != null && serverTargetCombo != null) {
+ IRuntime lastUsedRuntime = serverRuntimes.get(serverTargetCombo.getText());
+ if (lastUsedRuntime != null) {
+ dialogSettings.put(TARGET_RUNTIME, lastUsedRuntime.getId());
+ }
+ }
+ if (listener != null) {
+ ServerCore.removeRuntimeLifecycleListener(listener);
+ listener = null;
+ }
+
+ saveInputHistory();
+
+ super.dispose();
+ }
+
+
+ /********** code below copied from {@link AbstractMavenWizardPage} **********/
+
+ /** the history limit */
+ protected static final int MAX_HISTORY = 15;
+
+ /** dialog settings to store input history */
+ protected IDialogSettings dialogSettings;
+
+ /** the Map of field ids to List of comboboxes that share the same history */
+ private Map<String, List<Combo>> fieldsWithHistory;
+
+ private boolean isHistoryLoaded = false;
+
+
+ /** Loads the dialog settings using the page name as a section name. */
+ private void initDialogSettings() {
+ IDialogSettings pluginSettings;
+
+ // This is strictly to get SWT Designer working locally without blowing up.
+ if( MavenPluginActivator.getDefault() == null ) {
+ pluginSettings = new DialogSettings("Workbench");
+ }
+ else {
+ pluginSettings = M2EUIPluginActivator.getDefault().getDialogSettings();
+ }
+
+ dialogSettings = pluginSettings.getSection(getName());
+ if(dialogSettings == null) {
+ dialogSettings = pluginSettings.addNewSection(getName());
+ pluginSettings.addSection(dialogSettings);
+ }
+ }
+
+ /** Loads the input history from the dialog settings. */
+ private void loadInputHistory() {
+ for(Map.Entry<String, List<Combo>> e : fieldsWithHistory.entrySet()) {
+ String id = e.getKey();
+ String[] items = dialogSettings.getArray(id);
+ if(items != null) {
+ for(Combo combo : e.getValue()) {
+ String text = combo.getText();
+ combo.setItems(items);
+ if(text.length() > 0) {
+ // setItems() clears the text input, so we need to restore it
+ combo.setText(text);
+ }
+ }
+ }
+ }
+ }
+
+ /** Saves the input history into the dialog settings. */
+ private void saveInputHistory() {
+ for(Map.Entry<String, List<Combo>> e : fieldsWithHistory.entrySet()) {
+ String id = e.getKey();
+
+ Set<String> history = new LinkedHashSet<String>(MAX_HISTORY);
+
+ for(Combo combo : e.getValue()) {
+ String lastValue = combo.getText();
+ if(lastValue != null && lastValue.trim().length() > 0) {
+ history.add(lastValue);
+ }
+ }
+
+ Combo combo = e.getValue().iterator().next();
+ String[] items = combo.getItems();
+ for(int j = 0; j < items.length && history.size() < MAX_HISTORY; j++ ) {
+ history.add(items[j]);
+ }
+
+ dialogSettings.put(id, history.toArray(new String[history.size()]));
+ }
+ }
+
+ /** Adds an input control to the list of fields to save. */
+ protected void addFieldWithHistory(String id, Combo combo) {
+ if(combo != null) {
+ List<Combo> combos = fieldsWithHistory.get(id);
+ if(combos == null) {
+ combos = new ArrayList<Combo>();
+ fieldsWithHistory.put(id, combos);
+ }
+ combos.add(combo);
+ }
+ }
+
}
More information about the jbosstools-commits
mailing list