Commit 7ae347c2 authored by amccaskey's avatar amccaskey
Browse files

Setting the default project (when no project is selected) to be itemDB



This commit sets the Core to import files and items to the itemDB
directory when no directory has been specified. This addresses bug
480601 
Signed-off-by: default avataramccaskey <mccaskeyaj@ornl.gov>
parent 27907ad6
......@@ -13,15 +13,13 @@
package org.eclipse.ice.client.widgets;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.ice.client.common.internal.ClientHolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.datastructures.form.AllowedValueType;
......@@ -95,8 +93,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
/**
* Logger for handling event messages and other information.
*/
private static final Logger logger = LoggerFactory
.getLogger(EntryComposite.class);
private static final Logger logger = LoggerFactory.getLogger(EntryComposite.class);
/**
* A label that describes the Entry.
......@@ -182,8 +179,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
if (refEntry != null) {
entry = refEntry;
} else {
throw new RuntimeException("Entry passed to EntryComposite "
+ "constructor cannot be null!");
throw new RuntimeException("Entry passed to EntryComposite " + "constructor cannot be null!");
}
// Create the Buttons array
buttons = new ArrayList<Button>();
......@@ -267,8 +263,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Set the box to be checked if the current entry value is one of the
// "positive" answers from the allowed values
if (allowedBinaryValues.subList(0, 5)
.contains(entry.getValue().toLowerCase())) {
if (allowedBinaryValues.subList(0, 5).contains(entry.getValue().toLowerCase())) {
tmpButton.setSelection(true);
} else {
// Otherwise unchecked
......@@ -281,15 +276,12 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Notify any listeners that the selection has changed
notifyListeners(SWT.Selection, new Event());
// Get the index of the value
int index = lowercaseAllowedValues
.indexOf(entry.getValue().toLowerCase());
int index = lowercaseAllowedValues.indexOf(entry.getValue().toLowerCase());
// Set the correct value
String value = null;
value = (index == 0) ? entry.getAllowedValues().get(1)
: entry.getAllowedValues().get(0);
value = (index == 0) ? entry.getAllowedValues().get(1) : entry.getAllowedValues().get(0);
setEntryValue(value);
logger.info("EntryComposite Message: Updated Entry "
+ entry.getName() + " with value = "
logger.info("EntryComposite Message: Updated Entry " + entry.getName() + " with value = "
+ entry.getValue());
return;
......@@ -345,8 +337,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
if (dropDown == null || dropDown.isDisposed()) {
// Create a drop-down menu
dropDown = new Combo(this, SWT.DROP_DOWN | SWT.SINGLE | SWT.V_SCROLL
| SWT.H_SCROLL | SWT.READ_ONLY);
dropDown = new Combo(this, SWT.DROP_DOWN | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
dropDown.setBackground(getBackground());
// Determine the current value of the entry.
......@@ -456,37 +447,46 @@ public class EntryComposite extends Composite implements IUpdateableListener {
@Override
public void widgetSelected(SelectionEvent e) {
// Get the Client
IClient client = ClientHolder.getClient();
// Open up a file browser
FileDialog fileDialog = new FileDialog(getShell());
fileDialog.setText("Select a file to import into ICE");
String filePath = fileDialog.open();
if (filePath != null) {
// Import the files
File importedFile = new File(filePath);
client.importFile(importedFile.toURI());
// Create a new content provider with the new file
// in the allowed values list
IEntryContentProvider prov = new BasicEntryContentProvider();
ArrayList<String> valueList = entry.getAllowedValues();
if (!valueList.contains(importedFile.getName())) {
valueList.add(importedFile.getName());
}
prov.setAllowedValueType(AllowedValueType.File);
IClient client = null;
try {
client = IClient.getClient();
} catch (CoreException e1) {
logger.error("Could not get reference to IClient instance.", e1);
}
// Finish setting the allowed values and default
// value
prov.setAllowedValues(valueList);
if (client != null) {
// Open up a file browser
FileDialog fileDialog = new FileDialog(getShell());
fileDialog.setText("Select a file to import into ICE");
String filePath = fileDialog.open();
if (filePath != null) {
// Import the files
File importedFile = new File(filePath);
client.importFile(importedFile.toURI());
// Create a new content provider with the new file
// in the allowed values list
IEntryContentProvider prov = new BasicEntryContentProvider();
ArrayList<String> valueList = entry.getAllowedValues();
if (!valueList.contains(importedFile.getName())) {
valueList.add(importedFile.getName());
}
prov.setAllowedValueType(AllowedValueType.File);
// Set the new provider
entry.setContentProvider(prov);
// Finish setting the allowed values and default
// value
prov.setAllowedValues(valueList);
// Set the entry's value to the new file
setEntryValue(importedFile.getName());
}
// Notify any listeners of the selection event
notifyListeners(SWT.Selection, new Event());
// Set the new provider
entry.setContentProvider(prov);
// Set the entry's value to the new file
setEntryValue(importedFile.getName());
}
// Notify any listeners of the selection event
notifyListeners(SWT.Selection, new Event());
}
return;
}
......@@ -505,8 +505,8 @@ public class EntryComposite extends Composite implements IUpdateableListener {
*/
private void createExecutableDropDown() {
if (dropDown == null || dropDown.isDisposed()) {
dropDown = new Combo(this, SWT.BORDER | SWT.LEAD | SWT.DROP_DOWN
| SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
dropDown = new Combo(this,
SWT.BORDER | SWT.LEAD | SWT.DROP_DOWN | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
dropDown.setFocus();
dropDown.setLayoutData(new GridData(400, SWT.DEFAULT));
......@@ -527,8 +527,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
dropDown.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN
|| e.detail == SWT.TRAVERSE_TAB_NEXT) {
if (e.detail == SWT.TRAVERSE_RETURN || e.detail == SWT.TRAVERSE_TAB_NEXT) {
// Get the entered text and create a File
String path = dropDown.getText();
......@@ -540,11 +539,9 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Check if its an executable
if (file.canExecute()) {
IEntryContentProvider prov = new BasicEntryContentProvider();
ArrayList<String> valueList = entry
.getAllowedValues();
ArrayList<String> valueList = entry.getAllowedValues();
valueList.add(file.toURI().toString());
prov.setAllowedValueType(
AllowedValueType.Executable);
prov.setAllowedValueType(AllowedValueType.Executable);
// Finish setting the allowed values and default
// value
......@@ -556,10 +553,18 @@ public class EntryComposite extends Composite implements IUpdateableListener {
setEntryValue(file.toURI().toString());
} else {
// If its just a File, import it
IClient client = ClientHolder.getClient();
client.importFile(file.toURI());
// Set the entry's value to the new file
setEntryValue(file.getName());
IClient client = null;
try {
client = IClient.getClient();
} catch (CoreException e1) {
e1.printStackTrace();
}
if (client != null) {
client.importFile(file.toURI());
// Set the entry's value to the new file
setEntryValue(file.getName());
}
}
notifyListeners(SWT.Selection, new Event());
......@@ -618,11 +623,9 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Create a MessageDialog to get whether the user
// wants to use a remote or local executable.
MessageDialog dialog = new MessageDialog(getShell(),
"Local or Remote Application", null,
MessageDialog dialog = new MessageDialog(getShell(), "Local or Remote Application", null,
"Please specify whether your executable is local or remote.",
MessageDialog.QUESTION_WITH_CANCEL,
new String[] { "Local", "Remote" }, 0);
MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Local", "Remote" }, 0);
// Launch the dialot and get the result
int result = dialog.open();
......@@ -632,8 +635,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Create a new Remote browser and set its type to
// File_Browser
RemoteResourceBrowser browser = new RemoteResourceBrowser(
getShell(), SWT.NONE);
RemoteResourceBrowser browser = new RemoteResourceBrowser(getShell(), SWT.NONE);
browser.setTitle("Select a remote executable.");
browser.setType(RemoteResourceBrowser.FILE_BROWSER);
......@@ -645,10 +647,9 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Get the selected Resource
IFileStore fs = browser.getResource();
// Get the hostname
String hostName = browser.getConnection().getService(
IRemoteConnectionHostService.class)
.getHostname();
String hostName = browser.getConnection().getService(IRemoteConnectionHostService.class)
.getHostname();
// Set up the entry value
URI uri = fs.toURI();
entryValue = uri.getScheme() + "://" + hostName + uri.getPath();
......@@ -656,8 +657,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
} else {
// If Local, just open up a file browser
FileDialog fileDialog = new FileDialog(getShell());
fileDialog.setText(
"Select an executable to import into ICE");
fileDialog.setText("Select an executable to import into ICE");
String filePath = fileDialog.open();
if (filePath != null) {
// Import the files
......@@ -744,8 +744,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// We can use Radio buttons if the allowed values are few
if (numAllowedValues <= maxShortValues && shortValues) {
// Check to see if this is something that should use a check box
if (numAllowedValues == 2 && allowedBinaryValues
.containsAll(lowercaseAllowedValues)) {
if (numAllowedValues == 2 && allowedBinaryValues.containsAll(lowercaseAllowedValues)) {
createCheckbox();
} else {
// Otherwise create the regular button set
......@@ -816,14 +815,13 @@ public class EntryComposite extends Composite implements IUpdateableListener {
Button button = buttons.get(0);
int labelWidth = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
int buttonWidth = button.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
int padding = 2 * rowLayout.spacing + rowLayout.marginLeft
+ rowLayout.marginWidth * 2 + rowLayout.marginRight + 30;
int padding = 2 * rowLayout.spacing + rowLayout.marginLeft + rowLayout.marginWidth * 2
+ rowLayout.marginRight + 30;
unwrappedWidth = labelWidth + buttonWidth + padding;
// Size the dropdown based on the currently available space.
int availableWidth = getClientArea().width - unwrappedWidth;
rowData.width = (availableWidth > minWidth ? availableWidth
: minWidth);
rowData.width = (availableWidth > minWidth ? availableWidth : minWidth);
// If necessary, remove the old resize listener.
if (resizeListener != null) {
......@@ -836,8 +834,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
@Override
public void controlResized(ControlEvent e) {
int availableWidth = getClientArea().width - unwrappedWidth;
rowData.width = (availableWidth > minWidth ? availableWidth
: minWidth);
rowData.width = (availableWidth > minWidth ? availableWidth : minWidth);
layout();
}
};
......@@ -860,8 +857,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
if (errorMessage != null) {
// Display the error at the top of the screen
if (messageManager != null) {
messageManager.addMessage(messageName, errorMessage, null,
IMessageProvider.ERROR);
messageManager.addMessage(messageName, errorMessage, null, IMessageProvider.ERROR);
}
// Highlight the text if it is in a text box
if (text != null) {
......@@ -908,8 +904,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Print an error if this Entry has been prematurely disposed.
if (isDisposed()) {
logger.info("EntryComposite Message: "
+ "This composite has been prematurely disposed!");
logger.info("EntryComposite Message: " + "This composite has been prematurely disposed!");
return;
}
......@@ -960,8 +955,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
if (errorMessage != null) {
// Display the error at the top of the screen
if (messageManager != null) {
messageManager.addMessage(messageName, errorMessage, null,
IMessageProvider.ERROR);
messageManager.addMessage(messageName, errorMessage, null, IMessageProvider.ERROR);
}
// Highlight the text if it is in a text box
if (text != null) {
......@@ -1024,8 +1018,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Toggle the "unsaved changes" decoration if the entry
// value is different
if (!EntryComposite.this.entry.getValue()
.equals(currentSelection)) {
if (!EntryComposite.this.entry.getValue().equals(currentSelection)) {
toggleSaveDecoration();
}
......@@ -1045,7 +1038,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
* This method is responsible for toggling a ControlDecoration on and off on
* the EntryComposite. The decoration will toggle on if the editor is dirty
* and the selection was recently changed (monitored by
* {@link EntryComposite#currentSelection}). Otherwise, it will toggle off.
* {@link EntryComposite#currentSelection}). Otherwise, it will toggle off.
*/
public void toggleSaveDecoration() {
......@@ -1056,15 +1049,13 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Set a description and image
decoration.setDescriptionText(saveMessage);
Image image = FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING)
Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING)
.getImage();
decoration.setImage(image);
// Set a listener to hide/show the decoration according to the
// editor's state and the current entry value
final IEditorPart editor = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
editor.addPropertyListener(new IPropertyListener() {
@Override
......@@ -1072,8 +1063,7 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// Toggle the decoration on if the form is dirty and the
// value has changed
if (editor != null) {
if (editor.isDirty() && !EntryComposite.this.entry
.getValue().equals(currentSelection)) {
if (editor.isDirty() && !EntryComposite.this.entry.getValue().equals(currentSelection)) {
// Show the decoration
EntryComposite.this.decoration.show();
} else if (!editor.isDirty()) {
......@@ -1090,12 +1080,10 @@ public class EntryComposite extends Composite implements IUpdateableListener {
// If the decoration already exists, check the Entry's state and set the
// decoration as needed.
else {
final IEditorPart editor = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (editor != null) {
if (editor.isDirty() && !EntryComposite.this.entry.getValue()
.equals(currentSelection)) {
if (editor.isDirty() && !EntryComposite.this.entry.getValue().equals(currentSelection)) {
// Show the decoration
EntryComposite.this.decoration.show();
} else if (!editor.isDirty()) {
......
......@@ -428,7 +428,7 @@ public class CoreTester {
FakeGeometryBuilder fakeGeometryBuilder = new FakeGeometryBuilder();
IProject project = null;
project = getProject("default");
project = getProject("itemDB");
// Clean out any old test files
try {
......
......@@ -935,7 +935,7 @@ public class Core extends Application implements ICore, BundleActivator {
*/
@Override
public String importFileAsItem(URI file, String itemType) {
return importFileAsItem(file, itemType, "default");
return importFileAsItem(file, itemType, "itemDB");
}
/**
......@@ -998,7 +998,7 @@ public class Core extends Application implements ICore, BundleActivator {
public void importFile(URI file) {
// Simply import the file to the default project
importFile(file, "default");
importFile(file, "itemDB");
return;
}
......
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