| 126 | | |
| 127 | | { |
| 128 | | { |
| 129 | | Label resourcesLabel = new Label(mainWindow, SWT.NONE); |
| 130 | | resourcesLabel.setText("Available Resources"); |
| 131 | | resourcesLabel.setBounds(15, 48, 140, 17); |
| 132 | | } |
| 133 | | { |
| 134 | | refreshResourcesButton = |
| 135 | | new Button(mainWindow, SWT.PUSH | SWT.CENTER); |
| 136 | | refreshResourcesButton.setText("Refresh"); |
| 137 | | refreshResourcesButton.setBounds(163, 40, 82, 32); |
| 138 | | refreshResourcesButton.addSelectionListener( |
| 139 | | new SelectionAdapter() |
| 140 | | { |
| 141 | | public void widgetSelected(SelectionEvent event) |
| 142 | | { |
| 143 | | refreshResources(); |
| 144 | | } |
| 145 | | }); |
| 146 | | } |
| 147 | | { |
| 148 | | Tree resourcesTree = new Tree(mainWindow, SWT.BORDER); |
| 149 | | resourcesTree.setBounds(16, 83, 227, 282); |
| 150 | | resourcesTreeViewer = new TreeViewer(resourcesTree); |
| 151 | | resourcesTreeViewer.setContentProvider( |
| 152 | | new ResourceTreeContentProvider()); |
| 153 | | resourcesTreeViewer.setLabelProvider( |
| 154 | | new ResourceTreeLabelProvider()); |
| 155 | | resourcesTreeViewer.setAutoExpandLevel(2); |
| 156 | | resourcesTree.addFocusListener(this); |
| 157 | | resourcesTreeViewer.addDoubleClickListener( |
| 158 | | new IDoubleClickListener() |
| 159 | | { |
| 160 | | public void doubleClick(DoubleClickEvent event) |
| 161 | | { |
| 162 | | IStructuredSelection selection = |
| 163 | | (IStructuredSelection)event.getSelection(); |
| 164 | | if (!selection.isEmpty()) |
| 165 | | { |
| 166 | | ITreeNode node = |
| 167 | | (ITreeNode)selection.getFirstElement(); |
| 168 | | if (node.data() instanceof Component) |
| 169 | | { |
| 170 | | if (((Component)node.data()).isDevice()) |
| 171 | | { |
| 172 | | Node selectedNode = |
| 173 | | getSelectedPlatformNode(); |
| 174 | | if (selectedNode != null) |
| 175 | | { |
| 176 | | selectedNode.getDevices().append( |
| 177 | | node.data().deepcopy()); |
| 178 | | refreshPlatform(); |
| 179 | | setIsDirty(true); |
| 180 | | } |
| 181 | | } |
| 182 | | else |
| 183 | | { |
| 184 | | getActiveWaveform().getComponents().append( |
| 185 | | node.data().deepcopy()); |
| 186 | | refreshWaveform(); |
| 187 | | setIsDirty(true); |
| 188 | | } |
| 189 | | } |
| 190 | | else if (node.data() instanceof Node) |
| 191 | | { |
| 192 | | getActivePlatform().getNodes().append( |
| 193 | | node.data().deepcopy()); |
| 194 | | refreshPlatform(); |
| 195 | | setIsDirty(true); |
| 196 | | } |
| 197 | | } |
| 198 | | } |
| 199 | | }); |
| 200 | | |
| 201 | | final Action cannotAddToNode = new Action("Add to Node") |
| 202 | | { |
| 203 | | public boolean isEnabled() { return false; } |
| 204 | | }; |
| 205 | | |
| 206 | | final MenuManager rMgr = new MenuManager(); |
| 207 | | |
| 208 | | rMgr.setRemoveAllWhenShown(true); |
| 209 | | rMgr.addMenuListener(new IMenuListener() |
| 210 | | { |
| 211 | | public void menuAboutToShow(IMenuManager manager) |
| 212 | | { |
| 213 | | try |
| 214 | | { |
| 215 | | IStructuredSelection selection = |
| 216 | | (IStructuredSelection) |
| 217 | | resourcesTreeViewer.getSelection(); |
| 218 | | if (!selection.isEmpty()) |
| 219 | | { |
| 220 | | ITreeNode node = |
| 221 | | (ITreeNode)selection.getFirstElement(); |
| 222 | | if (node.parent() != null |
| 223 | | && node.parent().parent() == null) |
| 224 | | { |
| 225 | | if ("Components".equals( |
| 226 | | node.parent().getName())) |
| 227 | | { |
| 228 | | rMgr.add(new AddToWaveformAction( |
| 229 | | node.data())); |
| 230 | | } |
| 231 | | else if ("Devices".equals( |
| 232 | | node.parent().getName())) |
| 233 | | { |
| 234 | | Node selected = |
| 235 | | getSelectedPlatformNode(); |
| 236 | | if (selected == null) |
| 237 | | { |
| 238 | | rMgr.add(cannotAddToNode); |
| 239 | | } |
| 240 | | else |
| 241 | | { |
| 242 | | rMgr.add(new AddToNodeAction( |
| 243 | | node.data())); |
| 244 | | } |
| 245 | | } |
| 246 | | else if ("Nodes".equals( |
| 247 | | node.parent().getName())) |
| 248 | | { |
| 249 | | rMgr.add(new AddToPlatformAction( |
| 250 | | node.data())); |
| 251 | | } |
| 252 | | rMgr.add(new DoxygenAction(node.data())); |
| 253 | | rMgr.add(new Separator()); |
| 254 | | } |
| 255 | | } |
| 256 | | rMgr.add(new RefreshResourcesAction()); |
| 257 | | rMgr.add(new ExpandAllAction( |
| 258 | | resourcesTreeViewer)); |
| 259 | | } |
| 260 | | catch (Exception e) |
| 261 | | { |
| 262 | | log.error("menuAboutToShow()", e); |
| 263 | | } |
| 264 | | } |
| 265 | | }); |
| 266 | | resourcesTreeViewer.getControl().setMenu( |
| 267 | | rMgr.createContextMenu( |
| 268 | | resourcesTreeViewer.getControl())); |
| 269 | | |
| 270 | | //mainFrame().generateTestWaveform(); |
| 271 | | } |
| 272 | | { |
| 273 | | Label waveformLabel = new Label(mainWindow, SWT.NONE); |
| 274 | | waveformLabel.setText("Waveform"); |
| 275 | | waveformLabel.setBounds(445, 7, 77, 23); |
| 276 | | } |
| 277 | | { |
| 278 | | Tree waveformTree = new Tree(mainWindow, SWT.BORDER); |
| 279 | | waveformTree.setBounds(257, 30, 490, 149); |
| 280 | | waveformTreeViewer = new TreeViewer(waveformTree); |
| 281 | | waveformTreeViewer.setContentProvider( |
| 282 | | new ResourceTreeContentProvider()); |
| 283 | | waveformTreeViewer.setLabelProvider( |
| 284 | | new ResourceTreeLabelProvider()); |
| 285 | | waveformTree.addFocusListener(this); |
| 286 | | waveformTreeViewer.addDoubleClickListener( |
| 287 | | new IDoubleClickListener() |
| 288 | | { |
| 289 | | public void doubleClick(DoubleClickEvent event) |
| 290 | | { |
| 291 | | log.debug("double-click received"); |
| 292 | | IStructuredSelection selection = |
| 293 | | (IStructuredSelection)event.getSelection(); |
| 294 | | if (!selection.isEmpty()) |
| 295 | | { |
| 296 | | ITreeNode node = |
| 297 | | (ITreeNode)selection.getFirstElement(); |
| 298 | | if (node.data() instanceof Component) |
| 299 | | { |
| 300 | | openComponentInEditor((Component)node.data()); |
| 301 | | } |
| 302 | | } |
| 303 | | } |
| 304 | | }); |
| 305 | | |
| 306 | | |
| 307 | | final MenuManager wMgr = new MenuManager(); |
| 308 | | |
| 309 | | wMgr.setRemoveAllWhenShown(true); |
| 310 | | wMgr.addMenuListener(new IMenuListener() |
| 311 | | { |
| 312 | | public void menuAboutToShow(IMenuManager manager) |
| 313 | | { |
| 314 | | try |
| 315 | | { |
| 316 | | log.debug("menuAboutToShow(): about to show"); |
| 317 | | IStructuredSelection selection = |
| 318 | | (IStructuredSelection) |
| 319 | | waveformTreeViewer.getSelection(); |
| 320 | | if (!selection.isEmpty()) |
| 321 | | { |
| 322 | | final ITreeNode node = |
| 323 | | (ITreeNode)selection.getFirstElement(); |
| 324 | | if (node.data() instanceof Component) |
| 325 | | { |
| 326 | | wMgr.add(new ComponentEditAction( |
| 327 | | node.data())); |
| 328 | | wMgr.add(new Action("Rename") |
| 329 | | { |
| 330 | | public void run() |
| 331 | | { |
| 332 | | log.debug( |
| 333 | | "rename " + node.getName()); |
| 334 | | waveformTreeViewer.editElement( |
| 335 | | node, 0); |
| 336 | | } |
| 337 | | }); |
| 338 | | wMgr.add(new ComponentConnectAction( |
| 339 | | node.data())); |
| 340 | | wMgr.add(new ComponentRemoveAction( |
| 341 | | node.data())); |
| 342 | | wMgr.add(new Separator()); |
| 343 | | wMgr.add(new |
| 344 | | ComponentSetAssemblyControllerAction( |
| 345 | | node)); |
| 346 | | wMgr.add(new Separator()); |
| 347 | | } |
| 348 | | } |
| 349 | | wMgr.add(new ComponentRefreshAction()); |
| 350 | | wMgr.add(new ExpandAllAction( |
| 351 | | waveformTreeViewer)); |
| 352 | | } |
| 353 | | catch (Exception e) |
| 354 | | { |
| 355 | | log.error("menuAboutToShow()", e); |
| 356 | | } |
| 357 | | } |
| 358 | | }); |
| 359 | | waveformTreeViewer.getControl().setMenu( |
| 360 | | wMgr.createContextMenu( |
| 361 | | waveformTreeViewer.getControl())); |
| 362 | | |
| 363 | | waveformTreeViewer.setCellEditors(new CellEditor[] { |
| 364 | | new CustomTextCellEditor(waveformTreeViewer.getTree()) |
| 365 | | }); |
| 366 | | waveformTreeViewer.setColumnProperties(new String[] { "name" }); |
| 367 | | waveformTreeViewer.setCellModifier(new ICellModifier() |
| 368 | | { |
| 369 | | public boolean canModify( |
| 370 | | Object element, String property) |
| 371 | | { |
| 372 | | log.debug("canModify(" + element + ") = true"); |
| 373 | | return true; |
| 374 | | } |
| 375 | | |
| 376 | | public Object getValue( |
| 377 | | Object element, String property) |
| 378 | | { |
| 379 | | // Only the name is supported |
| 380 | | return ((ITreeNode)element).getName(); |
| 381 | | } |
| 382 | | |
| 383 | | public void modify( |
| 384 | | Object element, String property, Object value) |
| 385 | | { |
| 386 | | TreeItem item = (TreeItem)element; |
| 387 | | ITreeNode node = (ITreeNode)item.getData(); |
| 388 | | ((NamedObject)node.data()).setName( |
| 389 | | value.toString()); |
| 390 | | waveformTreeViewer.update(node, null); |
| 391 | | setIsDirty(true); |
| 392 | | } |
| 393 | | }); |
| 394 | | TreeViewerEditor.create(waveformTreeViewer, |
| 395 | | new ColumnViewerEditorActivationStrategy(waveformTreeViewer) |
| 396 | | { |
| 397 | | protected boolean isEditorActivationEvent( |
| 398 | | ColumnViewerEditorActivationEvent event) |
| 399 | | { |
| 400 | | return event.eventType == |
| 401 | | ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
| 402 | | } |
| 403 | | }, ColumnViewerEditor.DEFAULT); |
| 404 | | } |
| 405 | | { |
| 406 | | Tree platformTree = new Tree(mainWindow, SWT.BORDER); |
| 407 | | platformTree.setBounds(257, 191, 490, 173); |
| 408 | | platformTreeViewer = new TreeViewer(platformTree); |
| 409 | | platformTreeViewer.setContentProvider( |
| 410 | | new ResourceTreeContentProvider()); |
| 411 | | platformTreeViewer.setLabelProvider( |
| 412 | | new ResourceTreeLabelProvider()); |
| 413 | | platformTreeViewer.setAutoExpandLevel(2); |
| 414 | | platformTree.addFocusListener(this); |
| 415 | | |
| 416 | | final MenuManager pMgr = new MenuManager(); |
| 417 | | |
| 418 | | pMgr.setRemoveAllWhenShown(true); |
| 419 | | pMgr.addMenuListener(new IMenuListener() |
| 420 | | { |
| 421 | | public void menuAboutToShow(IMenuManager manager) |
| 422 | | { |
| 423 | | try |
| 424 | | { |
| 425 | | log.debug("menuAboutToShow(): about to show"); |
| 426 | | IStructuredSelection selection = |
| 427 | | (IStructuredSelection) |
| 428 | | platformTreeViewer.getSelection(); |
| 429 | | if (!selection.isEmpty()) |
| 430 | | { |
| 431 | | final ITreeNode node = |
| 432 | | (ITreeNode)selection.getFirstElement(); |
| 433 | | pMgr.add(new Action("Rename") |
| 434 | | { |
| 435 | | public void run() |
| 436 | | { |
| 437 | | log.debug("rename " + node.getName()); |
| 438 | | platformTreeViewer.editElement( |
| 439 | | node, 0); |
| 440 | | } |
| 441 | | }); |
| 442 | | pMgr.add(new Separator()); |
| 443 | | pMgr.add(new ExpandAllAction( |
| 444 | | platformTreeViewer)); |
| 445 | | } |
| 446 | | } |
| 447 | | catch (Exception e) |
| 448 | | { |
| 449 | | log.error("menuAboutToShow()", e); |
| 450 | | } |
| 451 | | } |
| 452 | | }); |
| 453 | | platformTreeViewer.getControl().setMenu( |
| 454 | | pMgr.createContextMenu( |
| 455 | | platformTreeViewer.getControl())); |
| 456 | | platformTreeViewer.setCellEditors(new CellEditor[] { |
| 457 | | new CustomTextCellEditor(platformTreeViewer.getTree()) |
| 458 | | }); |
| 459 | | platformTreeViewer.setColumnProperties(new String[] { "name" }); |
| 460 | | platformTreeViewer.setCellModifier(new ICellModifier() |
| 461 | | { |
| 462 | | public boolean canModify( |
| 463 | | Object element, String property) |
| 464 | | { |
| 465 | | log.debug("canModify(" + element + ") = true"); |
| 466 | | return true; |
| 467 | | } |
| 468 | | |
| 469 | | public Object getValue( |
| 470 | | Object element, String property) |
| 471 | | { |
| 472 | | // Only the name is supported |
| 473 | | return ((ITreeNode)element).getName(); |
| 474 | | } |
| 475 | | |
| 476 | | public void modify( |
| 477 | | Object element, String property, Object value) |
| 478 | | { |
| 479 | | TreeItem item = (TreeItem)element; |
| 480 | | ITreeNode node = (ITreeNode)item.getData(); |
| 481 | | ((NamedObject)node.data()).setName( |
| 482 | | value.toString()); |
| 483 | | platformTreeViewer.update(node, null); |
| 484 | | setIsDirty(true); |
| 485 | | } |
| 486 | | }); |
| 487 | | TreeViewerEditor.create(platformTreeViewer, |
| 488 | | new ColumnViewerEditorActivationStrategy(platformTreeViewer) |
| 489 | | { |
| 490 | | protected boolean isEditorActivationEvent( |
| 491 | | ColumnViewerEditorActivationEvent event) |
| 492 | | { |
| 493 | | return event.eventType == |
| 494 | | ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
| 495 | | } |
| 496 | | }, ColumnViewerEditor.DEFAULT); |
| 497 | | } |
| 498 | | mainWindow.setSize( |
| 499 | | mainWindow.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
| 500 | | } |
| | 123 | mainWindow.setLayout(new GridLayout(2, false)); |
| | 124 | |
| | 125 | Label resourcesLabel = new Label(mainWindow, SWT.NONE); |
| | 126 | resourcesLabel.setText("Available Resources"); |
| | 127 | //resourcesLabel.setBounds(15, 48, 140, 17); |
| | 128 | resourcesLabel.setLayoutData( |
| | 129 | new GridData(SWT.CENTER, SWT.BOTTOM, true, false)); |
| | 130 | |
| | 131 | Label waveformLabel = new Label(mainWindow, SWT.NONE); |
| | 132 | waveformLabel.setText("Waveform"); |
| | 133 | //waveformLabel.setBounds(445, 7, 77, 23); |
| | 134 | waveformLabel.setLayoutData( |
| | 135 | new GridData(SWT.CENTER, SWT.BOTTOM, true, false)); |
| | 136 | |
| | 137 | createResourcesTree(mainWindow); |
| | 138 | createWaveformTree(mainWindow); |
| | 139 | |
| | 140 | Label platformLabel = new Label(mainWindow, SWT.NONE); |
| | 141 | platformLabel.setText("Platform"); |
| | 142 | platformLabel.setLayoutData( |
| | 143 | new GridData(SWT.CENTER, SWT.BOTTOM, true, false)); |
| | 144 | |
| | 145 | createPlatformTree(mainWindow); |
| | 146 | |
| | 147 | mainWindow.setSize(mainWindow.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
| | 692 | |
| | 693 | // ---------------------------------------------------------- |
| | 694 | private void createResourcesTree(Composite parent) |
| | 695 | { |
| | 696 | Tree resourcesTree = new Tree(parent, SWT.BORDER); |
| | 697 | //resourcesTree.setBounds(16, 83, 227, 282); |
| | 698 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3); |
| | 699 | data.minimumHeight = 200; |
| | 700 | data.minimumWidth = 200; |
| | 701 | resourcesTree.setLayoutData(data); |
| | 702 | resourcesTreeViewer = new TreeViewer(resourcesTree); |
| | 703 | resourcesTreeViewer.setContentProvider( |
| | 704 | new ResourceTreeContentProvider()); |
| | 705 | resourcesTreeViewer.setLabelProvider( |
| | 706 | new ResourceTreeLabelProvider()); |
| | 707 | resourcesTreeViewer.setAutoExpandLevel(2); |
| | 708 | resourcesTree.addFocusListener(this); |
| | 709 | resourcesTreeViewer.addDoubleClickListener( |
| | 710 | new IDoubleClickListener() |
| | 711 | { |
| | 712 | public void doubleClick(DoubleClickEvent event) |
| | 713 | { |
| | 714 | IStructuredSelection selection = |
| | 715 | (IStructuredSelection)event.getSelection(); |
| | 716 | if (!selection.isEmpty()) |
| | 717 | { |
| | 718 | ITreeNode node = (ITreeNode)selection.getFirstElement(); |
| | 719 | if (node.data() instanceof Component) |
| | 720 | { |
| | 721 | if (((Component)node.data()).isDevice()) |
| | 722 | { |
| | 723 | Node selectedNode = getSelectedPlatformNode(); |
| | 724 | if (selectedNode != null) |
| | 725 | { |
| | 726 | selectedNode.getDevices().append( |
| | 727 | node.data().deepcopy()); |
| | 728 | refreshPlatform(); |
| | 729 | setIsDirty(true); |
| | 730 | } |
| | 731 | } |
| | 732 | else |
| | 733 | { |
| | 734 | getActiveWaveform().getComponents().append( |
| | 735 | node.data().deepcopy()); |
| | 736 | refreshWaveform(); |
| | 737 | setIsDirty(true); |
| | 738 | } |
| | 739 | } |
| | 740 | else if (node.data() instanceof Node) |
| | 741 | { |
| | 742 | getActivePlatform().getNodes().append( |
| | 743 | node.data().deepcopy()); |
| | 744 | refreshPlatform(); |
| | 745 | setIsDirty(true); |
| | 746 | } |
| | 747 | } |
| | 748 | } |
| | 749 | }); |
| | 750 | |
| | 751 | final Action cannotAddToNode = new Action("Add to Node") |
| | 752 | { |
| | 753 | public boolean isEnabled() { return false; } |
| | 754 | }; |
| | 755 | |
| | 756 | final MenuManager rMgr = new MenuManager(); |
| | 757 | |
| | 758 | rMgr.setRemoveAllWhenShown(true); |
| | 759 | rMgr.addMenuListener(new IMenuListener() |
| | 760 | { |
| | 761 | public void menuAboutToShow(IMenuManager manager) |
| | 762 | { |
| | 763 | try |
| | 764 | { |
| | 765 | IStructuredSelection selection = (IStructuredSelection) |
| | 766 | resourcesTreeViewer.getSelection(); |
| | 767 | if (!selection.isEmpty()) |
| | 768 | { |
| | 769 | ITreeNode node = |
| | 770 | (ITreeNode)selection.getFirstElement(); |
| | 771 | if (node.parent() != null |
| | 772 | && node.parent().parent() == null) |
| | 773 | { |
| | 774 | if ("Components".equals(node.parent().getName())) |
| | 775 | { |
| | 776 | rMgr.add(new AddToWaveformAction(node.data())); |
| | 777 | } |
| | 778 | else if ("Devices".equals(node.parent().getName())) |
| | 779 | { |
| | 780 | Node selected = getSelectedPlatformNode(); |
| | 781 | if (selected == null) |
| | 782 | { |
| | 783 | rMgr.add(cannotAddToNode); |
| | 784 | } |
| | 785 | else |
| | 786 | { |
| | 787 | rMgr.add(new AddToNodeAction(node.data())); |
| | 788 | } |
| | 789 | } |
| | 790 | else if ("Nodes".equals(node.parent().getName())) |
| | 791 | { |
| | 792 | rMgr.add(new AddToPlatformAction(node.data())); |
| | 793 | } |
| | 794 | rMgr.add(new DoxygenAction(node.data())); |
| | 795 | rMgr.add(new Separator()); |
| | 796 | } |
| | 797 | } |
| | 798 | rMgr.add(new RefreshResourcesAction()); |
| | 799 | rMgr.add(new ExpandAllAction(resourcesTreeViewer)); |
| | 800 | } |
| | 801 | catch (Exception e) |
| | 802 | { |
| | 803 | log.error("menuAboutToShow()", e); |
| | 804 | } |
| | 805 | } |
| | 806 | }); |
| | 807 | resourcesTreeViewer.getControl().setMenu(rMgr.createContextMenu( |
| | 808 | resourcesTreeViewer.getControl())); |
| | 809 | } |
| | 810 | |
| | 811 | |
| | 812 | // ---------------------------------------------------------- |
| | 813 | private void createWaveformTree(Composite parent) |
| | 814 | { |
| | 815 | Tree waveformTree = new Tree(parent, SWT.BORDER); |
| | 816 | //waveformTree.setBounds(257, 30, 490, 149); |
| | 817 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); |
| | 818 | data.minimumHeight = 100; |
| | 819 | data.minimumWidth = 200; |
| | 820 | waveformTree.setLayoutData(data); |
| | 821 | waveformTreeViewer = new TreeViewer(waveformTree); |
| | 822 | waveformTreeViewer.setContentProvider( |
| | 823 | new ResourceTreeContentProvider()); |
| | 824 | waveformTreeViewer.setLabelProvider( |
| | 825 | new ResourceTreeLabelProvider()); |
| | 826 | waveformTree.addFocusListener(this); |
| | 827 | waveformTreeViewer.addDoubleClickListener( |
| | 828 | new IDoubleClickListener() |
| | 829 | { |
| | 830 | public void doubleClick(DoubleClickEvent event) |
| | 831 | { |
| | 832 | log.debug("double-click received"); |
| | 833 | IStructuredSelection selection = |
| | 834 | (IStructuredSelection)event.getSelection(); |
| | 835 | if (!selection.isEmpty()) |
| | 836 | { |
| | 837 | ITreeNode node = (ITreeNode)selection.getFirstElement(); |
| | 838 | if (node.data() instanceof Component) |
| | 839 | { |
| | 840 | openComponentInEditor((Component)node.data()); |
| | 841 | } |
| | 842 | } |
| | 843 | } |
| | 844 | }); |
| | 845 | |
| | 846 | final MenuManager wMgr = new MenuManager(); |
| | 847 | |
| | 848 | wMgr.setRemoveAllWhenShown(true); |
| | 849 | wMgr.addMenuListener(new IMenuListener() |
| | 850 | { |
| | 851 | public void menuAboutToShow(IMenuManager manager) |
| | 852 | { |
| | 853 | try |
| | 854 | { |
| | 855 | log.debug("menuAboutToShow(): about to show"); |
| | 856 | IStructuredSelection selection = (IStructuredSelection) |
| | 857 | waveformTreeViewer.getSelection(); |
| | 858 | if (!selection.isEmpty()) |
| | 859 | { |
| | 860 | final ITreeNode node = |
| | 861 | (ITreeNode)selection.getFirstElement(); |
| | 862 | if (node.data() instanceof Component) |
| | 863 | { |
| | 864 | wMgr.add(new ComponentEditAction(node.data())); |
| | 865 | wMgr.add(new Action("Rename") |
| | 866 | { |
| | 867 | public void run() |
| | 868 | { |
| | 869 | log.debug("rename " + node.getName()); |
| | 870 | waveformTreeViewer.editElement(node, 0); |
| | 871 | } |
| | 872 | }); |
| | 873 | wMgr.add(new ComponentConnectAction(node.data())); |
| | 874 | wMgr.add(new ComponentRemoveAction(node.data())); |
| | 875 | wMgr.add(new Separator()); |
| | 876 | wMgr.add(new ComponentSetAssemblyControllerAction( |
| | 877 | node)); |
| | 878 | wMgr.add(new Separator()); |
| | 879 | } |
| | 880 | } |
| | 881 | wMgr.add(new ComponentRefreshAction()); |
| | 882 | wMgr.add(new ExpandAllAction(waveformTreeViewer)); |
| | 883 | } |
| | 884 | catch (Exception e) |
| | 885 | { |
| | 886 | log.error("menuAboutToShow()", e); |
| | 887 | } |
| | 888 | } |
| | 889 | }); |
| | 890 | waveformTreeViewer.getControl().setMenu(wMgr.createContextMenu( |
| | 891 | waveformTreeViewer.getControl())); |
| | 892 | |
| | 893 | waveformTreeViewer.setCellEditors(new CellEditor[] { |
| | 894 | new CustomTextCellEditor(waveformTreeViewer.getTree()) |
| | 895 | }); |
| | 896 | waveformTreeViewer.setColumnProperties(new String[] { "name" }); |
| | 897 | waveformTreeViewer.setCellModifier(new ICellModifier() |
| | 898 | { |
| | 899 | public boolean canModify(Object element, String property) |
| | 900 | { |
| | 901 | return true; |
| | 902 | } |
| | 903 | |
| | 904 | public Object getValue(Object element, String property) |
| | 905 | { |
| | 906 | // Only the name is supported |
| | 907 | return ((ITreeNode)element).getName(); |
| | 908 | } |
| | 909 | |
| | 910 | public void modify( |
| | 911 | Object element, String property, Object value) |
| | 912 | { |
| | 913 | if (value == null) return; |
| | 914 | String newName = value.toString(); |
| | 915 | // Disallow empty names |
| | 916 | if ("".equals(newName)) return; |
| | 917 | |
| | 918 | TreeItem item = (TreeItem)element; |
| | 919 | ITreeNode node = (ITreeNode)item.getData(); |
| | 920 | ((NamedObject)node.data()).setName(newName); |
| | 921 | waveformTreeViewer.update(node, null); |
| | 922 | setIsDirty(true); |
| | 923 | } |
| | 924 | }); |
| | 925 | TreeViewerEditor.create(waveformTreeViewer, |
| | 926 | new ColumnViewerEditorActivationStrategy(waveformTreeViewer) |
| | 927 | { |
| | 928 | protected boolean isEditorActivationEvent( |
| | 929 | ColumnViewerEditorActivationEvent event) |
| | 930 | { |
| | 931 | return event.eventType == |
| | 932 | ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
| | 933 | } |
| | 934 | }, ColumnViewerEditor.DEFAULT); |
| | 935 | } |
| | 936 | |
| | 937 | |
| | 938 | // ---------------------------------------------------------- |
| | 939 | private void createPlatformTree(Composite parent) |
| | 940 | { |
| | 941 | Tree platformTree = new Tree(parent, SWT.BORDER); |
| | 942 | // platformTree.setBounds(257, 191, 490, 173); |
| | 943 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); |
| | 944 | data.minimumHeight = 100; |
| | 945 | data.minimumWidth = 200; |
| | 946 | platformTree.setLayoutData(data); |
| | 947 | platformTreeViewer = new TreeViewer(platformTree); |
| | 948 | platformTreeViewer.setContentProvider( |
| | 949 | new ResourceTreeContentProvider()); |
| | 950 | platformTreeViewer.setLabelProvider( |
| | 951 | new ResourceTreeLabelProvider()); |
| | 952 | platformTreeViewer.setAutoExpandLevel(2); |
| | 953 | platformTree.addFocusListener(this); |
| | 954 | |
| | 955 | final MenuManager pMgr = new MenuManager(); |
| | 956 | |
| | 957 | pMgr.setRemoveAllWhenShown(true); |
| | 958 | pMgr.addMenuListener(new IMenuListener() |
| | 959 | { |
| | 960 | public void menuAboutToShow(IMenuManager manager) |
| | 961 | { |
| | 962 | try |
| | 963 | { |
| | 964 | log.debug("menuAboutToShow(): about to show"); |
| | 965 | IStructuredSelection selection = (IStructuredSelection) |
| | 966 | platformTreeViewer.getSelection(); |
| | 967 | if (!selection.isEmpty()) |
| | 968 | { |
| | 969 | final ITreeNode node = |
| | 970 | (ITreeNode)selection.getFirstElement(); |
| | 971 | pMgr.add(new Action("Rename") |
| | 972 | { |
| | 973 | public void run() |
| | 974 | { |
| | 975 | log.debug("rename " + node.getName()); |
| | 976 | platformTreeViewer.editElement(node, 0); |
| | 977 | } |
| | 978 | }); |
| | 979 | pMgr.add(new Separator()); |
| | 980 | pMgr.add(new ExpandAllAction(platformTreeViewer)); |
| | 981 | } |
| | 982 | } |
| | 983 | catch (Exception e) |
| | 984 | { |
| | 985 | log.error("menuAboutToShow()", e); |
| | 986 | } |
| | 987 | } |
| | 988 | }); |
| | 989 | platformTreeViewer.getControl().setMenu(pMgr.createContextMenu( |
| | 990 | platformTreeViewer.getControl())); |
| | 991 | platformTreeViewer.setCellEditors(new CellEditor[] { |
| | 992 | new CustomTextCellEditor(platformTreeViewer.getTree()) |
| | 993 | }); |
| | 994 | platformTreeViewer.setColumnProperties(new String[] { "name" }); |
| | 995 | platformTreeViewer.setCellModifier(new ICellModifier() |
| | 996 | { |
| | 997 | public boolean canModify(Object element, String property) |
| | 998 | { |
| | 999 | log.debug("canModify(" + element + ") = true"); |
| | 1000 | return true; |
| | 1001 | } |
| | 1002 | |
| | 1003 | public Object getValue(Object element, String property) |
| | 1004 | { |
| | 1005 | // Only the name is supported |
| | 1006 | return ((ITreeNode)element).getName(); |
| | 1007 | } |
| | 1008 | |
| | 1009 | public void modify( |
| | 1010 | Object element, String property, Object value) |
| | 1011 | { |
| | 1012 | if (value == null) return; |
| | 1013 | String newName = value.toString(); |
| | 1014 | // Disallow empty names |
| | 1015 | if ("".equals(newName)) return; |
| | 1016 | |
| | 1017 | TreeItem item = (TreeItem)element; |
| | 1018 | ITreeNode node = (ITreeNode)item.getData(); |
| | 1019 | ((NamedObject)node.data()).setName(newName); |
| | 1020 | platformTreeViewer.update(node, null); |
| | 1021 | setIsDirty(true); |
| | 1022 | } |
| | 1023 | }); |
| | 1024 | TreeViewerEditor.create(platformTreeViewer, |
| | 1025 | new ColumnViewerEditorActivationStrategy(platformTreeViewer) |
| | 1026 | { |
| | 1027 | protected boolean isEditorActivationEvent( |
| | 1028 | ColumnViewerEditorActivationEvent event) |
| | 1029 | { |
| | 1030 | return event.eventType == |
| | 1031 | ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
| | 1032 | } |
| | 1033 | }, ColumnViewerEditor.DEFAULT); |
| | 1034 | } |
| | 1035 | |