Mercurial > hg > thermostat-tools-eclipse
view com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/NewBundleDialog.java @ 104:5877be030593
Show an error dialog on IO error
If an IO error happens when extracting information from a
bundle, show an error dialog.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 07 Feb 2014 16:11:46 -0500 |
parents | e5e10d8a356c |
children | 969ba523a22c |
line wrap: on
line source
package com.redhat.thermostat.tools.eclipse.plugin.editor; import java.io.IOException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.redhat.thermostat.tools.eclipse.plugin.BundleInformation; import com.redhat.thermostat.tools.eclipse.plugin.BundleInformationExtractor; import com.redhat.thermostat.tools.eclipse.plugin.Messages; /** * Prompt the user to enter or select a bundle name/version. * * Used by the command edit page. */ public class NewBundleDialog extends TitleAreaDialog { private BundleInformation bundleInfo = new BundleInformation(); private Button manualSelectionButton; private Text nameText; private Text versionText; private Button fromJarButton; private Text fileLocationText; private Button btnFromFile; public NewBundleDialog(Shell parentShell) { super(parentShell); } @Override public void create() { super.create(); setTitle(Messages.NewBundleDialog_title); setMessage(Messages.NewBundleDialog_message); } @Override protected Control createDialogArea(Composite parent) { Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,true)); GridLayout containerLayout = new GridLayout(3, false); containerLayout.marginTop = 5; containerLayout.marginRight = 5; containerLayout.marginLeft = 5; container.setLayout(containerLayout); 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); fileLocationText.setEnabled(false); btnFromFile.setEnabled(false); } }); 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.setText(Messages.NewBundleDialog_symbolicNameLabel); nameText = new Text(container, SWT.None); GridData nameTextLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); nameTextLayoutData.horizontalSpan = 2; nameText.setLayoutData(nameTextLayoutData); Label versionLabel = new Label(container, SWT.None); versionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); versionLabel.setText(Messages.NewBundleDialog_versionLabel); versionText = new Text(container, SWT.None); GridData versionTextLayoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); versionTextLayoutData.horizontalSpan = 2; versionText.setLayoutData(versionTextLayoutData); fromJarButton = new Button(container, SWT.RADIO); fromJarButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { nameText.setEnabled(false); versionText.setEnabled(false); fileLocationText.setEnabled(true); btnFromFile.setEnabled(true); } }); fromJarButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); 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.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)); btnFromFile = new Button(container, SWT.NONE); btnFromFile.setText(Messages.NewBundleDialog_findOnDisk); btnFromFile.setEnabled(false); btnFromFile.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); dialog.setFilterExtensions(new String[] { "*.jar" }); //$NON-NLS-1$ String result = dialog.open(); if (result != null) { fileLocationText.setText(result); } } }); return area; } @Override protected void okPressed() { saveInput(); super.okPressed(); } private void saveInput() { if (manualSelectionButton.getSelection()) { bundleInfo = new BundleInformation(nameText.getText(), versionText.getText()); } else { try { BundleInformationExtractor extractor = new BundleInformationExtractor(); BundleInformation extractedInfo = extractor.extract(fileLocationText.getText()); bundleInfo.setName(extractedInfo.getName()); bundleInfo.setVersion(extractedInfo.getVersion()); } catch (final IOException e) { getShell().getDisplay().asyncExec(new Runnable() { @Override public void run() { MessageDialog.openError(getShell(), Messages.NewBundleDialog_errorExtractingInformationFromJarFile, e.getMessage()); } }); } } } public BundleInformation getBundleInformation() { return bundleInfo; } }