ServiceClientItemProvider.java
Go to the documentation of this file.
00001 
00003 package org.ros.model.ros.provider;
00004 
00005 
00006 import java.io.BufferedReader;
00007 import java.io.IOException;
00008 import java.io.InputStreamReader;
00009 import java.util.ArrayList;
00010 import java.util.Collection;
00011 import java.util.List;
00012 
00013 import org.best_of_robotics.model.datatypes.DataType;
00014 import org.best_of_robotics.model.datatypes.DatatypesFactory;
00015 import org.eclipse.emf.common.notify.AdapterFactory;
00016 import org.eclipse.emf.common.notify.Notification;
00017 
00018 import org.eclipse.emf.common.util.ResourceLocator;
00019 
00020 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
00021 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
00022 import org.eclipse.emf.edit.provider.IItemLabelProvider;
00023 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
00024 import org.eclipse.emf.edit.provider.IItemPropertySource;
00025 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
00026 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
00027 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
00028 import org.eclipse.emf.edit.provider.ItemProviderAdapter;
00029 import org.eclipse.emf.edit.provider.ViewerNotification;
00030 
00031 import org.ros.model.ros.RosPackage;
00032 import org.ros.model.ros.ServiceClient;
00033 import org.ros.model.smach.provider.SMACHStateItemProvider;
00034 import org.ros.model.ros.ServiceServer;
00035 
00042 public class ServiceClientItemProvider
00043         extends ItemProviderAdapter
00044         implements
00045                 IEditingDomainItemProvider,
00046                 IStructuredItemContentProvider,
00047                 ITreeItemContentProvider,
00048                 IItemLabelProvider,
00049                 IItemPropertySource {
00056         public ServiceClientItemProvider(AdapterFactory adapterFactory) {
00057                 super(adapterFactory);
00058         }
00059 
00066         @Override
00067         public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
00068                 if (itemPropertyDescriptors == null) {
00069                         super.getPropertyDescriptors(object);
00070 
00071                         addNamePropertyDescriptor(object);
00072                         addMsgPropertyDescriptor(object);
00073                 }
00074                 return itemPropertyDescriptors;
00075         }
00076 
00083         protected void addNamePropertyDescriptor(Object object) {
00084                 itemPropertyDescriptors.add
00085                         (createItemPropertyDescriptor
00086                                 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00087                                  getResourceLocator(),
00088                                  getString("_UI_ServiceClient_name_feature"),
00089                                  getString("_UI_PropertyDescriptor_description", "_UI_ServiceClient_name_feature", "_UI_ServiceClient_type"),
00090                                  RosPackage.Literals.SERVICE_CLIENT__NAME,
00091                                  true,
00092                                  false,
00093                                  false,
00094                                  ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00095                                  null,
00096                                  null));
00097         }
00098 
00099         
00103         protected void addMsgPropertyDescriptor(Object object) {
00104                 itemPropertyDescriptors.add
00105                         (new ItemPropertyDescriptor
00106                                 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00107                                  getResourceLocator(),
00108                                  getString("_UI_ServiceClient_msg_feature"),
00109                                  getString("_UI_PropertyDescriptor_description", "_UI_ServiceClient_msg_feature", "_UI_ServiceClient_type"),
00110                                  RosPackage.Literals.SERVICE_CLIENT__MSG,
00111                                  true,
00112                                  false,
00113                                  false,
00114                                  ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00115                                  null,
00116                                  null) {
00117                         @Override
00118                 public Collection<?> getChoiceOfValues(Object object) {
00119                         ServiceClient serviceclient = (ServiceClient) object;
00120                         org.ros.model.ros.Package pack = (org.ros.model.ros.Package) serviceclient.eContainer().eContainer();
00121                         System.out.println(pack.getName());
00122                         
00123                         DataType test = DatatypesFactory.eINSTANCE.createSimpleType();
00124                                                 
00125                         List<String> strings = new ArrayList<String>(); // Copy the students to a temporary list
00126                         for (String item: pack.getDepend()) {
00127                                 String cmd = "rossrv package " + item;
00128                                 Runtime run = Runtime.getRuntime();
00129                                 Process pr;
00130                                 try {
00131                                         pr = run.exec(cmd);
00132                                         pr.waitFor();
00133                                         BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
00134                                         String line = "";
00135                                         while ((line=buf.readLine())!=null) {
00136                                                 strings.add(line.replace("/", "::"));
00137                                         }
00138                                 } catch (IOException e) {
00139                                         // TODO Auto-generated catch block
00140                                         e.printStackTrace();
00141                                 } catch (InterruptedException e) {
00142                                         // TODO Auto-generated catch block
00143                                         e.printStackTrace();
00144                                 }
00145                                 //strings.add(item);
00146                         }
00147                         return strings;
00148                 }
00149                 });
00150         }
00151 
00158         @Override
00159         public Object getImage(Object object) {
00160                 return overlayImage(object, getResourceLocator().getImage("full/obj16/ServiceClient"));
00161         }
00162 
00169         @Override
00170         public String getText(Object object) {
00171                 String label = ((ServiceClient)object).getName();
00172                 return label == null || label.length() == 0 ?
00173                         getString("_UI_ServiceClient_type") :
00174                         getString("_UI_ServiceClient_type") + " " + label;
00175         }
00176 
00184         @Override
00185         public void notifyChanged(Notification notification) {
00186                 updateChildren(notification);
00187 
00188                 switch (notification.getFeatureID(ServiceClient.class)) {
00189                         case RosPackage.SERVICE_CLIENT__NAME:
00190                         case RosPackage.SERVICE_CLIENT__MSG:
00191                                 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
00192                                 return;
00193                 }
00194                 super.notifyChanged(notification);
00195         }
00196 
00204         @Override
00205         protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
00206                 super.collectNewChildDescriptors(newChildDescriptors, object);
00207         }
00208 
00215         @Override
00216         public ResourceLocator getResourceLocator() {
00217                 return RosEditPlugin.INSTANCE;
00218         }
00219 
00220 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34