# HG changeset patch # User Omair Majid # Date 1393961849 18000 # Node ID 969ba523a22c6e6a45bd0e4793ee8d6033b8c451 # Parent b2822596b9a0f851df5bf72f2f725d0ef35360e6 Provide bundle names/versions for thermostat bundles diff -r b2822596b9a0 -r 969ba523a22c TODO.md --- a/TODO.md Fri Feb 28 12:27:03 2014 -0500 +++ b/TODO.md Tue Mar 04 14:37:29 2014 -0500 @@ -6,8 +6,7 @@ - Implement UI for grouping options - Modify the bundle loading dialog to be smarter. Offer auto-completion and - automatically identify bundle names from all open projects and dependencies, - as well as core thermostat bundles. + automatically identify bundle names from all open projects and dependencies. - There are lots of things to fix marked in the code with `TODO` and `FIXME` diff -r b2822596b9a0 -r 969ba523a22c com.redhat.thermostat.tools.eclipse.plugin.tests/src/com/redhat/thermostat/tools/eclipse/plugin/tests/editor/ThermostatBundleInformationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/com.redhat.thermostat.tools.eclipse.plugin.tests/src/com/redhat/thermostat/tools/eclipse/plugin/tests/editor/ThermostatBundleInformationTest.java Tue Mar 04 14:37:29 2014 -0500 @@ -0,0 +1,28 @@ +package com.redhat.thermostat.tools.eclipse.plugin.tests.editor; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.tools.eclipse.plugin.editor.ThermostatBundleInformation; + +public class ThermostatBundleInformationTest { + + private ThermostatBundleInformation information; + + @Before + public void setUp() { + information = new ThermostatBundleInformation(); + } + + @Test + public void testVersions() { + List expected = Arrays.asList("1.0", "1.0.2", "1.2.0"); + assertEquals(expected, information.getVersions()); + } + +} diff -r b2822596b9a0 -r 969ba523a22c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/NewBundleDialog.java --- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/NewBundleDialog.java Fri Feb 28 12:27:03 2014 -0500 +++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/NewBundleDialog.java Tue Mar 04 14:37:29 2014 -0500 @@ -1,6 +1,7 @@ package com.redhat.thermostat.tools.eclipse.plugin.editor; import java.io.IOException; +import java.util.List; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; @@ -10,6 +11,7 @@ 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.Control; import org.eclipse.swt.widgets.FileDialog; @@ -30,9 +32,15 @@ private BundleInformation bundleInfo = new BundleInformation(); + private ThermostatBundleInformation thermostatInfo = new ThermostatBundleInformation(); + + private Button thermostatBundlesSelectionButton; + private Combo thermostatVersion; + private Combo thermostatBundle; + private Button manualSelectionButton; - private Text nameText; - private Text versionText; + private Text customNameText; + private Text customVersionText; private Button fromJarButton; private Text fileLocationText; @@ -63,43 +71,78 @@ containerLayout.marginLeft = 5; container.setLayout(containerLayout); + thermostatBundlesSelectionButton = new Button(container, SWT.RADIO); + thermostatBundlesSelectionButton.setSelection(true); + thermostatBundlesSelectionButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + disableInputWidgets(); + + thermostatVersion.setEnabled(true); + thermostatBundle.setEnabled(true); + } + }); + thermostatBundlesSelectionButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); + thermostatBundlesSelectionButton.setText("Thermostat Bundle"); + + Label thermostatVersionLabel = new Label(container, SWT.None); + thermostatVersionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + thermostatVersionLabel.setText("Version"); + + thermostatVersion = new Combo(container, SWT.None); + GridData thermostatVersionLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1); + thermostatVersion.setLayoutData(thermostatVersionLayoutData); + thermostatVersion.setItems(toArray(thermostatInfo.getVersions())); + thermostatVersion.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String selectedVersion = thermostatVersion.getItem(thermostatVersion.getSelectionIndex()); + thermostatBundle.setItems(toArray(thermostatInfo.getBundleNames(selectedVersion))); + } + }); + + Label thermostatBundleLabel = new Label(container, SWT.None); + thermostatBundleLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + thermostatBundleLabel.setText("Bundle"); + + thermostatBundle = new Combo(container, SWT.NONE); + GridData thermostatBundleLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1); + thermostatBundle.setLayoutData(thermostatBundleLayoutData); + manualSelectionButton = new Button(container, SWT.RADIO); - manualSelectionButton.setSelection(true); manualSelectionButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - nameText.setEnabled(true); - versionText.setEnabled(true); + disableInputWidgets(); - fileLocationText.setEnabled(false); - btnFromFile.setEnabled(false); + customNameText.setEnabled(true); + customVersionText.setEnabled(true); } }); manualSelectionButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); manualSelectionButton.setText(Messages.NewBundleDialog_manualSectionTitle); Label nameLabel = new Label(container, SWT.None); - nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); nameLabel.setText(Messages.NewBundleDialog_symbolicNameLabel); - nameText = new Text(container, SWT.None); + customNameText = new Text(container, SWT.None); GridData nameTextLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); nameTextLayoutData.horizontalSpan = 2; - nameText.setLayoutData(nameTextLayoutData); + customNameText.setLayoutData(nameTextLayoutData); Label versionLabel = new Label(container, SWT.None); - versionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + versionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); versionLabel.setText(Messages.NewBundleDialog_versionLabel); - versionText = new Text(container, SWT.None); + customVersionText = new Text(container, SWT.None); GridData versionTextLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); versionTextLayoutData.horizontalSpan = 2; - versionText.setLayoutData(versionTextLayoutData); + customVersionText.setLayoutData(versionTextLayoutData); fromJarButton = new Button(container, SWT.RADIO); fromJarButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - nameText.setEnabled(false); - versionText.setEnabled(false); + disableInputWidgets(); fileLocationText.setEnabled(true); btnFromFile.setEnabled(true); @@ -109,16 +152,14 @@ fromJarButton.setText(Messages.NewBundleDialog_fromJarSectionTitle); Label locationLabel = new Label(container, SWT.NONE); - locationLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + locationLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); locationLabel.setText(Messages.NewBundleDialog_pathLabel); fileLocationText = new Text(container, SWT.BORDER); - fileLocationText.setEnabled(false); - fileLocationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + fileLocationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); btnFromFile = new Button(container, SWT.NONE); btnFromFile.setText(Messages.NewBundleDialog_findOnDisk); - btnFromFile.setEnabled(false); btnFromFile.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -131,9 +172,28 @@ } }); + // invoke manually on startup to enable/disable other widgets + thermostatBundlesSelectionButton.setSelection(true); + return area; } + private void disableInputWidgets() { + thermostatVersion.setEnabled(false); + thermostatBundle.setEnabled(false); + + customNameText.setEnabled(false); + customVersionText.setEnabled(false); + + fileLocationText.setEnabled(false); + btnFromFile.setEnabled(false); + } + + private String[] toArray(List inputList) { + return inputList.toArray(new String[inputList.size()]); + } + + @Override protected void okPressed() { saveInput(); @@ -141,9 +201,11 @@ } private void saveInput() { - if (manualSelectionButton.getSelection()) { - bundleInfo = new BundleInformation(nameText.getText(), versionText.getText()); - } else { + if (thermostatBundlesSelectionButton.getSelection()) { + bundleInfo = new BundleInformation(thermostatBundle.getText(), thermostatVersion.getText()); + } else if (manualSelectionButton.getSelection()) { + bundleInfo = new BundleInformation(customNameText.getText(), customVersionText.getText()); + } else if (fromJarButton.getSelection()) { try { BundleInformationExtractor extractor = new BundleInformationExtractor(); BundleInformation extractedInfo = extractor.extract(fileLocationText.getText()); @@ -157,6 +219,8 @@ } }); } + } else { + throw new AssertionError("Unexpected case"); } } diff -r b2822596b9a0 -r 969ba523a22c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/ThermostatBundleInformation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/ThermostatBundleInformation.java Tue Mar 04 14:37:29 2014 -0500 @@ -0,0 +1,57 @@ +package com.redhat.thermostat.tools.eclipse.plugin.editor; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Provides information about bundles included in thermostat + */ +public class ThermostatBundleInformation { + // TODO can we avoid hardcoding this information? + + private Map fileToBundleNames = new TreeMap<>(); + + public ThermostatBundleInformation() { + fileToBundleNames.put("agent-cli", "com.redhat.thermostat.agent.cli"); + fileToBundleNames.put("agent-command", "com.redhat.thermostat.agent.command"); + fileToBundleNames.put("agent-core", "com.redhat.thermostat.agent.core"); + fileToBundleNames.put("agent-proxy-common", "com.redhat.thermostat.agent.proxy.common"); + fileToBundleNames.put("annotations", "com.redhat.thermostat.annotations"); + fileToBundleNames.put("client-cli", "com.redhat.thermostat.client.cli"); + fileToBundleNames.put("client-command", "com.redhat.thermostat.client.command"); + fileToBundleNames.put("client-core", "com.redhat.thermostat.client.core"); + fileToBundleNames.put("client-swing", "com.redhat.thermostat.client.swing"); + fileToBundleNames.put("common-command", "com.redhat.thermostat.common.command"); + fileToBundleNames.put("common-core", "com.redhat.thermostat.common.core"); + fileToBundleNames.put("keyring", "com.redhat.thermostat.keyring"); + fileToBundleNames.put("killvm-agent", "com.redhat.thermostat.killvm.agent"); + fileToBundleNames.put("killvm-client-swing", "com.redhat.thermostat.killvm.client"); + fileToBundleNames.put("laf-utils", "com.redhat.thermostat.internal.utils.laf"); + fileToBundleNames.put("launcher", "com.redhat.thermostat.launcher"); + fileToBundleNames.put("main", "com.redhat.thermostat.main"); + fileToBundleNames.put("osgi-living-vm-filter-core", "com.redhat.thermostat.filter.livingvm.core"); + fileToBundleNames.put("osgi-living-vm-filter-swing", "com.redhat.thermostat.filter.livingvm.swing"); + fileToBundleNames.put("osgi-process-handler", "com.redhat.thermostat.process"); + fileToBundleNames.put("plugin-validator", "com.redhat.thermostat.plugin.validator"); + fileToBundleNames.put("shared-config", "com.redhat.thermostat.configuration"); + fileToBundleNames.put("storage-cli", "com.redhat.thermostat.storage.cli"); + fileToBundleNames.put("storage-core", "com.redhat.thermostat.storage.core"); + fileToBundleNames.put("storage-mongodb", "com.redhat.thermostat.storage.mongodb"); + fileToBundleNames.put("swing-components", "com.redhat.thermostat.client.swing.components"); + fileToBundleNames.put("system-backend", "com.redhat.thermostat.backend.system"); + fileToBundleNames.put("web-client", "com.redhat.thermostat.web.client"); + fileToBundleNames.put("web-common", "com.redhat.thermostat.web.common"); + fileToBundleNames.put("web-server", "com.redhat.thermostat.web.server"); + } + public List getVersions() { + return Arrays.asList("1.0", "1.0.2", "1.2.0"); + } + + public List getBundleNames(String selectedVersion) { + return new ArrayList<>(fileToBundleNames.values()); + } + +}