1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 07:05:24 +02:00

[222829] [useractions] MoveUp/Down Broken in Work with User Actions Dialog

This commit is contained in:
Kevin Doyle 2008-08-13 19:08:07 +00:00
parent 12ee882ba1
commit 33f5ea9a40
3 changed files with 161 additions and 25 deletions

View file

@ -10,6 +10,7 @@ package org.eclipse.rse.internal.useractions.ui.uda;
* Contributors:
* IBM Corporation - initial API and implementation
* Xuan Chen (IBM) - [222263] Need to provide a PropertySet Adapter for System Team View (cleanup some use action stuff)
* Kevin Doyle (IBM) - [222829] MoveUp/Down Broken in Work with User Actions Dialog
*******************************************************************************/
/**
* @author coulthar
@ -34,22 +35,26 @@ public interface ISystemUDAConstants {
* or for iSeries "Object" and "Member" domains
*/
public static final String XE_DOMAIN = "Domain"; //$NON-NLS-1$
/**
* The name of the xml attribute of domain tags which
* identifies the domain type. Its values will be
* an untranslated name like "Object" or "Folder".
*/
public static final String XE_DOMTYPE = "DomainType"; //$NON-NLS-1$
/**
* The name of the xml attribute of domain tags which
* identifies the domain name. Its values will be
* a translated name like "Object" or "Folder".
*/
public static final String XE_DOMNAME = "name"; //$NON-NLS-1$
/**
* The name of the attribute we consistently use to store an element's name
*/
public static final String NAME_ATTR = "name"; //$NON-NLS-1$
/**
* The type of the attribute we consistently use to store an element's name
*/
@ -59,6 +64,12 @@ public interface ISystemUDAConstants {
* The name of the attribute we consistently use to store an element's original IBM-supplied name
*/
public static final String ORIGINAL_NAME_ATTR = "OriginalName"; //$NON-NLS-1$
/**
* The position in the list of other user actions a user action should show up in
*/
public static final String ORDER_ATTR = "Order"; //$NON-NLS-1$
/**
* The name of the attribute we consistently use to store a release number
*/

View file

@ -16,6 +16,7 @@
* Kevin Doyle (IBM) - [222828] Icons for some Actions Missing
* Kevin Doyle (IBM) - [240725] Add Null Pointer checking when there are no default user actions
* Kevin Doyle (IBM) - [239702] Copy/Paste doesn't work with User Defined Actions and Named Types
* Kevin Doyle (IBM) - [222829] MoveUp/Down Broken in Work with User Actions Dialog
*******************************************************************************/
package org.eclipse.rse.internal.useractions.ui.uda;
@ -34,6 +35,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.SystemResourceManager;
import org.eclipse.rse.core.model.IProperty;
import org.eclipse.rse.core.model.IPropertySet;
import org.eclipse.rse.core.model.IPropertySetContainer;
import org.eclipse.rse.core.model.ISystemProfile;
@ -666,19 +668,31 @@ public abstract class SystemUDBaseManager implements IResourceChangeListener, IS
IPropertySet element = elementWrapper.getElement();
IPropertySetContainer parentElement = element.getContainer();
IPropertySet[] allChildren = parentElement.getPropertySets();
for (int i = 0; i < allChildren.length; ++i)
IPropertySet elementBelow = null;
int elementOrder = getOrder(element);
// Find the element whose order index is 1 more then the current element
for (int i = 0; i < allChildren.length && elementBelow == null; ++i)
{
if (allChildren[i] == element)
{
if (i < allChildren.length - 1) //not the last one
{
allChildren[i] = allChildren[i+1];
allChildren[i+1] = element;
}
}
// Get the order attribute of the current property set
int order = getOrder(allChildren[i]);
// Compare to the current elements order attribute
if (order != -1 && (elementOrder + 1) == order)
elementBelow = allChildren[i];
}
saveUserData(elementWrapper.getProfile());
return true;
// Swap the order for the 2 elements
if (elementBelow != null) {
elementBelow.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(elementOrder));
element.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(elementOrder + 1));
// Save User Data
setProfileIndexedInstanceVariable_hasChanged(elementWrapper.getProfile(), true);
saveUserData(elementWrapper.getProfile());
return true;
}
return false;
}
/**
@ -690,19 +704,30 @@ public abstract class SystemUDBaseManager implements IResourceChangeListener, IS
IPropertySet element = elementWrapper.getElement();
IPropertySetContainer parentElement = element.getContainer();
IPropertySet[] allChildren = parentElement.getPropertySets();
for (int i = 0; i < allChildren.length; ++i)
IPropertySet elementAbove = null;
int elementOrder = getOrder(element);
for (int i = 0; i < allChildren.length && elementAbove == null; ++i)
{
if (allChildren[i] == element)
{
if (i > 0) //not the first one
{
allChildren[i] = allChildren[i-1];
allChildren[i-1] = element;
}
}
// Get the order attribute of the current property set
int order = getOrder(allChildren[i]);
// Compare to the current elements order attribute
if (order != -1 && (elementOrder - 1) == order)
elementAbove = allChildren[i];
}
saveUserData(elementWrapper.getProfile());
return true;
// Swap the order for the 2 elements
if (elementAbove != null) {
elementAbove.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(elementOrder));
element.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(elementOrder - 1));
// Save User Data
setProfileIndexedInstanceVariable_hasChanged(elementWrapper.getProfile(), true);
saveUserData(elementWrapper.getProfile());
return true;
}
return false;
}
/**
@ -760,11 +785,28 @@ public abstract class SystemUDBaseManager implements IResourceChangeListener, IS
if (selectedElementWrapper.isDomain()) {
parentElement = selectedElement;
IPropertySet[] allChildren = parentElement.getPropertySets();
currentNodeClone.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(allChildren.length));
parentElement.addPropertySet(currentNodeClone);
pastedElement = currentNodeClone;
} else {
parentElement = selectedElement.getContainer();
//TODO - Xuan: need to take care of order here.
IPropertySet[] allChildren = parentElement.getPropertySets();
IPropertySet elementBelow = null;
int elementOrder = getOrder(selectedElement);
for (int i = 0; i < allChildren.length && elementBelow == null; ++i)
{
// Get the order attribute of the current property set
int order = getOrder(allChildren[i]);
// Increment the order value for each property set greater then the current element's as we
// insert the new pasted element right below the selected
if (order > elementOrder) {
allChildren[i].addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(order + 1));
}
}
currentNodeClone.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(elementOrder + 1));
parentElement.addPropertySet(currentNodeClone);
pastedElement = currentNodeClone;
}
@ -1014,6 +1056,12 @@ public abstract class SystemUDBaseManager implements IResourceChangeListener, IS
}
child.addProperty(ISystemUDAConstants.NAME_ATTR, uppercaseName() ? name.toUpperCase() : name);
child.addProperty(ISystemUDAConstants.TYPE_ATTR, getTagName());
// Set the Order
IPropertySetContainer parentElement = child.getContainer();
IPropertySet[] allChildren = parentElement.getPropertySets();
child.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(allChildren.length - 1)); // -1 the length because we are already part of the child list
SystemXMLElementWrapper newElementWrapper = null;
newElementWrapper = createElementWrapper(child, profile, domain);
@ -1287,4 +1335,15 @@ public abstract class SystemUDBaseManager implements IResourceChangeListener, IS
}
return false;
}
private int getOrder(IPropertySet elm) {
IProperty orderProperty = elm.getProperty(ISystemUDAConstants.ORDER_ATTR);
int order = -1;
if (orderProperty != null)
{
order = Integer.valueOf(orderProperty.getValue()).intValue();
}
return order;
}
}

View file

@ -10,6 +10,7 @@
* Martin Oberhuber (Wind River) - [180562][api] dont implement ISystemUDAConstants
* Xuan Chen (IBM) - [222263] Need to provide a PropertySet Adapter for System Team View (cleanup some use action stuff)
* Kevin Doyle (IBM) - [240725] Add Null Pointer checking when there are no default user actions
* Kevin Doyle (IBM) - [222829] MoveUp/Down Broken in Work with User Actions Dialog
*******************************************************************************/
package org.eclipse.rse.internal.useractions.ui.uda;
@ -20,6 +21,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.rse.core.model.IProperty;
import org.eclipse.rse.core.model.IPropertySet;
import org.eclipse.rse.core.model.IPropertySetContainer;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.swt.graphics.Image;
@ -204,6 +206,24 @@ public abstract class SystemXMLElementWrapper implements IAdaptable {
setAttribute(ISystemUDAConstants.NAME_ATTR, s);
setUserChanged(true);
}
/**
* Return the value of this node's "order" attribute
*/
public int getOrder() {
IProperty orderProperty = elm.getProperty(ISystemUDAConstants.ORDER_ATTR);
int order = -1;
if (orderProperty != null)
{
order = Integer.valueOf(orderProperty.getValue()).intValue();
}
return order;
}
public void setOrder(int order) {
elm.addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(order));
}
/**
* For IBM-supplied elements that have been edited, returns the original IBM-supplied name
@ -283,7 +303,25 @@ public abstract class SystemXMLElementWrapper implements IAdaptable {
public void deleteElement() {
// Not intended for root. Only for Actions
//elm.getParentNode().removeChild(elm);
int elmOrder = getOrder();
elm.getContainer().removePropertySet(elm.getName());
IPropertySetContainer parentElement = elm.getContainer();
IPropertySet[] allChildren = parentElement.getPropertySets();
for (int i = 0; i < allChildren.length; i++) {
IProperty orderProperty = allChildren[i].getProperty(ISystemUDAConstants.ORDER_ATTR);
int order = -1;
if (orderProperty != null)
{
order = Integer.valueOf(orderProperty.getValue()).intValue();
}
// Decrease the order of all elements greater then elmOrder
if (order > elmOrder) {
allChildren[i].addProperty(ISystemUDAConstants.ORDER_ATTR, Integer.toString(order - 1));
}
}
}
/**
@ -426,6 +464,7 @@ public abstract class SystemXMLElementWrapper implements IAdaptable {
*/
public static Vector getChildren(Vector children, IPropertySet parentElement, IPropertySet xdoc, ISystemProfile profile, ISystemXMLElementWrapperFactory factory, int domain) {
if (children == null) children = new Vector();
Vector ordered = new Vector();
String tagName = factory.getTagName();
IPropertySet[] subList = null;
@ -434,15 +473,42 @@ public abstract class SystemXMLElementWrapper implements IAdaptable {
else if (xdoc != null)
subList = xdoc.getPropertySets();
if (subList != null) {
Vector unordered = new Vector();
for (int idx = 0; idx < subList.length; idx++) {
IPropertySet sn = subList[idx];
if (sn.getPropertyValue(ISystemUDAConstants.TYPE_ATTR).equals(tagName))
{
SystemXMLElementWrapper thisWrapper = factory.createElementWrapper(sn, profile, domain);
children.add(thisWrapper);
unordered.add(sn);
}
} // end for all subnodes
ordered.setSize(unordered.size());
for (int i = 0; i < unordered.size(); i++) {
int order = i;
// get the ordering
IPropertySet sn = ((IPropertySet) unordered.get(i));
IProperty orderProperty = sn.getProperty(ISystemUDAConstants.ORDER_ATTR);
if (orderProperty != null) {
order = Integer.valueOf(orderProperty.getValue()).intValue();
}
SystemXMLElementWrapper thisWrapper = factory.createElementWrapper(sn, profile, domain);
try {
ordered.remove(order);
ordered.add(order, thisWrapper);
} catch (Exception e) {
e.printStackTrace();
}
}
} // end if sublist != null
// Set the order position of all attributes to handle 3.0 where we didn't have the order attribute
for (int i = 0; i < ordered.size(); i++) {
if (ordered.get(i) instanceof SystemXMLElementWrapper) {
SystemXMLElementWrapper element = (SystemXMLElementWrapper) ordered.get(i);
if (element != null)
element.setOrder(i);
}
children.add(ordered.get(i));
}
return children;
}