/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.design.wizards;
import org.eclipse.core.resources.IContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
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.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.Preferences;
import de.innovationgate.wga.model.WGADesignConfigurationModel;
/**
* wizard page to export a wga design as plugin
*
*
*/
public class ExportWGAPluginLocalPage extends WizardPage {
private IContainer _design;
private Text _txtExportLocation;
private Button _btnBrowse;
private Text _txtBuild;
private WGADesignConfigurationModel _model;
private Button _optFileNameShort;
private Button _optFileNameFQ;
private String _exportLocation;
private boolean _shortFileName = true;
private int _build;
protected ExportWGAPluginLocalPage(IContainer design) {
super("Export WGA Plugin");
_design = design;
setPageComplete(false);
setTitle("Export WGA Plugin");
setDescription("This wizard exports a WGA Plugin to the local filesystem.");
}
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
container.setLayout(layout);
Label lblFolder = new Label(container, SWT.None);
lblFolder.setText("Design folder:");
Label lblPath = new Label(container, SWT.None);
lblPath.setText(_design.getLocation().toFile().getAbsolutePath());
new Label(container, SWT.None);
Label lblExportLocation = new Label(container, SWT.None);
lblExportLocation.setText("Export directory:");
_txtExportLocation = new Text(container, SWT.BORDER|SWT.READ_ONLY);
_txtExportLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
String exportLocation = Plugin.getDefault().getPreferenceStore().getString(Preferences.PLUGIN_EXPORT_LOCATION);
_txtExportLocation.setText(exportLocation);
_txtExportLocation.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
pageChanged();
}
});
_btnBrowse = new Button(container, SWT.None);
_btnBrowse.setText("...");
_btnBrowse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleBrowse();
}
});
Label lblBuild = new Label(container, SWT.None);
lblBuild.setText("Build:");
_txtBuild = new Text(container, SWT.BORDER);
_txtBuild.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
_txtBuild.setText(Integer.toString(getModel().getPluginBuild()));
_txtBuild.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
pageChanged();
}
});
_txtBuild.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
if (!Character.isIdentifierIgnorable(e.character)) {
if (Character.isDigit(e.character)) {
e.doit = true;
} else {
e.doit = false;
}
}
}
});
new Label(container, SWT.None);
Group optFileNameGroup = new Group(container, SWT.None);
optFileNameGroup.setText("File name");
GridLayout groupLayout = new GridLayout();
groupLayout.numColumns = 1;
optFileNameGroup.setLayout(groupLayout);
GridData groupLayoutData = new GridData(GridData.FILL_HORIZONTAL);
groupLayoutData.horizontalSpan = 3;
optFileNameGroup.setLayoutData(groupLayoutData);
_optFileNameShort = new Button(optFileNameGroup, SWT.RADIO);
_optFileNameShort.setText("Short");
_optFileNameShort.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
_optFileNameShort.setSelection(true);
_optFileNameShort.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
pageChanged();
}
});
_optFileNameFQ = new Button(optFileNameGroup, SWT.RADIO);
_optFileNameFQ.setText("Fully qualified");
_optFileNameFQ.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
_optFileNameFQ.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
pageChanged();
}
});
setControl(container);
pageChanged();
}
private void handleBrowse() {
DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SINGLE);
dialog.setText("Select export directory");
String selectedDirectory = dialog.open();
if (selectedDirectory != null) {
_txtExportLocation.setText(selectedDirectory);
Plugin.getDefault().getPreferenceStore().putValue(Preferences.PLUGIN_EXPORT_LOCATION, _txtExportLocation.getText());
}
}
public WGADesignConfigurationModel getModel() {
return _model;
}
public void setModel(WGADesignConfigurationModel model) {
_model = model;
}
public String getExportLocation() {
return _exportLocation;
}
public boolean isShortFileName() {
return _shortFileName;
}
private void pageChanged() {
_exportLocation = _txtExportLocation.getText();
if (_optFileNameFQ.getSelection()) {
_shortFileName = false;
} else {
_shortFileName = true;
}
if (_txtBuild.getText().trim().equals("")) {
setMessage("Please specify a buildnumber.", WizardPage.WARNING);
setPageComplete(false);
return;
} else {
_build = Integer.parseInt(_txtBuild.getText());
}
setPageComplete(true);
}
public int getBuild() {
return _build;
}
public boolean isPageComplete() {
return super.isPageComplete()&&isCurrentPage();
}
public IWizardPage getNextPage() {
return null;
}
}