package samples.model; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; import com.ibm.etools.systems.core.ui.SystemMenuManager; import com.ibm.etools.systems.core.ui.view.AbstractSystemViewAdapter; import com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter; import samples.subsystems.*; import java.util.*; /** * This is the adapter which enables us to work with our remote team resources. */ public class TeamResourceAdapter extends AbstractSystemViewAdapter implements ISystemRemoteElementAdapter { /** * @see com.ibm.etools.systems.core.ui.view.ISystemViewElementAdapter#addActions(SystemMenuManager, IStructuredSelection, Shell, String) */ public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell parent, String menuGroup) { } /** * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(Object) */ public ImageDescriptor getImageDescriptor(Object object) { return RSESamples.RSESamplesPlugin.getDefault().getImageDescriptor("ICON_ID_TEAM"); } /** * @see com.ibm.etools.systems.core.ui.view.ISystemViewElementAdapter#getText(Object) */ public String getText(Object element) { return ((TeamResource)element).getName(); } /** * @see com.ibm.etools.systems.subsystems.IRemoteObjectIdentifier#getAbsoluteName(Object) */ public String getAbsoluteName(Object object) { TeamResource team = (TeamResource)object; return "Team_"+team.getName(); } /** * @see com.ibm.etools.systems.core.ui.view.ISystemViewElementAdapter#getType(Object) */ public String getType(Object element) { return "Team resource"; } /** * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(Object) */ public Object getParent(Object o) { return null; // not really used, which is good because it is ambiguous } /** * @see com.ibm.etools.systems.core.ui.view.ISystemViewElementAdapter#hasChildren(Object) */ public boolean hasChildren(Object element) { return true; } /** * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object) */ public Object[] getChildren(Object o) { return ((TeamResource)o).getDevelopers(); } /** * @see com.ibm.etools.systems.core.ui.view.AbstractSystemViewAdapter#internalGetPropertyDescriptors() */ protected IPropertyDescriptor[] internalGetPropertyDescriptors() { return null; } /** * @see com.ibm.etools.systems.core.ui.view.AbstractSystemViewAdapter#internalGetPropertyValue() */ public Object internalGetPropertyValue(Object key) { return null; } /** * Intercept of parent method to indicate these objects can be renamed using the RSE-supplied * rename action. */ public boolean canRename(Object element) { return true; } /** * Intercept of parent method to actually do the rename. RSE supplies the rename GUI, but * defers the action work of renaming to this adapter method. */ public boolean doRename(Shell shell, Object element, String newName) { ((TeamResource)element).setName(newName); return true; } // -------------------------------------- // ISystemRemoteElementAdapter methods... // -------------------------------------- /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getAbsoluteParentName(Object) */ public String getAbsoluteParentName(Object element) { return "root"; // not really applicable as we have no unique hierarchy } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getSubSystemFactoryId(Object) */ public String getSubSystemFactoryId(Object element) { return "samples.subsystems.factory"; // as declared in extension in plugin.xml } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getRemoteTypeCategory(Object) */ public String getRemoteTypeCategory(Object element) { return "developers"; // Course grained. Same for all our remote resources. } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getRemoteType(Object) */ public String getRemoteType(Object element) { return "team"; // Fine grained. Unique to this resource type. } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getRemoteSubType(Object) */ public String getRemoteSubType(Object element) { return null; // Very fine grained. We don't use it. } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#refreshRemoteObject(Object, Object) */ public boolean refreshRemoteObject(Object oldElement, Object newElement) { TeamResource oldTeam = (TeamResource)oldElement; TeamResource newTeam = (TeamResource)newElement; newTeam.setName(oldTeam.getName()); return false; // If developer objects held references to their team names, we'd have to return true } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getRemoteParent(Shell, Object) */ public Object getRemoteParent(Shell shell, Object element) throws Exception { return null; // maybe this would be a Project or Roster object, or leave as null if this is the root } /** * @see com.ibm.etools.systems.core.ui.view.ISystemRemoteElementAdapter#getRemoteParentNamesInUse(Shell, Object) */ public String[] getRemoteParentNamesInUse(Shell shell, Object element) throws Exception { DeveloperSubSystem ourSS = (DeveloperSubSystem)getSubSystem(element); TeamResource[] allTeams = ourSS.getAllTeams(); String[] allNames = new String[allTeams.length]; for (int idx=0; idx<allTeams.length; idx++) allNames[idx] = allTeams[idx].getName(); return allNames; // Return list of all team names } }