mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 02:15:31 +02:00
[176577] wrong enablement of "Move up/down" in connection context menu
fix and unit tests
This commit is contained in:
parent
8c7aef9f65
commit
d12987030d
2 changed files with 243 additions and 59 deletions
|
@ -22,9 +22,12 @@
|
||||||
|
|
||||||
package org.eclipse.rse.internal.core.model;
|
package org.eclipse.rse.internal.core.model;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.eclipse.rse.core.IRSESystemType;
|
import org.eclipse.rse.core.IRSESystemType;
|
||||||
import org.eclipse.rse.core.IRSEUserIdConstants;
|
import org.eclipse.rse.core.IRSEUserIdConstants;
|
||||||
|
@ -406,68 +409,83 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move existing connections a given number of positions in the same pool.
|
* Move existing hosts a given number of positions in the same pool.
|
||||||
* If the delta is negative, they are all moved up by the given amount. If
|
* If the delta is negative, they are all moved up (left) by the given amount. If
|
||||||
* positive, they are all moved down by the given amount.<p>
|
* positive, they are all moved down (right) by the given amount.<p>
|
||||||
* <ul>
|
* After the move, the pool containing the moved host is committed.
|
||||||
* <li>After the move, the pool containing the moved connection is saved to disk.
|
* @param hosts an Array of hosts to move, can be empty but must not be null.
|
||||||
* <li>The connection's alias name must be unique in pool.
|
* @param delta the amount by which to move the hosts
|
||||||
* </ul>
|
*/
|
||||||
* <b>TODO PROBLEM: CAN'T RE-ORDER FOLDERS SO CAN WE SUPPORT THIS ACTION?</b>
|
public void moveHosts(IHost hosts[], int delta) {
|
||||||
* @param conns Array of SystemConnections to move.
|
/*
|
||||||
* @param delta the amount by which to move the connections
|
* Determine the indices of the supplied hosts in this pool.
|
||||||
*/
|
* If the delta is positive this list should be in descending order,
|
||||||
public void moveHosts(IHost conns[], int delta)
|
* if negative, the list should be in ascending oder.
|
||||||
{
|
*/
|
||||||
int[] oldPositions = new int[conns.length];
|
final int m = (delta > 0) ? -1 : 1; // modifier that determines the ordering
|
||||||
for (int idx=0; idx<conns.length; idx++)
|
SortedSet indices = new TreeSet(new Comparator() {
|
||||||
oldPositions[idx] = getHostPosition(conns[idx]);
|
public int compare(Object o1, Object o2) {
|
||||||
if (delta > 0) // moving down, process backwards
|
return m * ((Integer)o1).compareTo((Integer)o2);
|
||||||
for (int idx=conns.length-1; idx>=0; idx--)
|
}
|
||||||
moveConnection(conns[idx], oldPositions[idx]+delta);
|
});
|
||||||
else
|
List hostList = getHostList();
|
||||||
for (int idx=0; idx<conns.length; idx++)
|
for (int i = 0; i < hosts.length; i++) {
|
||||||
moveConnection(conns[idx], oldPositions[idx]+delta);
|
IHost host = hosts[i];
|
||||||
|
int index = hostList.indexOf(host);
|
||||||
commit();
|
if (index >= 0) {
|
||||||
}
|
indices.add(new Integer(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Go through the sorted list of indices.
|
||||||
|
boolean moved = indices.size() > 0;
|
||||||
|
for (Iterator z = indices.iterator(); z.hasNext() && moved;) {
|
||||||
|
int index = ((Integer) z.next()).intValue();
|
||||||
|
moved &= moveHost(hostList, index, delta);
|
||||||
|
}
|
||||||
|
if (moved) {
|
||||||
|
invalidateCache();
|
||||||
|
commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move one connection to a new location
|
* Move a host to a new location in the host pool.
|
||||||
* <b>TODO PROBLEM: CAN'T RE-ORDER FOLDERS SO CAN WE SUPPORT THIS ACTION?</b>
|
* @param hostList the list of hosts to modify
|
||||||
*/
|
* @param oldPos the index of the host to move. If outside the bounds of the list, the list is not altered.
|
||||||
private void moveConnection(IHost conn, int newPos)
|
* @param delta the amount by which to move the host. If the resulting
|
||||||
{
|
* position would be outside the bounds of the list, the list is not altered.
|
||||||
/*
|
* If 0 then the list is not altered.
|
||||||
* DWD revisit, make sure that connections can be "moved", whatever that means.
|
* @return true if the host was moved, false if not
|
||||||
* It appears that connections can be moved up and down in the list which
|
*/
|
||||||
* probably provides for some rational for keeping this around.
|
private boolean moveHost(List hostList, int oldPos, int delta) {
|
||||||
*/
|
boolean moved = false; // assume the element will not be moved
|
||||||
// java.util.List connList = getHostList();
|
if (0 <= oldPos && oldPos < hostList.size() && delta != 0) {
|
||||||
//FIXME connList.move(newPos, conn);
|
int newPos = oldPos + delta;
|
||||||
invalidateCache();
|
if (0 <= newPos && newPos < hostList.size()) {
|
||||||
}
|
IHost host = (IHost) hostList.remove(oldPos);
|
||||||
|
hostList.add(newPos, host);
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return moved;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order connections according to user preferences.
|
* Order connections according to user preferences.
|
||||||
* Called after restore.
|
* Called after restore.
|
||||||
*/
|
*/
|
||||||
public void orderHosts(String[] names)
|
public void orderHosts(String[] names) {
|
||||||
{
|
List connList = getHostList();
|
||||||
java.util.List connList = getHostList();
|
IHost[] conns = new IHost[names.length];
|
||||||
IHost[] conns = new IHost[names.length];
|
for (int idx = 0; idx < conns.length; idx++) {
|
||||||
for (int idx=0; idx<conns.length; idx++)
|
conns[idx] = getHost(names[idx]);
|
||||||
conns[idx] = getHost(names[idx]);
|
}
|
||||||
connList.clear();
|
connList.clear();
|
||||||
//System.out.println("Ordering connections within pool " + getName() + "...");
|
for (int idx = 0; idx < conns.length; idx++) {
|
||||||
for (int idx=0; idx<conns.length; idx++)
|
connList.add(conns[idx]);
|
||||||
{
|
}
|
||||||
connList.add(conns[idx]);
|
invalidateCache();
|
||||||
//System.out.println(" '"+conns[idx].getAliasName()+"'");
|
}
|
||||||
}
|
|
||||||
//System.out.println();
|
|
||||||
invalidateCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the unqualified save file name with the extension .xmi
|
* Return the unqualified save file name with the extension .xmi
|
||||||
|
|
|
@ -0,0 +1,166 @@
|
||||||
|
/********************************************************************************
|
||||||
|
* Copyright (c) 2007 IBM Corporation and others. 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:
|
||||||
|
* David Dykstal (IBM) - initial API and implementation.
|
||||||
|
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
|
||||||
|
* Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods
|
||||||
|
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
|
||||||
|
********************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.rse.tests.core;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.eclipse.rse.core.IRSESystemType;
|
||||||
|
import org.eclipse.rse.core.RSECorePlugin;
|
||||||
|
import org.eclipse.rse.core.model.IHost;
|
||||||
|
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||||
|
import org.eclipse.rse.tests.core.connection.IRSEConnectionProperties;
|
||||||
|
import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for host move in the host pool.
|
||||||
|
* Each testcase method should leave the host pool as it was prior to running the method.
|
||||||
|
*/
|
||||||
|
public class HostMoveTest extends RSEBaseConnectionTestCase {
|
||||||
|
|
||||||
|
static final int NUMBER_OF_HOSTS = 6; // number of hosts
|
||||||
|
private IHost hostArray[] = null;
|
||||||
|
private ISystemRegistry registry = null;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.rse.tests.core.RSECoreTestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
registry = RSECorePlugin.getTheSystemRegistry();
|
||||||
|
createHosts();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.rse.tests.core.RSECoreTestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
deleteHosts();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMoveOneUp() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost host = hostArray[NUMBER_OF_HOSTS - 1];
|
||||||
|
IHost[] hosts = new IHost[] {host};
|
||||||
|
registry.moveHosts("TestProfile", hosts, -1);
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 2, registry.getHostPosition(host));
|
||||||
|
registry.moveHosts("TestProfile", hosts, 1);
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 1, registry.getHostPosition(host));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMoveManyUp() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost[] hosts = new IHost[] {hostArray[NUMBER_OF_HOSTS - 1], hostArray[NUMBER_OF_HOSTS - 2]};
|
||||||
|
registry.moveHosts("TestProfile", hosts, -2);
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 3, registry.getHostPosition(hostArray[NUMBER_OF_HOSTS - 1]));
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 4, registry.getHostPosition(hostArray[NUMBER_OF_HOSTS - 2]));
|
||||||
|
registry.moveHosts("TestProfile", hosts, 2);
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 1, registry.getHostPosition(hostArray[NUMBER_OF_HOSTS - 1]));
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 2, registry.getHostPosition(hostArray[NUMBER_OF_HOSTS - 2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMoveFirstUp() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost host = hostArray[0];
|
||||||
|
assertEquals(0, registry.getHostPosition(host));
|
||||||
|
IHost[] hosts = new IHost[] {host};
|
||||||
|
registry.moveHosts("TestProfile", hosts, -1); // should not actually move
|
||||||
|
assertEquals(0, registry.getHostPosition(host));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMoveOneDown() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost host = hostArray[1]; // second in the list
|
||||||
|
assertEquals(1, registry.getHostPosition(host));
|
||||||
|
IHost[] hosts = new IHost[] {host};
|
||||||
|
registry.moveHosts("TestProfile", hosts, 1);
|
||||||
|
assertEquals(2, registry.getHostPosition(host));
|
||||||
|
registry.moveHosts("TestProfile", hosts, -1);
|
||||||
|
assertEquals(1, registry.getHostPosition(host));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMoveManyDown() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost[] hosts = new IHost[] {hostArray[0], hostArray[2], hostArray[4]};
|
||||||
|
assertEquals(0, registry.getHostPosition(hostArray[0]));
|
||||||
|
assertEquals(2, registry.getHostPosition(hostArray[2]));
|
||||||
|
assertEquals(4, registry.getHostPosition(hostArray[4]));
|
||||||
|
registry.moveHosts("TestProfile", hosts, 1);
|
||||||
|
assertEquals(1, registry.getHostPosition(hostArray[0]));
|
||||||
|
assertEquals(3, registry.getHostPosition(hostArray[2]));
|
||||||
|
assertEquals(5, registry.getHostPosition(hostArray[4]));
|
||||||
|
registry.moveHosts("TestProfile", hosts, -1);
|
||||||
|
assertEquals(0, registry.getHostPosition(hostArray[0]));
|
||||||
|
assertEquals(2, registry.getHostPosition(hostArray[2]));
|
||||||
|
assertEquals(4, registry.getHostPosition(hostArray[4]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMoveLastDown() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost host = hostArray[NUMBER_OF_HOSTS - 1];
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 1, registry.getHostPosition(host));
|
||||||
|
IHost[] hosts = new IHost[] {host};
|
||||||
|
registry.moveHosts("TestProfile", hosts, 1); // should not actually move
|
||||||
|
assertEquals(NUMBER_OF_HOSTS - 1, registry.getHostPosition(host));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNoHost() {
|
||||||
|
checkPrecondition();
|
||||||
|
IHost[] hosts = new IHost[] {};
|
||||||
|
registry.moveHosts("TestProfile", hosts, -1); // should not fail
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the test hosts.
|
||||||
|
*/
|
||||||
|
private void createHosts() {
|
||||||
|
|
||||||
|
hostArray = new IHost[NUMBER_OF_HOSTS];
|
||||||
|
|
||||||
|
/* Common host properties */
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(IRSEConnectionProperties.ATTR_PROFILE_NAME, "TestProfile"); //$NON-NLS-1$
|
||||||
|
properties.setProperty(IRSEConnectionProperties.ATTR_ADDRESS, "localhost"); //$NON-NLS-1$
|
||||||
|
properties.setProperty(IRSEConnectionProperties.ATTR_SYSTEM_TYPE_ID, IRSESystemType.SYSTEMTYPE_UNIX_ID);
|
||||||
|
properties.setProperty(IRSEConnectionProperties.ATTR_USERID, "userid"); //$NON-NLS-1$
|
||||||
|
properties.setProperty(IRSEConnectionProperties.ATTR_PASSWORD, "password"); //$NON-NLS-1$
|
||||||
|
IRSEConnectionProperties props = getConnectionManager().loadConnectionProperties(properties, false);
|
||||||
|
|
||||||
|
for (int i = 0; i < hostArray.length; i++) {
|
||||||
|
String hostName = getHostName(i);
|
||||||
|
properties.setProperty(IRSEConnectionProperties.ATTR_NAME, hostName); //$NON-NLS-1$
|
||||||
|
hostArray[i] = getConnectionManager().findOrCreateConnection(props);
|
||||||
|
assertNotNull("Failed to create connection " + props.getProperty(IRSEConnectionProperties.ATTR_NAME), hostArray[i]); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteHosts() {
|
||||||
|
for (int i = 1; i < hostArray.length; i++) {
|
||||||
|
registry.deleteHost(hostArray[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPrecondition() {
|
||||||
|
for (int i = 0; i < hostArray.length; i++) {
|
||||||
|
assertEquals("Precondition check failed", i, registry.getHostPosition(hostArray[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getHostName(int i) {
|
||||||
|
String hostName = "TestHost" + Integer.toString(i);
|
||||||
|
return hostName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue