$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.Publisher; 00032 import org.ros.model.ros.RosPackage; 00033 import org.ros.model.ros.Subscriber; 00034 00041 public class SubscriberItemProvider 00042 extends ItemProviderAdapter 00043 implements 00044 IEditingDomainItemProvider, 00045 IStructuredItemContentProvider, 00046 ITreeItemContentProvider, 00047 IItemLabelProvider, 00048 IItemPropertySource { 00055 public SubscriberItemProvider(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 addQueueSizePropertyDescriptor(object); 00072 addEventHandlerPropertyDescriptor(object); 00073 addMsgPropertyDescriptor(object); 00074 addEventPortPropertyDescriptor(object); 00075 } 00076 return itemPropertyDescriptors; 00077 } 00078 00085 protected void addNamePropertyDescriptor(Object object) { 00086 itemPropertyDescriptors.add 00087 (createItemPropertyDescriptor 00088 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00089 getResourceLocator(), 00090 getString("_UI_Subscriber_name_feature"), 00091 getString("_UI_PropertyDescriptor_description", "_UI_Subscriber_name_feature", "_UI_Subscriber_type"), 00092 RosPackage.Literals.SUBSCRIBER__NAME, 00093 true, 00094 false, 00095 false, 00096 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 00097 null, 00098 null)); 00099 } 00100 00107 protected void addQueueSizePropertyDescriptor(Object object) { 00108 itemPropertyDescriptors.add 00109 (createItemPropertyDescriptor 00110 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00111 getResourceLocator(), 00112 getString("_UI_Subscriber_queueSize_feature"), 00113 getString("_UI_PropertyDescriptor_description", "_UI_Subscriber_queueSize_feature", "_UI_Subscriber_type"), 00114 RosPackage.Literals.SUBSCRIBER__QUEUE_SIZE, 00115 true, 00116 false, 00117 false, 00118 ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE, 00119 null, 00120 null)); 00121 } 00122 00129 protected void addEventHandlerPropertyDescriptor(Object object) { 00130 itemPropertyDescriptors.add 00131 (createItemPropertyDescriptor 00132 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00133 getResourceLocator(), 00134 getString("_UI_Subscriber_eventHandler_feature"), 00135 getString("_UI_PropertyDescriptor_description", "_UI_Subscriber_eventHandler_feature", "_UI_Subscriber_type"), 00136 RosPackage.Literals.SUBSCRIBER__EVENT_HANDLER, 00137 true, 00138 false, 00139 false, 00140 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 00141 null, 00142 null)); 00143 } 00144 00148 protected void addMsgPropertyDescriptor(Object object) { 00149 itemPropertyDescriptors.add 00150 (new ItemPropertyDescriptor 00151 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00152 getResourceLocator(), 00153 getString("_UI_Subscriber_msg_feature"), 00154 getString("_UI_PropertyDescriptor_description", "_UI_Subscriber_msg_feature", "_UI_Subscriber_type"), 00155 RosPackage.Literals.SUBSCRIBER__MSG, 00156 true, 00157 false, 00158 false, 00159 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 00160 null, 00161 null){ 00162 @Override 00163 public Collection<?> getChoiceOfValues(Object object) { 00164 Subscriber subscriber = (Subscriber) object; 00165 org.ros.model.ros.Package pack = (org.ros.model.ros.Package) subscriber.eContainer().eContainer(); 00166 System.out.println(pack.getName()); 00167 00168 DataType test = DatatypesFactory.eINSTANCE.createSimpleType(); 00169 00170 List<String> strings = new ArrayList<String>(); // Copy the students to a temporary list 00171 for (String item: pack.getDepend()) { 00172 String cmd = "rosmsg package " + item; 00173 Runtime run = Runtime.getRuntime(); 00174 Process pr; 00175 try { 00176 pr = run.exec(cmd); 00177 pr.waitFor(); 00178 BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); 00179 String line = ""; 00180 while ((line=buf.readLine())!=null) { 00181 strings.add(line.replace("/", "::")); 00182 } 00183 } catch (IOException e) { 00184 // TODO Auto-generated catch block 00185 e.printStackTrace(); 00186 } catch (InterruptedException e) { 00187 // TODO Auto-generated catch block 00188 e.printStackTrace(); 00189 } 00190 //strings.add(item); 00191 } 00192 return strings; 00193 } 00194 }); 00195 } 00196 00203 protected void addEventPortPropertyDescriptor(Object object) { 00204 itemPropertyDescriptors.add 00205 (createItemPropertyDescriptor 00206 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 00207 getResourceLocator(), 00208 getString("_UI_Subscriber_eventPort_feature"), 00209 getString("_UI_PropertyDescriptor_description", "_UI_Subscriber_eventPort_feature", "_UI_Subscriber_type"), 00210 RosPackage.Literals.SUBSCRIBER__EVENT_PORT, 00211 true, 00212 false, 00213 false, 00214 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 00215 null, 00216 null)); 00217 } 00218 00225 @Override 00226 public Object getImage(Object object) { 00227 return overlayImage(object, getResourceLocator().getImage("full/obj16/Subscriber")); 00228 } 00229 00236 @Override 00237 public String getText(Object object) { 00238 String label = ((Subscriber)object).getName(); 00239 return label == null || label.length() == 0 ? 00240 getString("_UI_Subscriber_type") : 00241 getString("_UI_Subscriber_type") + " " + label; 00242 } 00243 00251 @Override 00252 public void notifyChanged(Notification notification) { 00253 updateChildren(notification); 00254 00255 switch (notification.getFeatureID(Subscriber.class)) { 00256 case RosPackage.SUBSCRIBER__NAME: 00257 case RosPackage.SUBSCRIBER__QUEUE_SIZE: 00258 case RosPackage.SUBSCRIBER__EVENT_HANDLER: 00259 case RosPackage.SUBSCRIBER__MSG: 00260 case RosPackage.SUBSCRIBER__EVENT_PORT: 00261 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 00262 return; 00263 } 00264 super.notifyChanged(notification); 00265 } 00266 00274 @Override 00275 protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { 00276 super.collectNewChildDescriptors(newChildDescriptors, object); 00277 } 00278 00285 @Override 00286 public ResourceLocator getResourceLocator() { 00287 return RosEditPlugin.INSTANCE; 00288 } 00289 00290 }