1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-24 00:33:48 +02:00

[228577] [rseterminal] Further cleanup

This commit is contained in:
Martin Oberhuber 2008-05-05 18:40:36 +00:00
parent 9a75a4b103
commit 4c176f689d
2 changed files with 101 additions and 72 deletions

View file

@ -1,18 +1,21 @@
/******************************************************************************** /********************************************************************************
* Copyright (c) 2008 MontaVista Software, Inc. * Copyright (c) 2008 MontaVista Software, Inc. and others.
* This program and the accompanying materials are made available under the terms * All rights reserved. This program and the accompanying materials
* of the Eclipse Public License v1.0 which accompanies this distribution, and is * are made available under the terms of the Eclipse Public License v1.0
* available at http://www.eclipse.org/legal/epl-v10.html * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Yu-Fen Kuo (MontaVista) - initial API and implementation * Yu-Fen Kuo (MontaVista) - initial API and implementation
* Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits * Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits
* Anna Dushistova (MontaVista) - [228577] [rseterminal] Clean up RSE Terminal impl * Anna Dushistova (MontaVista) - [228577] [rseterminal] Clean up RSE Terminal impl
* Martin Oberhuber (Wind River) - [228577] [rseterminal] Further cleanup
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.subsystems.terminals.core; package org.eclipse.rse.subsystems.terminals.core;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.RSECorePlugin;
@ -28,38 +31,38 @@ import org.eclipse.rse.internal.services.terminals.ITerminalService;
import org.eclipse.rse.subsystems.terminals.core.elements.TerminalElement; import org.eclipse.rse.subsystems.terminals.core.elements.TerminalElement;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
public final class TerminalServiceSubSystem extends SubSystem implements /**
* A Subsystem that has terminal instances as children.
*/
public class TerminalServiceSubSystem extends SubSystem implements
ITerminalServiceSubSystem, ICommunicationsListener { ITerminalServiceSubSystem, ICommunicationsListener {
protected ITerminalService _hostService = null; private ITerminalService _hostService = null;
private ArrayList children = new ArrayList(); private ArrayList children = new ArrayList();
public class Refresh implements Runnable { /**
private TerminalServiceSubSystem _ss; * Constructor.
*/
public Refresh(TerminalServiceSubSystem ss) {
_ss = ss;
}
public void run() {
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
registry.fireEvent(new SystemResourceChangeEvent(_ss,
ISystemResourceChangeEvents.EVENT_REFRESH, _ss));
}
}
protected TerminalServiceSubSystem(IHost host,
IConnectorService connectorService) {
super(host, connectorService);
}
public TerminalServiceSubSystem(IHost host, public TerminalServiceSubSystem(IHost host,
IConnectorService connectorService, ITerminalService hostService) { IConnectorService connectorService, ITerminalService hostService) {
super(host, connectorService); super(host, connectorService);
_hostService = hostService; _hostService = hostService;
} }
private void fireAsyncRefresh(final Object target) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
registry.fireEvent(new SystemResourceChangeEvent(target, ISystemResourceChangeEvents.EVENT_REFRESH, target));
}
});
}
/**
* Return the Terminal Service associated with this subsystem.
*/
public ITerminalService getTerminalService() { public ITerminalService getTerminalService() {
return _hostService; return _hostService;
} }
@ -69,10 +72,12 @@ public final class TerminalServiceSubSystem extends SubSystem implements
} }
public void addChild(TerminalElement element) { public void addChild(TerminalElement element) {
if (element != null) {
synchronized (children) { synchronized (children) {
children.add(element); children.add(element);
} }
Display.getDefault().asyncExec(new Refresh(this)); fireAsyncRefresh(this);
}
} }
public void removeChild(TerminalElement element) { public void removeChild(TerminalElement element) {
@ -80,39 +85,40 @@ public final class TerminalServiceSubSystem extends SubSystem implements
synchronized (children) { synchronized (children) {
children.remove(element); children.remove(element);
} }
Display.getDefault().asyncExec(new Refresh(this)); fireAsyncRefresh(this);
} }
} }
public void removeChild(String terminalTitle) { public void removeChild(String terminalTitle) {
removeChild(getChild(terminalTitle)); removeChild(getChild(terminalTitle));
} }
public TerminalElement getChild(String terminalTitle) { public TerminalElement getChild(String terminalTitle) {
Object[] children = getChildren(); synchronized (children) {
for (int i = 0, e = children.length; i < e; i++) { for (Iterator it = children.iterator(); it.hasNext();) {
TerminalElement element = (TerminalElement)children[i]; TerminalElement element = (TerminalElement) it.next();
if (element.getName().equals(terminalTitle)) if (element.getName().equals(terminalTitle))
return element; return element;
} }
}
return null; return null;
} }
public Object[] getChildren() { public Object[] getChildren() {
Object[] result;
synchronized (children) { synchronized (children) {
result = (Object[]) children return children.toArray();
.toArray(new Object[children.size()]);
} }
return result;
} }
public boolean hasChildren() { public boolean hasChildren() {
synchronized (children) { synchronized (children) {
if (children.size() > 0) return !children.isEmpty();
return true;
return false;
} }
} }
/**
* Set the terminal service associated with this subsystem.
*/
public void setTerminalService(ITerminalService service) { public void setTerminalService(ITerminalService service) {
_hostService = service; _hostService = service;
} }
@ -141,10 +147,17 @@ public final class TerminalServiceSubSystem extends SubSystem implements
public boolean isPassiveCommunicationsListener() { public boolean isPassiveCommunicationsListener() {
return true; return true;
} }
/**
* Set the terminal service associated with this subsystem.
*/
public void cancelAllTerminals() { public void cancelAllTerminals() {
if (children.size() == 0) Object[] terminals;
return; synchronized (children) {
Object[] terminals = getChildren(); terminals = getChildren();
children.clear();
}
if (terminals.length > 0) {
for (int i = terminals.length - 1; i >= 0; i--) { for (int i = terminals.length - 1; i >= 0; i--) {
TerminalElement element = (TerminalElement) terminals[i]; TerminalElement element = (TerminalElement) terminals[i];
try { try {
@ -153,11 +166,8 @@ public final class TerminalServiceSubSystem extends SubSystem implements
RSECorePlugin.getDefault().getLogger().logError("Error removing terminal", e); //$NON-NLS-1$ RSECorePlugin.getDefault().getLogger().logError("Error removing terminal", e); //$NON-NLS-1$
} }
} }
synchronized(children){ fireAsyncRefresh(this);
children.clear();
} }
Display.getDefault().asyncExec(new Refresh(this));
} }
private void removeTerminalElement(TerminalElement element) { private void removeTerminalElement(TerminalElement element) {
@ -165,6 +175,7 @@ public final class TerminalServiceSubSystem extends SubSystem implements
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
registry.fireEvent(new SystemResourceChangeEvent(element, ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_REMOVED, null)); registry.fireEvent(new SystemResourceChangeEvent(element, ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_REMOVED, null));
} }
public void initializeSubSystem(IProgressMonitor monitor) { public void initializeSubSystem(IProgressMonitor monitor) {
super.initializeSubSystem(monitor); super.initializeSubSystem(monitor);
getConnectorService().addCommunicationsListener(this); getConnectorService().addCommunicationsListener(this);

View file

@ -1,13 +1,15 @@
/******************************************************************************** /********************************************************************************
* Copyright (c) 2008 MontaVista Software, Inc. * Copyright (c) 2008 MontaVista Software, Inc. and others.
* This program and the accompanying materials are made available under the terms * All rights reserved. This program and the accompanying materials
* of the Eclipse Public License v1.0 which accompanies this distribution, and is * are made available under the terms of the Eclipse Public License v1.0
* available at http://www.eclipse.org/legal/epl-v10.html * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Yu-Fen Kuo (MontaVista) - initial API and implementation * Yu-Fen Kuo (MontaVista) - initial API and implementation
* Anna Dushistova (MontaVista) - initial API and implementation * Anna Dushistova (MontaVista) - initial API and implementation
* Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits * Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits
* Martin Oberhuber (Wind River) - [228577] [rseterminal] Further cleanup
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.subsystems.terminals.core.elements; package org.eclipse.rse.subsystems.terminals.core.elements;
@ -15,34 +17,44 @@ import org.eclipse.rse.core.subsystems.AbstractResource;
import org.eclipse.rse.internal.services.terminals.ITerminalShell; import org.eclipse.rse.internal.services.terminals.ITerminalShell;
import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem; import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
/**
* An element in the RSE Tree that resembles a Terminal connection.
*/
public class TerminalElement extends AbstractResource { public class TerminalElement extends AbstractResource {
private String name; private String name;
private ITerminalShell terminalShell; private ITerminalShell terminalShell;
/**
* Constructor.
*/
public TerminalElement(String name, public TerminalElement(String name,
ITerminalServiceSubSystem terminalServiceSubSystem) { ITerminalServiceSubSystem terminalServiceSubSystem) {
super(terminalServiceSubSystem); super(terminalServiceSubSystem);
this.name = name; this.name = name;
} }
public String getName() { /**
* Return the name of this element, which will also be used as the label in
* the tree.
*/
public final String getName() {
return name; return name;
} }
public String toString() { public String toString() {
return getName(); return getName();
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof TerminalElement) {
if (obj == this) if (obj == this)
return true; return true;
return name.equals(((TerminalElement) obj).getName()) if (!(obj instanceof TerminalElement))
&& terminalShell == ((TerminalElement) obj) return false;
.getTerminalShell(); TerminalElement other = (TerminalElement) obj;
} return name.equals(other.getName())
return super.equals(obj); && getSubSystem().equals(other.getSubSystem())
&& (terminalShell == null ? other.getTerminalShell() == null
: terminalShell.equals(other.getTerminalShell()));
} }
public int hashCode() { public int hashCode() {
@ -51,10 +63,16 @@ public class TerminalElement extends AbstractResource {
return name.hashCode() ; return name.hashCode() ;
} }
/**
* Return the back-end connection of this terminal instance.
*/
public ITerminalShell getTerminalShell() { public ITerminalShell getTerminalShell() {
return terminalShell; return terminalShell;
} }
/**
* Set the back-end connection of this terminal instance.
*/
public void setTerminalShell(ITerminalShell terminalShell) { public void setTerminalShell(ITerminalShell terminalShell) {
this.terminalShell = terminalShell; this.terminalShell = terminalShell;
} }