Commit 26949305 authored by arbennett's avatar arbennett
Browse files

Adding first draft of DataFileOption.



This will allow new ICE Item projects to choose a default set of data to
load into the form when creating the item with a null argument to the
loadInput() method.
Signed-off-by: default avatararbennett <bennett.andr@gmail.com>
parent 5a44c89c
package org.eclipse.ice.projectgeneration.templates;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.pde.ui.templates.BaseOptionTemplateSection;
import org.eclipse.pde.ui.templates.TemplateOption;
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.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class DataFileOption extends TemplateOption {
private Text locationPathField;
private Button browseButton;
private Label locationLabel;
public DataFileOption(BaseOptionTemplateSection section, String name, String label) {
super(section, name, label);
}
@Override
public void createControl(Composite parent, int span) {
locationLabel = new Label(parent, SWT.NONE);
locationLabel.setText("Default dataset to load into the form:");
locationPathField = new Text(parent, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = 250;
data.horizontalSpan = 2;
locationPathField.setLayoutData(data);
browseButton = new Button(parent, SWT.PUSH);
browseButton.setText("Browse");
browseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
handleLocationBrowseButtonPressed();
}
});
}
private void handleLocationBrowseButtonPressed() {
String selectedFile = null;
String dirName = getPathFromLocationField();
}
private String getPathFromLocationField() {
URI fieldURI;
try {
fieldURI = new URI(locationPathField.getText());
} catch (URISyntaxException e) {
return locationPathField.getText();
}
String path = fieldURI.getPath();
return path != null ? path : locationPathField.getText();
}
@Override
public void setEnabled(boolean enabled) {
locationLabel.setEnabled(enabled);
locationPathField.setEnabled(enabled);
browseButton.setEnabled(enabled);
}
}
......@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.ice.projectgeneration.templates;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.ArrayList;
......@@ -32,6 +33,7 @@ import org.eclipse.pde.core.plugin.IPluginModelFactory;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.IPluginFieldData;
import org.eclipse.pde.ui.templates.OptionTemplateSection;
import org.eclipse.pde.ui.templates.TemplateOption;
/**
* Provides the information for the ICEItemWizard, the final page in the
......@@ -50,6 +52,10 @@ public class ICEItemTemplate extends OptionTemplateSection {
protected static final String KEY_JOB_LAUNCHER_EXT = "createJobLauncher";
protected static final String KEY_MODEL_EXT = "createModel";
protected static final String KEY_IO_FORMAT_EXT = "ioFormat";
protected static final String KEY_SET_DEFAULT_FILE = "defaultFile";
protected static final String KEY_DEFAULT_FILE_NAME = "defaultFileName";
private ArrayList<TemplateOption> options;
/**
* Constructor
......@@ -81,6 +87,9 @@ public class ICEItemTemplate extends OptionTemplateSection {
addOption(KEY_JOB_LAUNCHER_EXT, "Create Job Launcher?", true, 0);
addOption(KEY_MODEL_EXT, "Create Model?", true, 0);
addOption(KEY_IO_FORMAT_EXT, "File Format", getIOFormatOptions(), "", 0);
addOption(KEY_SET_DEFAULT_FILE, "Include a default dataset?", false, 0);
addOption(KEY_DEFAULT_FILE_NAME, "Choose a default dataset:", new File(""), 0);
setOptionEnabled(KEY_DEFAULT_FILE_NAME, false);
}
@Override
......@@ -152,6 +161,15 @@ public class ICEItemTemplate extends OptionTemplateSection {
" "
).trim();
}
protected TemplateOption addOption(String name, String label, File value, int pageIndex) {
DataFileOption option = new DataFileOption(this, name, label);
option.setValue(value);
registerOption(option, value, pageIndex);
return option;
}
@Override
protected void updateModel(IProgressMonitor monitor) throws CoreException {
......@@ -191,5 +209,9 @@ public class ICEItemTemplate extends OptionTemplateSection {
if (!extension.isInTheModel())
plugin.add(extension);
}
if (getBooleanOption(KEY_SET_DEFAULT_FILE)) {
setOptionEnabled(KEY_DEFAULT_FILE_NAME,true);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment