| package org.eclipse.epp.sfx.archive.ui.internal; |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.epp.sfx.archive.ui.Activator; |
| import org.eclipse.epp.sfx.archive.ui.ArchiveMaker; |
| import org.eclipse.epp.sfx.archive.ui.internal.model.Archive; |
| import org.eclipse.epp.sfx.archive.ui.internal.model.ISFXArchiveModelListener; |
| import org.eclipse.epp.sfx.archive.ui.internal.model.ModelChangedEvent; |
| import org.eclipse.epp.sfx.archive.ui.internal.model.SFXArchiveModel; |
| import org.eclipse.jface.operation.IRunnableWithProgress; |
| import org.eclipse.jface.text.IDocument; |
| 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.Event; |
| import org.eclipse.swt.widgets.FileDialog; |
| import org.eclipse.swt.widgets.Listener; |
| import org.eclipse.swt.widgets.Text; |
| import org.eclipse.ui.forms.widgets.FormToolkit; |
| import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
| import org.eclipse.ui.progress.IProgressService; |
| |
| public class DestinationFormPart extends SectionFormPart implements Listener, ISFXArchiveModelListener { |
| |
| private Text containerNameField; |
| private Button containerBrowseButton; |
| private Button generateButton; |
| private Button sfxRadioButton; |
| private Button exeRadioButton; |
| private Button pack200Checkbox; |
| private Button zipCheckbox; |
| |
| private SFXArchiveConfigurationPage page; |
| |
| private boolean fChangingModel; |
| private boolean fChangingUI; |
| |
| public DestinationFormPart(SFXArchiveConfigurationPage page, Composite body) { |
| super(body, "Destination", page.getEditor().getToolkit()); |
| this.page = page; |
| |
| updateWidgetEnablements(); |
| } |
| |
| public Composite createClient(Composite body, FormToolkit toolkit) { |
| return createDestinationGroup(body, toolkit); |
| } |
| |
| protected Composite createDestinationGroup(Composite parent, FormToolkit toolkit) { |
| Composite containerGroup = toolkit.createComposite(parent); |
| GridLayout layout = new GridLayout(); |
| layout.numColumns = 4; |
| containerGroup.setLayout(layout); |
| containerGroup.setLayoutData(new GridData( |
| GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); |
| |
| toolkit.createLabel(containerGroup, "Archive File:"); |
| |
| containerNameField = toolkit.createText(containerGroup, "", SWT.SINGLE | SWT.BORDER); |
| containerNameField.addListener(SWT.Modify, this); |
| GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
| | GridData.GRAB_HORIZONTAL); |
| data.horizontalSpan = 2; |
| containerNameField.setLayoutData(data); |
| |
| containerBrowseButton = toolkit.createButton(containerGroup, IDEWorkbenchMessages.WizardImportPage_browse2, SWT.PUSH); |
| containerBrowseButton.setLayoutData(new GridData( |
| GridData.HORIZONTAL_ALIGN_FILL)); |
| containerBrowseButton.addListener(SWT.Selection, this); |
| Utils.setButtonLayoutData(containerBrowseButton); |
| |
| toolkit.createLabel(containerGroup, ""); //placeholder |
| sfxRadioButton = toolkit.createButton(containerGroup, "Archive only", SWT.RADIO); |
| sfxRadioButton.addSelectionListener(new SelectionAdapter() { |
| |
| public void widgetSelected(SelectionEvent e) { |
| if (sfxRadioButton.getSelection()) |
| exeRadioButton.setSelection(false); |
| } |
| |
| }); |
| data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); |
| data.horizontalSpan = 3; |
| sfxRadioButton.setLayoutData(data); |
| |
| toolkit.createLabel(containerGroup, ""); //placeholder |
| exeRadioButton = toolkit.createButton(containerGroup, "Archive and link with Windows launcher", SWT.RADIO); |
| exeRadioButton.addSelectionListener(new SelectionAdapter() { |
| |
| public void widgetSelected(SelectionEvent e) { |
| if (exeRadioButton.getSelection()) |
| sfxRadioButton.setSelection(false); |
| } |
| |
| }); |
| exeRadioButton.setLayoutData(data); |
| exeRadioButton.setSelection(true); |
| |
| toolkit.createLabel(containerGroup, ""); //placeholder |
| pack200Checkbox = toolkit.createButton(containerGroup, "Use pack200 jar compression", SWT.CHECK); |
| pack200Checkbox.setLayoutData(data); |
| |
| toolkit.createLabel(containerGroup, ""); //placeholder |
| zipCheckbox = toolkit.createButton(containerGroup, "Use zip compression", SWT.CHECK); |
| zipCheckbox.setLayoutData(data); |
| zipCheckbox.setEnabled(false); |
| |
| toolkit.createLabel(containerGroup, ""); //placeholder |
| |
| generateButton = toolkit.createButton(containerGroup, "Generate Archive", SWT.PUSH); |
| generateButton.setImage(Activator.getDefault() |
| .getImageDescriptor("/icons/obj16/sfx_archive_obj.gif").createImage()); |
| generateButton.setLayoutData(new GridData( |
| GridData.HORIZONTAL_ALIGN_BEGINNING)); |
| generateButton.addListener(SWT.Selection, this); |
| Utils.setButtonLayoutData(generateButton); |
| |
| return containerGroup; |
| } |
| |
| public void handleEvent(Event event) { |
| if (fChangingUI) |
| return; |
| |
| if (event.widget == containerBrowseButton) { |
| handleContainerBrowseButtonPressed(); |
| } |
| else if (event.widget == generateButton) { |
| handleGenerateButtonPressed(); |
| } |
| else if (event.widget == containerNameField) { |
| handleContainerNameFieldChanged(); |
| } |
| |
| updateWidgetEnablements(); |
| } |
| |
| private void updateWidgetEnablements() { |
| |
| } |
| |
| protected void handleContainerBrowseButtonPressed() { |
| FileDialog dialog = new FileDialog(page.getEditorSite().getShell(), SWT.SAVE); |
| String path = containerNameField.getText(); |
| if (path.trim().length() == 0) |
| path = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); |
| dialog.setFileName(path); |
| String res = dialog.open(); |
| if (res != null) { |
| containerNameField.setText(res); |
| } |
| } |
| |
| protected void handleGenerateButtonPressed() { |
| page.getEditor().doSave(null); |
| SFXArchiveModel model = page.getModel(); |
| if (model != null) { |
| final Archive archive = model.getArchive(); |
| final boolean exe = exeRadioButton.getSelection(); |
| final boolean pack200 = pack200Checkbox.getSelection(); |
| final boolean zip = zipCheckbox.getSelection(); |
| if (archive != null) { |
| IProgressService progressService = Activator.getDefault().getWorkbench().getProgressService(); |
| try { |
| progressService.busyCursorWhile(new IRunnableWithProgress() { |
| |
| public void run(IProgressMonitor monitor) |
| throws InvocationTargetException, InterruptedException { |
| ArchiveMaker.getInstance().make(archive, exe, pack200, zip, monitor); |
| } |
| |
| }); |
| } catch (InvocationTargetException e) { |
| throw new RuntimeException(e); |
| } catch (InterruptedException e) { |
| // Ignore |
| } |
| |
| } |
| } |
| } |
| |
| private void handleContainerNameFieldChanged() { |
| SFXArchiveModel model = page.getModel(); |
| if (model != null) { |
| Archive archive = model.getArchive(); |
| if (archive != null) { |
| fChangingModel = true; |
| try { |
| archive.setDestinationFile(containerNameField.getText()); |
| } |
| finally { |
| fChangingModel = false; |
| } |
| } |
| } |
| } |
| |
| public void modelChanged(ModelChangedEvent event) { |
| if (fChangingModel) |
| return; |
| fChangingUI = true; |
| try { |
| if (event.type == ModelChangedEvent.TYPE_REFRESH) { |
| containerNameField.setText(Utils.avoidNull(page.getModel().getArchive().getDestinationFile())); |
| } |
| if (event.type == ModelChangedEvent.TYPE_CHANGE) { |
| if (event.object instanceof Archive) { |
| switch (event.property) { |
| case Archive.PROP_DESTINATION_FILE: |
| containerNameField.setText(Utils.avoidNull(((Archive) event.object).getDestinationFile())); |
| break; |
| } |
| } |
| } |
| } |
| finally { |
| fChangingUI = false; |
| } |
| } |
| |
| } |