Commit 2aa50f3b authored by amccaskey's avatar amccaskey
Browse files

Adding Item rename capability



Added ability to rename item XML files. Updated tests accordingly. 
Signed-off-by: default avataramccaskey <mccaskeyaj@ornl.gov>
parent 40a48d5e
......@@ -260,6 +260,18 @@ public class ClientTester {
return;
}
/**
* Check that the Core gets invoked when we
* rename an Item.
*/
@Test
public void checkItemRenaming() {
int itemId = iCEClient.createItem("Red");
iCEClient.renameItem(itemId, "HELLO");
assertTrue(fakeCore.itemNameChanged());
fakeCore.reset();
}
/**
* This operation checks the Client by insuring that Items and Forms can be
* updated. It calls through the IUpdateWidgetListener interface. Review the
......
......@@ -92,6 +92,8 @@ public class FakeCore implements ICore {
*/
private boolean imported;
private boolean itemNameChanged;
/**
* <p>
* True if the client attempted to cancel an Item process request, false
......@@ -117,6 +119,7 @@ public class FakeCore implements ICore {
public FakeCore() {
lastProcessStatus = FormStatus.InfoError;
imported = false;
itemNameChanged = false;
}
/**
......@@ -148,7 +151,8 @@ public class FakeCore implements ICore {
imported = false;
cancelled = false;
loaded = false;
itemNameChanged = false;
return;
}
......@@ -579,4 +583,13 @@ public class FakeCore implements ICore {
}
return;
}
public boolean itemNameChanged() {
return itemNameChanged;
}
@Override
public void renameItem(int itemID, String name) {
itemNameChanged = true;
}
}
\ No newline at end of file
......@@ -177,6 +177,8 @@ public class ICEFormEditor extends SharedHeaderFormEditor
*/
protected ICEMeshPage meshPage;
private IManagedForm managedForm;
/**
* The Constructor
*/
......@@ -218,8 +220,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
staticLogger.info("ICEFormEditor Message: IVizServiceFactory set!");
IConfigurationElement[] elements = Platform.getExtensionRegistry()
.getConfigurationElementsFor(
"org.eclipse.ice.viz.service.IVizServiceFactory");
.getConfigurationElementsFor("org.eclipse.ice.viz.service.IVizServiceFactory");
staticLogger.info("ICEFormEditor: Available configuration elements");
for (IConfigurationElement element : elements) {
staticLogger.info(element.getName());
......@@ -250,10 +251,8 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Push a message to the message manager
if (getHeaderForm() != null) {
final IMessageManager messageManager = getHeaderForm()
.getMessageManager();
messageManager.addMessage("statusUpdate",
"There are unsaved changes on the form.", null,
final IMessageManager messageManager = getHeaderForm().getMessageManager();
messageManager.addMessage("statusUpdate", "There are unsaved changes on the form.", null,
IMessageProvider.WARNING);
}
......@@ -314,12 +313,10 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// should
// only be one output page.
if (!(componentMap.get("output").isEmpty())) {
resourceComponent = (ResourceComponent) (componentMap.get("output")
.get(0));
resourceComponent = (ResourceComponent) (componentMap.get("output").get(0));
if (resourceComponent != null) {
// Make the page
resourceComponentPage = new ICEResourcePage(this,
resourceComponent.getName(),
resourceComponentPage = new ICEResourcePage(this, resourceComponent.getName(),
resourceComponent.getName());
// Set the ResourceComponent
resourceComponentPage.setResourceComponent(resourceComponent);
......@@ -353,18 +350,15 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Get the MasterDetailsComponent and create the MasterDetails page.
if (!(componentMap.get("masterDetails").isEmpty())) {
masterDetailsComponent = (MasterDetailsComponent) (componentMap
.get("masterDetails").get(0));
masterDetailsComponent = (MasterDetailsComponent) (componentMap.get("masterDetails").get(0));
if (masterDetailsComponent != null) {
// Get the name
String name = masterDetailsComponent.getName();
// Make the page
ICEMasterDetailsPage iCEMasterDetailsPage = new ICEMasterDetailsPage(
this, "MDPid", name);
ICEMasterDetailsPage iCEMasterDetailsPage = new ICEMasterDetailsPage(this, "MDPid", name);
// Set the MasterDetailsComponent
iCEMasterDetailsPage
.setMasterDetailsComponent(masterDetailsComponent);
iCEMasterDetailsPage.setMasterDetailsComponent(masterDetailsComponent);
masterDetailsPages.add(iCEMasterDetailsPage);
}
......@@ -393,10 +387,8 @@ public class ICEFormEditor extends SharedHeaderFormEditor
public void run() {
// Post the message to the update manager
if (getHeaderForm() != null) {
final IMessageManager messageManager = getHeaderForm()
.getMessageManager();
messageManager.addMessage("statusUpdate", message, null,
IMessageProvider.INFORMATION);
final IMessageManager messageManager = getHeaderForm().getMessageManager();
messageManager.addMessage("statusUpdate", message, null, IMessageProvider.INFORMATION);
}
}
});
......@@ -417,14 +409,12 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Get the GeometryComponent and create the GeometryPage.
if (!(componentMap.get("geometry").isEmpty())) {
geometryComponent = (GeometryComponent) (componentMap
.get("geometry").get(0));
geometryComponent = (GeometryComponent) (componentMap.get("geometry").get(0));
if (geometryComponent != null) {
// Make the GeometryPage
geometryPage = new ICEGeometryPage(this, "GPid",
geometryComponent.getName());
geometryPage = new ICEGeometryPage(this, "GPid", geometryComponent.getName());
// Set the GeometryComponent
geometryPage.setGeometry(geometryComponent);
......@@ -453,8 +443,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
if (meshComponent != null) {
// Make the MeshPage
meshPage = new ICEMeshPage(this, "MeshPid",
meshComponent.getName());
meshPage = new ICEMeshPage(this, "MeshPid", meshComponent.getName());
// Set the MeshComponent
meshPage.setMeshComponent(meshComponent);
......@@ -482,8 +471,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
emfComponent = (EMFComponent) comp;
if (emfComponent != null) {
// Make the EMFSectionPage
emfPage = new EMFSectionPage(this, emfComponent.getName(),
emfComponent.getName());
emfPage = new EMFSectionPage(this, emfComponent.getName(), emfComponent.getName());
// Set the EMFComponent
emfPage.setEMFComponent(emfComponent);
pages.add(emfPage);
......@@ -515,8 +503,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// a collection
if (list != null) {
// Create a new page for the list
ListComponentSectionPage page = new ListComponentSectionPage(
this, list.getName(), list.getName());
ListComponentSectionPage page = new ListComponentSectionPage(this, list.getName(), list.getName());
page.setList(list);
// Add the page to the return list
pages.add(page);
......@@ -538,8 +525,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
if (!trees.isEmpty()) {
// Show the view
try {
getSite().getWorkbenchWindow().getActivePage()
.showView(getTreeCompositeViewerID());
getSite().getWorkbenchWindow().getActivePage().showView(getTreeCompositeViewerID());
} catch (PartInitException e) {
logger.error(getClass().getName() + " Exception!", e);
}
......@@ -562,8 +548,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
}
// Get the TreeCompositeViewer
TreeCompositeViewer treeView = (TreeCompositeViewer) getSite()
.getWorkbenchWindow().getActivePage()
TreeCompositeViewer treeView = (TreeCompositeViewer) getSite().getWorkbenchWindow().getActivePage()
.findView(getTreeCompositeViewerID());
// Set the tree as input to the tree view
treeView.setInput(tree, this);
......@@ -638,9 +623,12 @@ public class ICEFormEditor extends SharedHeaderFormEditor
@Override
protected void createHeaderContents(IManagedForm headerForm) {
// Get a reference to the IManagedForm
managedForm = headerForm;
// Get the Form that provides the common header and decorate it.
org.eclipse.ui.forms.widgets.Form form = headerForm.getForm().getForm();
headerForm.getToolkit().decorateFormHeading(form);
org.eclipse.ui.forms.widgets.Form form = managedForm.getForm().getForm();
managedForm.getToolkit().decorateFormHeading(form);
// Create a composite for the overall head layout.
Composite headClient = new Composite(form.getHead(), SWT.NONE);
......@@ -674,16 +662,15 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Create the process label, button and dropdown if the action list is
// available.
if (iceDataForm.getActionList() != null
&& !iceDataForm.getActionList().isEmpty()) {
if (iceDataForm.getActionList() != null && !iceDataForm.getActionList().isEmpty()) {
// Create a label for the process buttons
Label processLabel = new Label(headClient, SWT.NONE);
processLabel.setText("Process:");
// Create the dropdown menu
processDropDown = new Combo(headClient, SWT.DROP_DOWN | SWT.SINGLE
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
processDropDown = new Combo(headClient,
SWT.DROP_DOWN | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
for (String i : iceDataForm.getActionList()) {
processDropDown.add(i);
}
......@@ -695,8 +682,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
@Override
public void widgetSelected(SelectionEvent e) {
// Set the action value to use when processing
processName = processDropDown
.getItem(processDropDown.getSelectionIndex());
processName = processDropDown.getItem(processDropDown.getSelectionIndex());
}
});
......@@ -780,8 +766,8 @@ public class ICEFormEditor extends SharedHeaderFormEditor
if (numComponents == 1) {
pageName = ((ICEObject) (comps.get(0))).getName();
} else {
pageName = ((ICEObject) (comps.get(0))).getName() + ", "
+ ((ICEObject) (comps.get(1))).getName() + ", etc.";
pageName = ((ICEObject) (comps.get(0))).getName() + ", " + ((ICEObject) (comps.get(1))).getName()
+ ", etc.";
}
// Instantiate the page
tmpPage = new ICESectionPage(this, pageName, pageName);
......@@ -794,12 +780,11 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Otherwise, if there are more components than the number of
// components per page, add them all with numCompsPerPage Components
// per page. This loop adds all of the full pages.
for (i = 0; i < (numComponents / numCompsPerPage)
* numCompsPerPage; i = i + numCompsPerPage) {
for (i = 0; i < (numComponents / numCompsPerPage) * numCompsPerPage; i = i + numCompsPerPage) {
// Set a name for the page that is a combination of the first
// two components
pageName = ((ICEObject) (comps.get(i))).getName() + ", "
+ ((ICEObject) (comps.get(i + 1))).getName() + ", etc.";
pageName = ((ICEObject) (comps.get(i))).getName() + ", " + ((ICEObject) (comps.get(i + 1))).getName()
+ ", etc.";
// Create the page
tmpPage = new ICESectionPage(this, pageName, pageName);
// Add the components
......@@ -819,8 +804,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
pageName = ((ICEObject) (comps.get(i))).getName();
} else {
pageName = ((ICEObject) (comps.get(i))).getName() + ", "
+ ((ICEObject) (comps.get(i + 1))).getName()
+ ", etc.";
+ ((ICEObject) (comps.get(i + 1))).getName() + ", etc.";
}
// Create the page
tmpPage = new ICESectionPage(this, pageName, pageName);
......@@ -847,8 +831,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
* the input for this editor
*/
@Override
public void init(IEditorSite site, IEditorInput input)
throws RuntimeException {
public void init(IEditorSite site, IEditorInput input) throws RuntimeException {
// Set the part name
setPartName(input.getName());
......@@ -881,10 +864,12 @@ public class ICEFormEditor extends SharedHeaderFormEditor
} else {
// Throw errors if the type is wrong
logger.error("Unable to load Form Editor!");
throw new RuntimeException("Input passed to ICEFormEditor.init()"
+ " is not of type ICEFormInput or FileEditorInput.");
throw new RuntimeException(
"Input passed to ICEFormEditor.init()" + " is not of type ICEFormInput or FileEditorInput.");
}
iceDataForm.register(this);
return;
}
......@@ -931,8 +916,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
}
// Refresh the parts on the selected page
for (IFormPart part : ((ICEFormPage) this.getSelectedPage())
.getManagedForm().getParts()) {
for (IFormPart part : ((ICEFormPage) this.getSelectedPage()).getManagedForm().getParts()) {
part.refresh();
}
......@@ -946,8 +930,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Get the first MasterDetailsComponent (The current code only
// allows one master details to be implemented at this time
MasterDetailsComponent comp = (MasterDetailsComponent) (componentMap
.get("masterDetails").get(0));
MasterDetailsComponent comp = (MasterDetailsComponent) (componentMap.get("masterDetails").get(0));
// Get the name of the component
String name = comp.getName();
......@@ -979,8 +962,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
if (!(componentMap.get("emf")).isEmpty()) {
for (int i = 0; i < this.getPageCount(); i++) {
FormPage formPage = (FormPage) this.pages.get(i);
EMFComponent comp = (EMFComponent) componentMap.get("emf")
.get(0);
EMFComponent comp = (EMFComponent) componentMap.get("emf").get(0);
if (formPage.getPartName().equals(comp.getName())) {
formPage.doSave(null);
}
......@@ -1030,14 +1012,12 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Loop over the components and get them into the map
for (Component i : iceDataForm.getComponents()) {
logger.info("ICEFormEditor Message: Adding component "
+ i.getName() + " " + i.getId());
logger.info("ICEFormEditor Message: Adding component " + i.getName() + " " + i.getId());
i.accept(this);
}
// Create pages for the DataComponents and add them to the list
if (!(componentMap.get("data").isEmpty())
|| !(componentMap.get("table").isEmpty())
if (!(componentMap.get("data").isEmpty()) || !(componentMap.get("table").isEmpty())
|| !(componentMap.get("matrix").isEmpty())) {
formPages.addAll(createDataTableAndMatrixComponentPages());
}
......@@ -1076,8 +1056,7 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Create the page for Reactors
if (!(componentMap.get("reactor").isEmpty())) {
logger.info("ICEFormEditor Message: "
+ componentMap.get("reactor").size()
logger.info("ICEFormEditor Message: " + componentMap.get("reactor").size()
+ " IReactorComponents not rendered.");
}
......@@ -1337,6 +1316,24 @@ public class ICEFormEditor extends SharedHeaderFormEditor
@Override
public void update(IUpdateable component) {
// Check if this is the Form
if (component instanceof Form) {
// We only registered with the form
// to get updates for name changes, so update the name
// on the header form
// Sync with the display
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
managedForm.getForm().getForm().setText(iceDataForm.getName() + " " + iceDataForm.getId());
managedForm.getForm().getForm().redraw();
}
});
return;
}
// Sync with the display
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
......
......@@ -71,4 +71,21 @@
</enablement>
</deleteParticipant>
</extension>
<extension
point="org.eclipse.ltk.core.refactoring.renameParticipants">
<renameParticipant
class="org.eclipse.ice.client.common.ICEItemRenameParticipant"
id="org.eclipse.ice.client.renameitem"
name="Rename Item Action">
<enablement>
<with variable="element">
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.extension"
value="xml">
</test>
</adapt>
</with>
</enablement>
</renameParticipant>
</extension>
</plugin>
......@@ -11,9 +11,7 @@
*******************************************************************************/
package org.eclipse.ice.client.common;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
......@@ -25,7 +23,6 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.ITextContentDescriber;
import org.eclipse.ice.datastructures.form.FormTextContentDescriber;
import org.eclipse.ice.iclient.IClient;
import org.eclipse.ice.item.ItemBuilder;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
......@@ -173,7 +170,7 @@ public class ICEItemDeleteParticipant extends DeleteParticipant {
*/
@Override
public String getName() {
return "Delete ICE XML File Participant";
return "ICE Item Delete Participant";
}
/*
......
/*******************************************************************************
* 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 -
* Alexander J. McCaskey
*******************************************************************************/
package org.eclipse.ice.client.common;
import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.ITextContentDescriber;
import org.eclipse.ice.datastructures.form.FormTextContentDescriber;
import org.eclipse.ice.iclient.IClient;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class subclasses the RenameParticipant class from the Eclipse Language
* Toolkit to provide a hook for correctly renaming ICE Item XML files.
*
* @author Alex McCaskey
*
*/
public class ICEItemRenameParticipant extends RenameParticipant {
/**
* Logger for handling event messages and other information.
*/
private static final Logger logger = LoggerFactory.getLogger(ICEItemDeleteParticipant.class);
/**
* Reference to the Item ID if the provided file is an ICE XML Item file.
*/
private int itemID;
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#
* initialize(java.lang.Object)
*/
@Override
protected boolean initialize(Object element) {
// Local Declarations
IFile itemFile = null;
// See if we can cast to an IFile,
// if not we do nothing
if (element instanceof IFile) {
itemFile = (IFile) element;
}
// If this is an IFile
if (itemFile != null) {
// Get the ICE Form Text Content Describer
FormTextContentDescriber describer = getFormTextContentDescriber("ICE Form");
try {
// Check if this is an ICE XML File
int isValid = describer.describe(itemFile.getContents(), null);
// If so, get the itemID and return true to
// indicate we want to participate in the deletion
if (isValid == ITextContentDescriber.VALID) {
itemID = describer.getItemID();
return true;
} else {
return false;
}
} catch (IOException | CoreException e1) {
logger.error("Could not describe the provided file.", e1);
return false;
}
}
// Indicate we don't need to do anythin
// with this element
return false;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#
* createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
// If we've made it here, we have a valid ICE XML Item
// to delete and we've collected its Item ID.
// So grab the client...
IClient client = null;
try {
client = IClient.getClient();
} catch (CoreException e) {
logger.error("Could not get a reference to the client.", e);
}
// Then use the client to rename the Item.
if (client != null) {
String newName = getArguments().getNewName();
client.renameItem(itemID, newName.substring(0, newName.lastIndexOf(".")));
}
return null;
}
/**
* This utility method is used to return the correct ITextContentDescriber
* so we can validate incoming IFiles being deleted as true ICE Item files.
*
* @param type
* @return
*/
private FormTextContentDescriber getFormTextContentDescriber(String type) {
// Local Declarations
FormTextContentDescriber describer = null;
String id = "org.eclipse.core.contenttype.contentTypes";
// Get the extension point
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(id);