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
00040 public class PublisherItemProvider
00041 extends ItemProviderAdapter
00042 implements
00043 IEditingDomainItemProvider,
00044 IStructuredItemContentProvider,
00045 ITreeItemContentProvider,
00046 IItemLabelProvider,
00047 IItemPropertySource {
00054 public PublisherItemProvider(AdapterFactory adapterFactory) {
00055 super(adapterFactory);
00056 }
00057
00064 @Override
00065 public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
00066 if (itemPropertyDescriptors == null) {
00067 super.getPropertyDescriptors(object);
00068
00069 addNamePropertyDescriptor(object);
00070 addQueueSizePropertyDescriptor(object);
00071 addLatchPropertyDescriptor(object);
00072 addEventHandlerPropertyDescriptor(object);
00073 addMsgPropertyDescriptor(object);
00074 }
00075 return itemPropertyDescriptors;
00076 }
00077
00084 protected void addNamePropertyDescriptor(Object object) {
00085 itemPropertyDescriptors.add
00086 (createItemPropertyDescriptor
00087 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00088 getResourceLocator(),
00089 getString("_UI_Publisher_name_feature"),
00090 getString("_UI_PropertyDescriptor_description", "_UI_Publisher_name_feature", "_UI_Publisher_type"),
00091 RosPackage.Literals.PUBLISHER__NAME,
00092 true,
00093 false,
00094 false,
00095 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00096 null,
00097 null));
00098 }
00099
00106 protected void addQueueSizePropertyDescriptor(Object object) {
00107 itemPropertyDescriptors.add
00108 (createItemPropertyDescriptor
00109 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00110 getResourceLocator(),
00111 getString("_UI_Publisher_queueSize_feature"),
00112 getString("_UI_PropertyDescriptor_description", "_UI_Publisher_queueSize_feature", "_UI_Publisher_type"),
00113 RosPackage.Literals.PUBLISHER__QUEUE_SIZE,
00114 true,
00115 false,
00116 false,
00117 ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE,
00118 null,
00119 null));
00120 }
00121
00128 protected void addLatchPropertyDescriptor(Object object) {
00129 itemPropertyDescriptors.add
00130 (createItemPropertyDescriptor
00131 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00132 getResourceLocator(),
00133 getString("_UI_Publisher_latch_feature"),
00134 getString("_UI_PropertyDescriptor_description", "_UI_Publisher_latch_feature", "_UI_Publisher_type"),
00135 RosPackage.Literals.PUBLISHER__LATCH,
00136 true,
00137 false,
00138 false,
00139 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
00140 null,
00141 null));
00142 }
00143
00150 protected void addEventHandlerPropertyDescriptor(Object object) {
00151 itemPropertyDescriptors.add
00152 (createItemPropertyDescriptor
00153 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00154 getResourceLocator(),
00155 getString("_UI_Publisher_eventHandler_feature"),
00156 getString("_UI_PropertyDescriptor_description", "_UI_Publisher_eventHandler_feature", "_UI_Publisher_type"),
00157 RosPackage.Literals.PUBLISHER__EVENT_HANDLER,
00158 true,
00159 false,
00160 false,
00161 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00162 null,
00163 null));
00164 }
00165
00169 protected void addMsgPropertyDescriptor(Object object) {
00170 itemPropertyDescriptors.add
00171 (new ItemPropertyDescriptor
00172 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00173 getResourceLocator(),
00174 getString("_UI_Publisher_msg_feature"),
00175 getString("_UI_PropertyDescriptor_description", "_UI_Publisher_msg_feature", "_UI_Publisher_type"),
00176 RosPackage.Literals.PUBLISHER__MSG,
00177 true,
00178 false,
00179 true,
00180 null,
00181 null,
00182 null) {
00183 @Override
00184 public Collection<?> getChoiceOfValues(Object object) {
00185 Publisher publisher = (Publisher) object;
00186 org.ros.model.ros.Package pack = (org.ros.model.ros.Package) publisher.eContainer().eContainer();
00187 System.out.println(pack.getName());
00188
00189 DataType test = DatatypesFactory.eINSTANCE.createSimpleType();
00190
00191 List<String> strings = new ArrayList<String>();
00192 for (String item: pack.getDepend()) {
00193 String cmd = "rosmsg package " + item;
00194 Runtime run = Runtime.getRuntime();
00195 Process pr;
00196 try {
00197 pr = run.exec(cmd);
00198 pr.waitFor();
00199 BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
00200 String line = "";
00201 while ((line=buf.readLine())!=null) {
00202 strings.add(line.replace("/", "::"));
00203 }
00204 } catch (IOException e) {
00205
00206 e.printStackTrace();
00207 } catch (InterruptedException e) {
00208
00209 e.printStackTrace();
00210 }
00211
00212 }
00213 return strings;
00214 }
00215 });
00216 }
00217
00224 @Override
00225 public Object getImage(Object object) {
00226 return overlayImage(object, getResourceLocator().getImage("full/obj16/Publisher"));
00227 }
00228
00235 @Override
00236 public String getText(Object object) {
00237 String label = ((Publisher)object).getName();
00238 return label == null || label.length() == 0 ?
00239 getString("_UI_Publisher_type") :
00240 getString("_UI_Publisher_type") + " " + label;
00241 }
00242
00250 @Override
00251 public void notifyChanged(Notification notification) {
00252 updateChildren(notification);
00253
00254 switch (notification.getFeatureID(Publisher.class)) {
00255 case RosPackage.PUBLISHER__NAME:
00256 case RosPackage.PUBLISHER__QUEUE_SIZE:
00257 case RosPackage.PUBLISHER__LATCH:
00258 case RosPackage.PUBLISHER__EVENT_HANDLER:
00259 case RosPackage.PUBLISHER__MSG:
00260 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
00261 return;
00262 }
00263 super.notifyChanged(notification);
00264 }
00265
00273 @Override
00274 protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
00275 super.collectNewChildDescriptors(newChildDescriptors, object);
00276 }
00277
00284 @Override
00285 public ResourceLocator getResourceLocator() {
00286 return RosEditPlugin.INSTANCE;
00287 }
00288
00289 }