$search
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.ros.ServiceServer; 00034 00041 public class ServiceClientItemProvider 00042 extends ItemProviderAdapter 00043 implements 00044 IEditingDomainItemProvider, 00045 IStructuredItemContentProvider, 00046 ITreeItemContentProvider, 00047 IItemLabelProvider, 00048 IItemPropertySource { 00055 public ServiceClientItemProvider(AdapterFactory adapterFactory) { 00056 super(adapterFactory); 00057 } 00058 00065 @Override 00066 public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) { 00067 if (itemPropertyDescriptors == null) { 00068 super.getPropertyDescriptors(object); 00069 00070 addNamePropertyDescriptor(object); 00071 addMsgPropertyDescriptor(object); 00072 } 00073 return itemPropertyDescriptors; 00074 } 00075 00082 protected void addNamePropertyDescriptor(Object object) { 00083 itemPropertyDescriptors.add 00084 (createItemPropertyDescriptor 00085 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00086 getResourceLocator(), 00087 getString("_UI_ServiceClient_name_feature"), 00088 getString("_UI_PropertyDescriptor_description", "_UI_ServiceClient_name_feature", "_UI_ServiceClient_type"), 00089 RosPackage.Literals.SERVICE_CLIENT__NAME, 00090 true, 00091 false, 00092 false, 00093 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 00094 null, 00095 null)); 00096 } 00097 00098 00102 protected void addMsgPropertyDescriptor(Object object) { 00103 itemPropertyDescriptors.add 00104 (new ItemPropertyDescriptor 00105 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00106 getResourceLocator(), 00107 getString("_UI_ServiceClient_msg_feature"), 00108 getString("_UI_PropertyDescriptor_description", "_UI_ServiceClient_msg_feature", "_UI_ServiceClient_type"), 00109 RosPackage.Literals.SERVICE_CLIENT__MSG, 00110 true, 00111 false, 00112 false, 00113 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 00114 null, 00115 null) { 00116 @Override 00117 public Collection<?> getChoiceOfValues(Object object) { 00118 ServiceClient serviceclient = (ServiceClient) object; 00119 org.ros.model.ros.Package pack = (org.ros.model.ros.Package) serviceclient.eContainer().eContainer(); 00120 System.out.println(pack.getName()); 00121 00122 DataType test = DatatypesFactory.eINSTANCE.createSimpleType(); 00123 00124 List<String> strings = new ArrayList<String>(); // Copy the students to a temporary list 00125 for (String item: pack.getDepend()) { 00126 String cmd = "rossrv package " + item; 00127 Runtime run = Runtime.getRuntime(); 00128 Process pr; 00129 try { 00130 pr = run.exec(cmd); 00131 pr.waitFor(); 00132 BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); 00133 String line = ""; 00134 while ((line=buf.readLine())!=null) { 00135 strings.add(line.replace("/", "::")); 00136 } 00137 } catch (IOException e) { 00138 // TODO Auto-generated catch block 00139 e.printStackTrace(); 00140 } catch (InterruptedException e) { 00141 // TODO Auto-generated catch block 00142 e.printStackTrace(); 00143 } 00144 //strings.add(item); 00145 } 00146 return strings; 00147 } 00148 }); 00149 } 00150 00157 @Override 00158 public Object getImage(Object object) { 00159 return overlayImage(object, getResourceLocator().getImage("full/obj16/ServiceClient")); 00160 } 00161 00168 @Override 00169 public String getText(Object object) { 00170 String label = ((ServiceClient)object).getName(); 00171 return label == null || label.length() == 0 ? 00172 getString("_UI_ServiceClient_type") : 00173 getString("_UI_ServiceClient_type") + " " + label; 00174 } 00175 00183 @Override 00184 public void notifyChanged(Notification notification) { 00185 updateChildren(notification); 00186 00187 switch (notification.getFeatureID(ServiceClient.class)) { 00188 case RosPackage.SERVICE_CLIENT__NAME: 00189 case RosPackage.SERVICE_CLIENT__MSG: 00190 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 00191 return; 00192 } 00193 super.notifyChanged(notification); 00194 } 00195 00203 @Override 00204 protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { 00205 super.collectNewChildDescriptors(newChildDescriptors, object); 00206 } 00207 00214 @Override 00215 public ResourceLocator getResourceLocator() { 00216 return RosEditPlugin.INSTANCE; 00217 } 00218 00219 }