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

Add Daytime Example - bug 138373

This commit is contained in:
Martin Oberhuber 2006-05-24 16:38:27 +00:00
parent 5c2813c452
commit 0e4a40ba00
26 changed files with 1021 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.rse.examples.daytime</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.rse.examples.daytime;singleton:=true
Bundle-Version: 0.0.2
Bundle-Activator: org.eclipse.rse.examples.daytime.Activator
Bundle-Vendor: Eclipse.org
Bundle-Localization: plugin
Require-Bundle: org.eclipse.rse.subsystems.files.ftp,
org.eclipse.rse.ui,
org.eclipse.rse.services,
org.eclipse.rse.core,
org.eclipse.ui,
org.eclipse.ui.views,
org.eclipse.core.runtime
Eclipse-LazyStart: true
Export-Package: org.eclipse.rse.examples.daytime

View file

@ -0,0 +1,22 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>About</title>
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
</head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>April 25, 2006</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content.</p>
</body>
</html>

View file

@ -0,0 +1,14 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
about.html,\
icons/,\
plugin.properties,\
plugin.xml
src.includes = META-INF/,\
about.html,\
plugin.properties,\
plugin.xml,\
readme.txt,\
icons/

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

View file

@ -0,0 +1,20 @@
################################################################################
# Copyright (c) 2006 Wind River Systems, Inc.
# 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:
# Martin Oberhuber (Wind River) - initial API and implementation
################################################################################
plugin.name = RSE Daytime
FTPDaytimeSystemDescription=FTP and Daytime Connection Type
Files=Files
FilesDescription=Files via FTP
DaytimeSubsystemName=Daytime
DaytimeDescription=This configuration allows you get the current time at a remote system via TCP port 13.

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006 Wind River Systems, Inc.
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:
Martin Oberhuber (Wind River) - initial API and implementation
-->
<?eclipse version="3.1"?>
<plugin>
<!-- Register a System that will only show FTP and Daytime subsystems -->
<extension point="org.eclipse.rse.core.systemTypes">
<systemType id="org.eclipse.rse.examples.daytime.systemtype.ftp"
name="FTP-Daytime"
description="%FTPDaytimeSystemDescription">
<property name="icon" value="icons/full/obj16/daytime_obj.gif"/>
<property name="iconlive" value="icons/full/obj16/daytimelive_obj.gif"/>
</systemType>
</extension>
<!-- Instantiate the FTP subsystem by referencing it from the external implementation -->
<extension
point="org.eclipse.rse.ui.subsystemConfiguration">
<configuration
systemTypes="FTP-Daytime"
name="%Files"
description="%FilesDescription"
iconlive="icons/full/obj16/systemfileslive_obj.gif"
icon="icons/full/obj16/systemfiles_obj.gif"
category="files"
class="org.eclipse.rse.subsystems.files.ftp.FTPFileSubSystemConfiguration"
vendor="IBM Corp"
id="ftp.files">
</configuration>
</extension>
<!-- Instantiate the Daytime subsystem from our own plugin -->
<extension
point="org.eclipse.rse.ui.subsystemConfiguration">
<configuration
systemTypes="FTP-Daytime;Unix"
name="%DaytimeSubsystemName"
description="%DaytimeDescription"
iconlive="icons/full/obj16/daytimelive_obj.gif"
icon="icons/full/obj16/daytime_obj.gif"
category="daytime"
class="org.eclipse.rse.examples.daytime.subsystems.DaytimeSubsystemConfiguration"
vendor="Wind River Systems"
id="daytime.tcp">
</configuration>
</extension>
</plugin>

View file

@ -0,0 +1,54 @@
Readme for RSE Daytime Example
------------------------------
The Daytime Example shows how a new subsystem (daytime) is contributed
to RSE, and how an existing subsystem (ftp) is configured for a system
type. The example is mainly meant for developer's educational use,
it does not have much user value: the Daytime Subsystem retrieves
the current time of day from a remote host via TCP port 13.
__Requirements:__
The Daytime example has been tested with with RSE M1 candidate
(CVS HEAD as of April 25, 2006) and Eclipse 3.2 RC1.
__Installation:__
You need an Eclipse PDE Workspace with RSE.
Then, choose File > Import > Existing Projects > Archive File,
to import the example archive.
__Usage:__
The daytime service must be enabled on the remote system (see below).
* Start RSE, create a new system of type "FTP-Daytime".
* Select the Daytime Subsystem and choose Contextmenu > Connect.
* Enter any username and password (this is not checked).
* Select the Daytime Subsystem and choose Refresh, or Contextmenu > Monitor.
* Enable polling in the remote monitor, you can see the time advance.
__Programmer's documentation:__
The interesting part of this example is in package
org.eclipse.rse.examples.daytime.model
where you see how the daytime node is added to the RSE tree through an
AbstractSystemViewAdapter. The DaytimeService is rather simple, since
queries are fast enough to use a connectionless service.
__Known Issues:__
* Entering Username and Password should not be required.
* Manual Refresh after connect should not be required.
* When something goes wrong during connect, the error message
does not give enough information about the cause of the error.
* The example defines a Service for its task; there might be
applications where this is not required or desired. A simpler
example should be provided that only defines a Subsystem but
no Service, ConnectorService or ConnectorServiceManager.
__Enabling the Daytime Service on a Remote Host:__
In order for the example to work, the service on TCP port 13 must be
activated on the host as follows:
* On Linux or other xinetd based UNIX systems, edit /etc/xinetd.d/daytime
and set "disable=no", then restart (kill -HUP) xinetd
* On Solaris or other inetd based UNIX systmes, edit /etc/inetd.conf
and make sure the following line is there:
daytime stream tcp nowait root internal
the kill -HUP inetd.
* On Windows/Cygwin, with xinetd installed, edit config
files like described for Linux, then start xinetd.exe

View file

@ -0,0 +1,75 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and Wind River Systems, Inc.
* 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - adapted template for daytime example.
********************************************************************************/
package org.eclipse.rse.examples.daytime;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.Platform;
import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.examples.daytime.model.DaytimeAdapterFactory;
import org.eclipse.rse.examples.daytime.model.DaytimeResource;
import org.osgi.framework.BundleContext;
/**
* The main plugin class to be used in the desktop.
*/
public class Activator extends SystemBasePlugin {
//The shared instance.
private static Activator plugin;
/**
* The constructor.
*/
public Activator() {
plugin = this;
}
/**
* This method is called upon plug-in activation
*/
public void start(BundleContext context) throws Exception {
super.start(context);
IAdapterManager manager = Platform.getAdapterManager();
DaytimeAdapterFactory factory = new DaytimeAdapterFactory();
manager.registerAdapters(factory, DaytimeResource.class);
}
/**
* This method is called when the plug-in is stopped
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
plugin = null;
}
/**
* Returns the shared instance.
*
* @return the shared instance.
*/
public static Activator getDefault() {
return plugin;
}
public static final String ICON_ID_DAYTIME = "ICON_ID_DAYTIME"; //$NON-NLS-1$
protected void initializeImageRegistry() {
String path = getIconPath();
putImageInRegistry(ICON_ID_DAYTIME, path+"full/obj16/daytime.gif"); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc.
* 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:
* Martin Oberhuber (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.examples.daytime;
import org.eclipse.osgi.util.NLS;
/**
* Resources for externalized Strings of the Daytime subsystem.
*/
public class DaytimeResources extends NLS {
private static String BUNDLE_NAME = "org.eclipse.rse.examples.daytime.DaytimeResources";//$NON-NLS-1$
public static String Daytime_Service_Name;
public static String Daytime_Service_Description;
public static String Daytime_Connector_Name;
public static String Daytime_Connector_Description;
public static String Daytime_Resource_Type;
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, DaytimeResources.class);
}
}

View file

@ -0,0 +1,16 @@
################################################################################
# Copyright (c) 2006 Wind River Systems, Inc.
# 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:
# Martin Oberhuber (Wind River) - initial API and implementation
################################################################################
Daytime_Service_Name=Daytime Service
Daytime_Service_Description=The Daytime Service retrieves the current time of day from a remote host by connecting to TCP port 13.
Daytime_Connector_Name=Daytime Connector Service
Daytime_Connector_Description=The Daytime Connector Service manages connections to TCP port 13 on a remote host.
Daytime_Resource_Type=daytime resource

View file

@ -0,0 +1,82 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and Wind River Systems, Inc.
* 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - adapted template for daytime example.
********************************************************************************/
package org.eclipse.rse.examples.daytime.connectorservice;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.core.subsystems.AbstractConnectorService;
import org.eclipse.rse.examples.daytime.DaytimeResources;
import org.eclipse.rse.examples.daytime.service.DaytimeService;
import org.eclipse.rse.examples.daytime.service.IDaytimeService;
import org.eclipse.rse.model.IHost;
/**
* The DaytimeConnectorService takes care of keeping a "session" for accessing
* the remote host to retrieve the time of day.
*
* Since the daytime service is really connectionless, there is not much to do
* here. We basically keep a local "connected" flag only, so to make sure that
* the remote host is only accessed when the user explicitly requested so.
*/
public class DaytimeConnectorService extends AbstractConnectorService {
private boolean fIsConnected = false;
private DaytimeService fDaytimeService;
public DaytimeConnectorService(IHost host) {
super(DaytimeResources.Daytime_Connector_Name, DaytimeResources.Daytime_Connector_Description, host, 13);
fDaytimeService = new DaytimeService();
}
protected void internalConnect(IProgressMonitor monitor) throws Exception {
internalConnect();
}
private void internalConnect() throws Exception
{
fDaytimeService.setHostName(getHostName());
fDaytimeService.getTimeOfDay();
//if no exception is thrown, we consider ourselves connected!
fIsConnected = true;
//TODO force a refresh of the Viewer in order to show the resource
}
public IDaytimeService getDaytimeService() {
return fDaytimeService;
}
public boolean isConnected() {
return fIsConnected;
}
public void disconnect() {
fIsConnected = false;
//TODO force a refresh of the Viewer in order to hide the resource
}
public boolean hasRemoteServerLauncherProperties() {
return false;
}
public boolean supportsRemoteServerLaunching() {
return false;
}
public boolean supportsServerLaunchProperties() {
return false;
}
}

View file

@ -0,0 +1,69 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and Wind River Systems, Inc.
* 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - adapted template for daytime example.
********************************************************************************/
package org.eclipse.rse.examples.daytime.connectorservice;
import org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.examples.daytime.subsystems.IDaytimeSubSystem;
import org.eclipse.rse.model.IHost;
/**
* This class manages our DaytimeConnectorService objects, so that if we ever
* have multiple subsystem factories, different subsystems can share the same
* ConnectorService if they share the communication layer.
*/
public class DaytimeConnectorServiceManager extends AbstractConnectorServiceManager {
private static DaytimeConnectorServiceManager fInstance;
public DaytimeConnectorServiceManager() {
super();
}
/**
* Return singleton instance
*/
public static DaytimeConnectorServiceManager getTheDaytimeConnectorServiceManager() {
if (fInstance == null) {
fInstance = new DaytimeConnectorServiceManager();
}
return fInstance;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager#createConnectorService(org.eclipse.rse.model.IHost)
*/
public IConnectorService createConnectorService(IHost host) {
return new DaytimeConnectorService(host);
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager#sharesSystem(org.eclipse.rse.core.subsystems.ISubSystem)
*/
public boolean sharesSystem(ISubSystem otherSubSystem) {
return (otherSubSystem instanceof IDaytimeSubSystem);
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager#getSubSystemCommonInterface(org.eclipse.rse.core.subsystems.ISubSystem)
*/
public Class getSubSystemCommonInterface(ISubSystem subsystem) {
return IDaytimeSubSystem.class;
}
}

View file

@ -0,0 +1,48 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and Wind River Systems, Inc.
* 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - adapted template for daytime example.
********************************************************************************/
package org.eclipse.rse.examples.daytime.model;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.rse.ui.view.AbstractSystemRemoteAdapterFactory;
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
import org.eclipse.ui.views.properties.IPropertySource;
/**
* This factory maps requests for an adapter object from a given remote object.
*/
public class DaytimeAdapterFactory extends AbstractSystemRemoteAdapterFactory
implements IAdapterFactory {
private DaytimeResourceAdapter daytimeAdapter = new DaytimeResourceAdapter();
public DaytimeAdapterFactory() {
super();
}
public Object getAdapter(Object adaptableObject, Class adapterType) {
ISystemViewElementAdapter adapter = null;
if (adaptableObject instanceof DaytimeResource) {
adapter = daytimeAdapter;
}
// these lines are very important!
if ((adapter != null) && (adapterType == IPropertySource.class)) {
adapter.setPropertySourceInput(adaptableObject);
}
return adapter;
}
}

View file

@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc.
* 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:
* Martin Oberhuber (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.examples.daytime.model;
import org.eclipse.rse.core.internal.subsystems.AbstractResource;
import org.eclipse.rse.core.subsystems.ISubSystem;
/**
* This models the time of day on a remote system.
* It might as well model any other remote resource.
*/
public class DaytimeResource extends AbstractResource {
private String fDaytime;
/** Default constructor */
public DaytimeResource() {
super();
}
/** Constructor when parent subsystem is given */
public DaytimeResource(ISubSystem subsystem) {
super(subsystem);
}
public String getDaytime() {
return fDaytime;
}
public void setDaytime(String daytime) {
fDaytime = daytime;
}
}

View file

@ -0,0 +1,137 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and Wind River Systems, Inc.
* 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - adapted template for daytime example.
********************************************************************************/
package org.eclipse.rse.examples.daytime.model;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.rse.examples.daytime.Activator;
import org.eclipse.rse.examples.daytime.DaytimeResources;
import org.eclipse.rse.examples.daytime.service.IDaytimeService;
import org.eclipse.rse.examples.daytime.subsystems.DaytimeSubSystem;
import org.eclipse.rse.ui.SystemMenuManager;
import org.eclipse.rse.ui.view.AbstractSystemViewAdapter;
import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
/**
* The DaytimeResourceAdapter fulfills the interface required by the Remote Systems
* View, and delegates UI requests to the underlying data model (DaytimeResource).
*/
public class DaytimeResourceAdapter extends AbstractSystemViewAdapter implements
ISystemRemoteElementAdapter {
public DaytimeResourceAdapter() {
super();
}
public void addActions(SystemMenuManager menu,
IStructuredSelection selection, Shell parent, String menuGroup) {
}
public ImageDescriptor getImageDescriptor(Object element) {
return Activator.getDefault().getImageDescriptor(Activator.ICON_ID_DAYTIME);
}
public String getText(Object element) {
return ((DaytimeResource)element).getDaytime();
}
public String getAbsoluteName(Object object) {
//Not used since we dont support clipboard copy, rename or filtering
//TODO check if it is still used anywhere? Then we'd want to externalize the String
return "daytime:"+getText(object); //$NON-NLS-1$
}
public String getType(Object element) {
return DaytimeResources.Daytime_Resource_Type;
}
public Object getParent(Object element) {
return null; // not really used, which is good because it is ambiguous
}
public boolean hasChildren(Object element) {
return false;
}
public Object[] getChildren(Object element) {
return null;
}
protected Object internalGetPropertyValue(Object key) {
return null;
}
protected IPropertyDescriptor[] internalGetPropertyDescriptors() {
return null;
}
// --------------------------------------
// ISystemRemoteElementAdapter methods...
// --------------------------------------
public String getAbsoluteParentName(Object element) {
// not really applicable as we have no unique hierarchy
return "root"; //$NON-NLS-1$
}
public String getSubSystemFactoryId(Object element) {
// as declared in extension in plugin.xml
return "daytime.tcp"; //$NON-NLS-1$
}
public String getRemoteTypeCategory(Object element) {
// Course grained. Same for all our remote resources.
return "daytime"; //$NON-NLS-1$
}
public String getRemoteType(Object element) {
// Fine grained. Unique to this resource type.
return "daytime"; //$NON-NLS-1$
}
public String getRemoteSubType(Object element) {
// Very fine grained. We don't use it.
return null;
}
public boolean refreshRemoteObject(Object oldElement, Object newElement) {
DaytimeResource oldTime = (DaytimeResource)oldElement;
DaytimeResource newTime = (DaytimeResource)newElement;
newTime.setDaytime(oldTime.getDaytime());
return false; // If daytime objects held references to their time string, we'd have to return true
}
public Object getRemoteParent(Shell shell, Object element) throws Exception {
return null; // leave as null if this is the root
}
public String[] getRemoteParentNamesInUse(Shell shell, Object element)
throws Exception {
DaytimeSubSystem ourSS = (DaytimeSubSystem)getSubSystem(element);
IDaytimeService service = ourSS.getDaytimeService();
String time = service.getTimeOfDay();
String[] allLabels = new String[] { time };
return allLabels; // Return list of all labels
}
public boolean supportsUserDefinedActions(Object object) {
return false;
}
}

View file

@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc.
* 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:
* Martin Oberhuber (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.examples.daytime.service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.examples.daytime.DaytimeResources;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
/**
* The DaytimeService implements the UI-less protocol for accessing the
* daytime TCP service on a remote host. Other implementations of the
* same interface might use other methods for retrieving the time of day.
*/
public class DaytimeService implements IDaytimeService {
private String fHostname;
public DaytimeService() {
//nothing to do
}
public String getName() {
return DaytimeResources.Daytime_Service_Name;
}
public String getDescription() {
return DaytimeResources.Daytime_Service_Description;
}
public void initService(IProgressMonitor monitor) {
//nothing to do
}
public SystemMessage getMessage(String messageID) {
//dummy impl for now
return null;
}
public void setHostName(String hostname) {
fHostname = hostname;
}
public String getTimeOfDay() throws UnknownHostException, IOException {
Socket s = new Socket(fHostname, 13);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String result = in.readLine();
in.close();
s.close();
return result;
}
public void uninitService(IProgressMonitor monitor) {
//nothing to do
}
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc.
* 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:
* Martin Oberhuber (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.examples.daytime.service;
import java.io.IOException;
import java.net.UnknownHostException;
import org.eclipse.rse.services.IService;
/**
* IDaytimeService is the interface (API) for retrieving the time of day
* from a remote system.
*/
public interface IDaytimeService extends IService {
/**
* @return a String of the form "01 MAR 2006 11:25:12 CET"
* @throws UnknownHostException when remote address could not be resolved
* @throws IOException in case of an error transferring the data
*/
public String getTimeOfDay() throws UnknownHostException, IOException;
}

View file

@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc.
* 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:
* Martin Oberhuber (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.examples.daytime.subsystems;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.core.subsystems.SubSystem;
import org.eclipse.rse.examples.daytime.model.DaytimeResource;
import org.eclipse.rse.examples.daytime.service.IDaytimeService;
import org.eclipse.rse.model.IHost;
import org.eclipse.rse.model.ISystemMessageObject;
import org.eclipse.rse.model.SystemMessageObject;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.ui.ISystemMessages;
import org.eclipse.rse.ui.RSEUIPlugin;
/**
* This is our subsystem, which manages the remote connection and resources for
* a particular Service (system connection) object.
*/
public class DaytimeSubSystem extends SubSystem {
private IDaytimeService fDaytimeService;
public DaytimeSubSystem(IHost host, IConnectorService connectorService, IDaytimeService daytimeService) {
super(host, connectorService);
fDaytimeService = daytimeService;
}
public void initializeSubSystem(IProgressMonitor monitor) {
// nothing to do
}
public boolean hasChildren() {
return isConnected();
}
public IDaytimeService getDaytimeService() {
return fDaytimeService;
}
public Object[] getChildren() {
try {
String daytime = fDaytimeService.getTimeOfDay();
DaytimeResource node = new DaytimeResource(this);
node.setDaytime(daytime);
return new Object[] { node };
} catch(Exception e) {
SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_FAILED);
msg.makeSubstitution(getHostName(), e);
SystemMessageObject msgobj = new SystemMessageObject(msg, ISystemMessageObject.MSGTYPE_ERROR,this);
return new Object[] { msgobj };
}
}
public void uninitializeSubSystem(IProgressMonitor monitor) {
//nothing to do
}
}

View file

@ -0,0 +1,111 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and Wind River Systems, Inc.
* 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - adapted template for daytime example.
********************************************************************************/
package org.eclipse.rse.examples.daytime.subsystems;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.rse.core.servicesubsystem.ServiceSubSystemConfiguration;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.examples.daytime.connectorservice.DaytimeConnectorService;
import org.eclipse.rse.examples.daytime.connectorservice.DaytimeConnectorServiceManager;
import org.eclipse.rse.examples.daytime.service.IDaytimeService;
import org.eclipse.rse.model.IHost;
import org.eclipse.rse.services.IService;
/**
* The DaytimeSubsystemConfiguration implements the main API for registering
* a new subsystem type.
* It gives the RSE framework basic configuration data about enabled
* or disabled options, and is responsible for instanciating the actual
* Daytime subsystem as well as the UI-less configuration layer (service).
*/
public class DaytimeSubsystemConfiguration extends ServiceSubSystemConfiguration {
private Map fServices = new HashMap();
public DaytimeSubsystemConfiguration() {
super();
}
public boolean supportsServerLaunchProperties(IHost host) {
return false;
}
public boolean supportsFilters() {
return false;
}
public boolean supportsSubSystemConnect() {
//TODO for now, we have to connect in order to pass the hostname to the service
//This should not be necessary in an ideal world
return true;
}
public boolean isPortEditable() {
return false;
}
public boolean supportsUserId() {
// TODO for now, we have to connect in order to pass the hostname to the service
// This should not be necessary in an ideal world
return true;
}
public boolean isFactoryFor(Class subSystemType) {
return DaytimeSubSystem.class.equals(subSystemType);
}
/**
* Instantiate and return an instance of OUR subystem.
* Do not populate it yet though!
* @see org.eclipse.rse.core.subsystems.impl.SubSystemFactoryImpl#createSubSystemInternal(IHost)
*/
public ISubSystem createSubSystemInternal(IHost host) {
IConnectorService connectorService = getConnectorService(host);
ISubSystem subsys = new DaytimeSubSystem(host, connectorService, createDaytimeService(host));
return subsys;
}
public IConnectorService getConnectorService(IHost host) {
return DaytimeConnectorServiceManager.getTheDaytimeConnectorServiceManager()
.getConnectorService(host, IDaytimeService.class);
}
public void setConnectorService(IHost host, IConnectorService connectorService) {
DaytimeConnectorServiceManager.getTheDaytimeConnectorServiceManager()
.setConnectorService(host, IDaytimeService.class, connectorService);
}
public IDaytimeService createDaytimeService(IHost host) {
DaytimeConnectorService connectorService = (DaytimeConnectorService)getConnectorService(host);
return connectorService.getDaytimeService();
}
public final IService getService(IHost host) {
IDaytimeService service = (IDaytimeService)fServices.get(host);
if (service == null) {
service = createDaytimeService(host);
fServices.put(host, service);
}
return service;
}
public final Class getServiceType() {
return IDaytimeService.class;
}
public Class getServiceImplType() {
return IDaytimeService.class;
}
}

View file

@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc.
* 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:
* Martin Oberhuber (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.examples.daytime.subsystems;
/**
* Markup interface for finding multiple different implementations of the
* DaytimeSubSystem, just in case we should ever have them.
*/
public interface IDaytimeSubSystem {
}