Commit a402c4f6 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Fixed my project creation bug.


Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 13490cfe
......@@ -180,6 +180,7 @@
</plugin>
</plugins>
<!-- This configured git support for examining the bundles and only updating the versions if they change. -->
<pluginManagement>
<plugins>
<plugin>
......
......@@ -34,17 +34,18 @@ import org.slf4j.LoggerFactory;
/**
* This class provides an Eclipse view showing the list of Items that have been
* created and made available in the Core.
*
*
* @author Jay Jay Billings
*
*
*/
public class ItemViewer extends ViewPart {
/**
* Logger for handling event messages and other information.
*/
private static final Logger logger = LoggerFactory.getLogger(ItemViewer.class);
private static final Logger logger = LoggerFactory
.getLogger(ItemViewer.class);
/**
* The id
*/
......@@ -96,7 +97,7 @@ public class ItemViewer extends ViewPart {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.error(getClass().getName() + " Exception!",e);
logger.error(getClass().getName() + " Exception!", e);
}
}
// Sync with the display
......@@ -227,7 +228,8 @@ public class ItemViewer extends ViewPart {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
logger.error(getClass().getName() + " Exception!",e);
logger.error(getClass().getName() + " Exception!",
e);
}
}
}
......@@ -240,7 +242,7 @@ public class ItemViewer extends ViewPart {
/**
* A simple pass-through for setting the focus. It does nothing.
*
*
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
@Override
......
......@@ -13,6 +13,8 @@
package org.eclipse.ice.client.common.wizards;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.ice.client.common.internal.ClientHolder;
import org.eclipse.ice.iclient.IClient;
import org.eclipse.jface.dialogs.MessageDialog;
......@@ -30,9 +32,9 @@ import org.eclipse.ui.IWorkbenchWindow;
* {@code org.eclipse.ui.newWizards} extension in the plugin (for adding it to
* the workbench new wizards).
* </p>
*
*
* @author Jay Jay Billings, Jordan Deyton
*
*
*/
public class NewItemWizard extends Wizard implements INewWizard {
......@@ -46,6 +48,11 @@ public class NewItemWizard extends Wizard implements INewWizard {
*/
protected IWorkbenchWindow workbenchWindow;
/**
* The project selected when the wizard was used.
*/
protected IProject project;
/**
* A nullary constructor. This is used by the platform. <b>If called from an
* {@link IHandler}, use {@link #NewItemWizard(IWorkbenchWindow)} </b>.
......@@ -57,7 +64,7 @@ public class NewItemWizard extends Wizard implements INewWizard {
/**
* The default constructor. This is not normally called by the platform but
* via handlers.
*
*
* @param window
* The workbench window.
*/
......@@ -74,12 +81,20 @@ public class NewItemWizard extends Wizard implements INewWizard {
*/
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
// Save the window
workbenchWindow = workbench.getActiveWorkbenchWindow();
// Get and save the project. This just casts to IResource since
// IProjects are IResources and doing otherwise would require additional
// checks.
Object element = selection.getFirstElement();
if (element instanceof IResource) {
project = ((IResource) element).getProject();
}
}
/*
* (non-Javadoc)
*
*
* @see org.eclipse.jface.wizard.Wizard#addPages()
*/
@Override
......@@ -92,7 +107,7 @@ public class NewItemWizard extends Wizard implements INewWizard {
/*
* (non-Javadoc)
*
*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
......@@ -112,7 +127,7 @@ public class NewItemWizard extends Wizard implements INewWizard {
// Direct the client to create a new Item if a selection was made
if (selectedItem != null) {
finished = client.createItem(selectedItem) > 0;
finished = client.createItem(selectedItem, project) > 0;
}
} else {
......
......@@ -41,9 +41,9 @@ import org.eclipse.swt.widgets.MessageBox;
/**
* This class provides the main page for the {@link NewItemWizard}. It includes
* a <code>ListViewer</code> of available <code>Item</code> types.
*
*
* @author Jay Jay Billings, Jordan
*
*
*/
public class NewItemWizardPage extends WizardPage {
......@@ -59,7 +59,7 @@ public class NewItemWizardPage extends WizardPage {
/**
* The default constructor.
*
*
* @param pageName
* The name of the page.
*/
......@@ -72,7 +72,7 @@ public class NewItemWizardPage extends WizardPage {
/**
* This operation returns the selected Item name.
*
*
* @return the selected Item name
*/
public String getSelectedItem() {
......@@ -81,7 +81,7 @@ public class NewItemWizardPage extends WizardPage {
/**
* This operation returns true if an Item has been selected.
*
*
* @return True if an Item has been selected, false otherwise.
*/
private boolean checkSelection() {
......@@ -101,127 +101,142 @@ public class NewItemWizardPage extends WizardPage {
// Get the client
IClient client = ClientHolder.getClient();
// Create the composite for file selection pieces
Composite itemSelectionComposite = new Composite(parentComposite,
SWT.NONE);
// Set its layout
GridLayout layout = new GridLayout(1, true);
itemSelectionComposite.setLayout(layout);
// Set its layout data
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
itemSelectionComposite.setLayoutData(data);
// Only create the wizard if the client is available
if (client != null) {
// Create the composite for file selection pieces
Composite itemSelectionComposite = new Composite(parentComposite,
SWT.NONE);
// Set its layout
GridLayout layout = new GridLayout(1, true);
itemSelectionComposite.setLayout(layout);
// Set its layout data
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
itemSelectionComposite.setLayoutData(data);
// Get the list of available Items from the client
final List<String> itemTypeList = client.getAvailableItemTypes();
// Sort the list so that items are displayed lexographically.
Collections.sort(itemTypeList);
// Create the item selection label
Label itemLabel = new Label(itemSelectionComposite, SWT.NONE);
itemLabel.setText("Please select an Item type.");
// Add the list for selecting an Item
ListViewer itemListViewer = new ListViewer(itemSelectionComposite,
SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
// Set the layout data so that it fills the space
data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
itemListViewer.getControl().setLayoutData(data);
// Add the label provider for the list viewer
itemListViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return (String) element;
}
});
// Add the content provider for the list viewer
itemListViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {
// Nothing to do
}
// Draw the list of Items and present the selection wizard.
drawWizard(itemSelectionComposite, client);
} else {
// Otherwise throw an error
MessageBox errorMessage = new MessageBox(parent.getShell(), ERROR);
errorMessage.setMessage("The ICE Client is not available. "
+ "Please file a bug report.");
errorMessage.open();
}
@Override
public void dispose() {
// Nothing to do
}
// Set the control
setControl(itemSelectionComposite);
// Disable the finished condition to start
setPageComplete(false);
@Override
public Object[] getElements(Object inputElement) {
return ((List<?>) inputElement).toArray();
}
});
// Create the selection listener
itemListViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// Get and store the selection
String selection = (String) ((IStructuredSelection) event
.getSelection()).getFirstElement();
if (selection != null) {
selectedItemType = selection;
}
// Validate the file and Item selection to enable
// the finish button
NewItemWizardPage.this
.setPageComplete(checkSelection());
return;
}
/**
* This operation draws the wizard on the screen.
*
* @param itemSelectionComposite
* The composite that should hold the contents of the wizard
* @param client
* The ICE Client
*/
private void drawWizard(Composite itemSelectionComposite, IClient client) {
// Get the list of available Items from the client
final List<String> itemTypeList = client.getAvailableItemTypes();
// Sort the list so that items are displayed lexographically.
Collections.sort(itemTypeList);
// Create the item selection label
Label itemLabel = new Label(itemSelectionComposite, SWT.NONE);
itemLabel.setText("Please select an Item type.");
// Add the list for selecting an Item
ListViewer itemListViewer = new ListViewer(itemSelectionComposite,
SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
// Set the layout data so that it fills the space
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
itemListViewer.getControl().setLayoutData(data);
// Add the label provider for the list viewer
itemListViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return (String) element;
}
});
// Add the content provider for the list viewer
itemListViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {
// Nothing to do
}
@Override
public void dispose() {
// Nothing to do
}
@Override
public Object[] getElements(Object inputElement) {
return ((List<?>) inputElement).toArray();
}
});
// Create the selection listener
itemListViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// Get and store the selection
String selection = (String) ((IStructuredSelection) event
.getSelection()).getFirstElement();
if (selection != null) {
selectedItemType = selection;
}
});
// Set the input to the list from the client
itemListViewer.setInput(itemTypeList);
// Add a double-click listener to the ListViewer. If the file was
// already selected, then a double-click can advance or finish the
// wizard.
itemListViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
// If the page is complete, we can try to finish the wizard.
if (isPageComplete()) {
// Get the wizard and its container.
IWizard wizard = getWizard();
IWizardContainer container = wizard.getContainer();
// If the container is a WizardDialog, we can try to
// finish the wizard and close the dialog.
if (container instanceof WizardDialog) {
if (wizard.performFinish()) {
((WizardDialog) container).close();
}
// Validate the file and Item selection to enable
// the finish button
NewItemWizardPage.this
.setPageComplete(checkSelection());
}
});
// Set the input to the list from the client
itemListViewer.setInput(itemTypeList);
// Add a double-click listener to the ListViewer. If the file was
// already selected, then a double-click can advance or finish the
// wizard.
itemListViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
// If the page is complete, we can try to finish the wizard.
if (isPageComplete()) {
// Get the wizard and its container.
IWizard wizard = getWizard();
IWizardContainer container = wizard.getContainer();
// If the container is a WizardDialog, we can try to
// finish the wizard and close the dialog.
if (container instanceof WizardDialog) {
if (wizard.performFinish()) {
((WizardDialog) container).close();
}
// Otherwise, we can try to advance to the next page if
// one exists.
else {
// Get the next page.
IWizardPage nextPage = wizard
.getNextPage(NewItemWizardPage.this);
// If it exists, move to it.
if (nextPage != null) {
container.showPage(nextPage);
}
}
// Otherwise, we can try to advance to the next page if
// one exists.
else {
// Get the next page.
IWizardPage nextPage = wizard
.getNextPage(NewItemWizardPage.this);
// If it exists, move to it.
if (nextPage != null) {
container.showPage(nextPage);
}
}
return;
}
});
// Set the control
setControl(itemSelectionComposite);
// Disable the finished condition to start
setPageComplete(false);
// Otherwise throw an error
} else {
MessageBox errorMessage = new MessageBox(parent.getShell(), ERROR);
errorMessage.setMessage("The ICE Client is not available. "
+ "Please file a bug report.");
}
return;
return;
}
});
}
......
......@@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.resources.IProject;
import org.eclipse.ice.client.common.internal.ClientHolder;
import org.eclipse.ice.core.iCore.ICore;
import org.eclipse.ice.datastructures.ICEObject.Identifiable;
......@@ -283,16 +284,43 @@ public class Client implements IUpdateEventListener, IProcessEventListener,
// Create the Item
itemId = Integer.valueOf(getCore().createItem(itemType));
// Load the Item into the editor
loadAfterCreate(itemId);
return itemId;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.iclient.IClient#createItem(java.lang.String,
* org.eclipse.core.resources.IProject)
*/
@Override
public int createItem(String itemType, IProject project) {
// Local Declarations
int itemId = -1;
// Create the Item
itemId = Integer.valueOf(getCore().createItem(itemType, project));
// Load the Item into the editor
loadAfterCreate(itemId);
return itemId;
}
private void loadAfterCreate(int itemId) {
// FIXME - Get the status! Need ItemStatus type or something
// Either load the Item or throw an error
if (itemId > 0) {// FIXME Status check!
loadItem(itemId);
} else if (itemId <= 0) {
throwSimpleError("Unable to create Item of type " + itemType + ".");
throwSimpleError("Unable to load Item " + itemId
+ " after creating it.");
}
return itemId;
}
/**
......
/*******************************************************************************
* Copyright (c) 2012, 2014 UT-Battelle, LLC.
* 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:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
* Copyright (c) 2012, 2014 UT-Battelle, LLC.
* 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:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.iclient;
import java.net.URI;
import java.util.ArrayList;
import org.eclipse.core.resources.IProject;
import org.eclipse.ice.core.iCore.ICore;
import org.eclipse.ice.datastructures.ICEObject.Identifiable;
import org.eclipse.ice.iclient.uiwidgets.IWidgetFactory;
/**
* <p>IClient is an interface that must be realized by clients of ICE. It describes the possible interactions between the Eclipse User and ICE.</p>
/**
* <p>
* IClient is an interface that must be realized by clients of ICE. It describes
* the possible interactions between the Eclipse User and ICE.
* </p>
*
* @author Jay Jay Billings
*/
public interface IClient {
/**
* <p>This operation retrieves a representation of the file system from the Core.</p>
* @return <p>A hierarchical list of the workspace directories available to the Eclipse User.</p>
/**
* <p>
* This operation retrieves a representation of the file system from the
* Core.
* </p>
*
* @return <p>
* A hierarchical list of the workspace directories available to the
* Eclipse User.
* </p>
*/
public Object getFileSystem();
/**
* <p>A setter for the OSGI Core service. This setter is used to register the ICore with the client. It should be used to set the service when the intention is to run the client in "local-only" mode.</p>
/**
* <p>
* A setter for the OSGI Core service. This setter is used to register the
* ICore with the client. It should be used to set the service when the
* intention is to run the client in "local-only" mode.
* </p>
*
* @param core
*/
public void setCoreService(ICore core);
/**
* <p>This operation directs ICE to create a new Item. If the Item is successfully created, it returns the identification number of the new Item and launches a UIWidget to gather additional information if needed. </p>
* @param itemType <p>The type of Item to create.</p>
* @return <p>The identification number of the new Item.</p>
/**
* This operation directs ICE to create a new Item. If the Item is
* successfully created, it returns the identification number of the new
* Item and launches a UIWidget to gather additional information if needed.
*
* @param itemType
* The type of Item to create.
* @return The identification number of the new Item.
*/
public int createItem(String itemType);
/**
* <p>This operation sets the factory that must be used to create widgets for the UI system that is used in the client implementation.</p>
/**
* This operation directs ICE to create a new Item. If the Item is
* successfully created, it returns the identification number of the new
* Item and launches a UIWidget to gather additional information if needed.
*
* @param itemType
* The type of Item to create.