1 17 package org.eclipse.emf.codegen.ecore.genmodel.presentation; 18 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.EventObject ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 28 import org.eclipse.core.resources.IFile; 29 import org.eclipse.core.resources.IMarker; 30 import org.eclipse.core.resources.IResource; 31 import org.eclipse.core.resources.IResourceChangeEvent; 32 import org.eclipse.core.resources.IResourceChangeListener; 33 import org.eclipse.core.resources.IResourceDelta; 34 import org.eclipse.core.resources.IResourceDeltaVisitor; 35 import org.eclipse.core.resources.ResourcesPlugin; 36 import org.eclipse.core.runtime.CoreException; 37 import org.eclipse.core.runtime.IPath; 38 import org.eclipse.core.runtime.IProgressMonitor; 39 import org.eclipse.core.runtime.IStatus; 40 import org.eclipse.jdt.core.JavaCore; 41 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; 42 import org.eclipse.jface.action.IMenuListener; 43 import org.eclipse.jface.action.IMenuManager; 44 import org.eclipse.jface.action.IStatusLineManager; 45 import org.eclipse.jface.action.IToolBarManager; 46 import org.eclipse.jface.action.MenuManager; 47 import org.eclipse.jface.action.Separator; 48 import org.eclipse.jface.dialogs.ErrorDialog; 49 import org.eclipse.jface.dialogs.MessageDialog; 50 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 51 import org.eclipse.jface.viewers.ISelection; 52 import org.eclipse.jface.viewers.ISelectionChangedListener; 53 import org.eclipse.jface.viewers.ISelectionProvider; 54 import org.eclipse.jface.viewers.IStructuredSelection; 55 import org.eclipse.jface.viewers.SelectionChangedEvent; 56 import org.eclipse.jface.viewers.StructuredSelection; 57 import org.eclipse.jface.viewers.StructuredViewer; 58 import org.eclipse.jface.viewers.TreeViewer; 59 import org.eclipse.jface.viewers.Viewer; 60 import org.eclipse.swt.SWT; 61 import org.eclipse.swt.custom.CTabFolder; 62 import org.eclipse.swt.dnd.DND; 63 import org.eclipse.swt.dnd.Transfer; 64 import org.eclipse.swt.events.ControlAdapter; 65 import org.eclipse.swt.events.ControlEvent; 66 import org.eclipse.swt.graphics.Point; 67 import org.eclipse.swt.widgets.Control; 68 import org.eclipse.swt.widgets.Menu; 69 import org.eclipse.swt.widgets.Tree; 70 import org.eclipse.ui.IActionBars; 71 import org.eclipse.ui.IEditorInput; 72 import org.eclipse.ui.IEditorPart; 73 import org.eclipse.ui.IEditorSite; 74 import org.eclipse.ui.IFileEditorInput; 75 import org.eclipse.ui.IPartListener; 76 import org.eclipse.ui.IWorkbenchPart; 77 import org.eclipse.ui.PartInitException; 78 import org.eclipse.ui.actions.WorkspaceModifyOperation; 79 import org.eclipse.ui.dialogs.SaveAsDialog; 80 import org.eclipse.ui.part.FileEditorInput; 81 import org.eclipse.ui.part.MultiPageEditorPart; 82 import org.eclipse.ui.views.properties.IPropertySheetPage; 83 import org.eclipse.ui.views.properties.PropertySheet; 84 import org.eclipse.ui.views.properties.PropertySheetPage; 85 86 import org.eclipse.emf.codegen.ecore.genmodel.GenModel; 87 import org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin; 88 import org.eclipse.emf.common.command.BasicCommandStack; 89 import org.eclipse.emf.common.command.Command; 90 import org.eclipse.emf.common.command.CommandStack; 91 import org.eclipse.emf.common.command.CommandStackListener; 92 import org.eclipse.emf.common.notify.AdapterFactory; 93 import org.eclipse.emf.common.ui.viewer.IViewerProvider; 94 import org.eclipse.emf.common.util.URI; 95 import org.eclipse.emf.ecore.plugin.EcorePlugin; 96 import org.eclipse.emf.ecore.resource.Resource; 97 import org.eclipse.emf.ecore.resource.ResourceSet; 98 import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; 99 import org.eclipse.emf.edit.domain.EditingDomain; 100 import org.eclipse.emf.edit.domain.IEditingDomainProvider; 101 import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator; 102 import org.eclipse.emf.edit.provider.ComposedAdapterFactory; 103 import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor; 104 import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor; 105 import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter; 106 import org.eclipse.emf.edit.ui.dnd.LocalTransfer; 107 import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter; 108 import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; 109 import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; 110 111 112 118 public class GenModelEditor 119 extends MultiPageEditorPart 120 implements IEditingDomainProvider, ISelectionProvider, IMenuListener, IViewerProvider 121 { 122 128 protected AdapterFactoryEditingDomain editingDomain; 129 130 136 protected ComposedAdapterFactory adapterFactory; 137 138 144 protected PropertySheetPage propertySheetPage; 145 146 152 protected Viewer currentViewer; 153 154 160 protected ISelectionChangedListener selectionChangedListener; 161 162 168 protected Collection selectionChangedListeners = new ArrayList (); 169 170 176 protected ISelection editorSelection = StructuredSelection.EMPTY; 177 178 184 protected IPartListener partListener = 185 new IPartListener() 186 { 187 public void partActivated(IWorkbenchPart p) 188 { 189 if (p instanceof PropertySheet) 190 { 191 if (((PropertySheet)p).getCurrentPage() == propertySheetPage) 192 { 193 getActionBarContributor().setActiveEditor(GenModelEditor.this); 194 handleActivate(); 195 } 196 } 197 else if (p == GenModelEditor.this) 198 { 199 handleActivate(); 200 } 201 } 202 public void partBroughtToTop(IWorkbenchPart p) 203 { 204 } 205 public void partClosed(IWorkbenchPart p) 206 { 207 } 208 public void partDeactivated(IWorkbenchPart p) 209 { 210 } 211 public void partOpened(IWorkbenchPart p) 212 { 213 } 214 }; 215 216 220 Collection removedResources = new ArrayList (); 221 222 226 Collection changedResources = new ArrayList (); 227 228 232 Collection savedResources = new ArrayList (); 233 234 240 protected IResourceChangeListener resourceChangeListener = 241 new IResourceChangeListener() 242 { 243 public void resourceChanged(IResourceChangeEvent event) 244 { 245 { 248 IResourceDelta delta = event.getDelta(); 249 try 250 { 251 class ResourceDeltaVisitor implements IResourceDeltaVisitor 252 { 253 protected ResourceSet resourceSet = editingDomain.getResourceSet(); 254 protected Collection changedResources = new ArrayList (); 255 protected Collection removedResources = new ArrayList (); 256 257 public boolean visit(IResourceDelta delta) 258 { 259 if (delta.getResource().getType() == IResource.FILE) 260 { 261 if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED)) != 0) 262 { 263 Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false); 264 if (resource != null) 265 { 266 if ((delta.getKind() & IResourceDelta.REMOVED) != 0) 267 { 268 removedResources.add(resource); 269 } 270 else 271 { 272 changedResources.add(resource); 273 } 274 } 275 } 276 } 277 278 return true; 279 } 280 281 public Collection getChangedResources() 282 { 283 return changedResources; 284 } 285 286 public Collection getRemovedResources() 287 { 288 return removedResources; 289 } 290 } 291 292 ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); 293 delta.accept(visitor); 294 295 if (!visitor.getRemovedResources().isEmpty()) 296 { 297 removedResources.addAll(visitor.getRemovedResources()); 298 if (!isDirty()) 299 { 300 getSite().getShell().getDisplay().asyncExec 301 (new Runnable () 302 { 303 public void run() 304 { 305 getSite().getPage().closeEditor(GenModelEditor.this, false); 306 GenModelEditor.this.dispose(); 307 } 308 }); 309 } 310 } 311 312 if (!visitor.getChangedResources().isEmpty()) 313 { 314 changedResources.addAll(visitor.getChangedResources()); 315 } 316 } 317 catch (CoreException exception) 318 { 319 GenModelEditPlugin.INSTANCE.log(exception); 320 } 321 } 322 } 323 }; 324 325 326 330 public void handleActivate() 331 { 332 if (!removedResources.isEmpty()) 333 { 334 if (handleDirtyConflict()) 335 { 336 getSite().getPage().closeEditor(GenModelEditor.this, false); 337 GenModelEditor.this.dispose(); 338 } 339 else 340 { 341 removedResources.clear(); 342 changedResources.clear(); 343 savedResources.clear(); 344 } 345 } 346 else if (!changedResources.isEmpty()) 347 { 348 changedResources.removeAll(savedResources); 349 handleChangedResources(); 350 changedResources.clear(); 351 savedResources.clear(); 352 } 353 } 354 355 356 360 protected void handleChangedResources() 361 { 362 if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) 363 { 364 editingDomain.getCommandStack().flush(); 365 Resource mainResource = (Resource)editingDomain.getResourceSet().getResources().get(0); 366 boolean reload = false; 367 for (Iterator i = changedResources.iterator(); i.hasNext(); ) 368 { 369 Resource resource = (Resource)i.next(); 370 if (resource == mainResource) 371 { 372 reload = true; 373 } 374 if (resource.isLoaded()) 375 { 376 resource.unload(); 377 try 378 { 379 resource.load(Collections.EMPTY_MAP); 380 } 381 catch (IOException exception) 382 { 383 GenModelEditPlugin.INSTANCE.log(exception); 384 } 385 } 386 } 387 388 if (reload) 389 { 390 GenModel genModel = (GenModel)mainResource.getContents().get(0); 391 initialize(genModel); 392 currentViewer.setInput(mainResource); 393 } 394 } 395 } 396 397 protected void initialize(GenModel genModel) 398 { 399 genModel.reconcile(); 400 genModel.setCanGenerate(true); 401 validate(); 402 403 Map options = JavaCore.getOptions(); 404 String tabSize = (String )options.get(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); 405 String braceStyle = (String )options.get(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION); 406 String tabCharacter = (String )options.get(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); 407 if (JavaCore.TAB.equals(tabCharacter)) 408 { 409 genModel.getJControlModel().setLeadingTabReplacement("\t"); 410 } 411 else 412 { 413 String spaces = ""; 414 for (int i = Integer.parseInt(tabSize); i > 0; --i) 415 { 416 spaces += " "; 417 } 418 genModel.getJControlModel().setLeadingTabReplacement(spaces); 419 } 420 genModel.getJControlModel().setConvertToStandardBraceStyle(DefaultCodeFormatterConstants.END_OF_LINE.equals(braceStyle)); 421 } 422 423 427 protected boolean handleDirtyConflict() 428 { 429 return 430 MessageDialog.openQuestion 431 (getSite().getShell(), 432 getString("_UI_FileConflict_label"), 433 getString("_WARN_FileConflict")); 434 } 435 436 442 public GenModelEditor() 443 { 444 super(); 445 446 adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); 447 448 BasicCommandStack commandStack = new BasicCommandStack(); 451 452 commandStack.addCommandStackListener 455 (new CommandStackListener() 456 { 457 public void commandStackChanged(final EventObject event) 458 { 459 getContainer().getDisplay().asyncExec 460 (new Runnable () 461 { 462 public void run() 463 { 464 firePropertyChange(IEditorPart.PROP_DIRTY); 465 466 Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand(); 469 if (mostRecentCommand != null) 470 { 471 setSelectionToViewer(mostRecentCommand.getAffectedObjects()); 472 } 473 474 if (propertySheetPage != null) 475 { 476 propertySheetPage.refresh(); 477 } 478 } 479 }); 480 } 481 }); 482 483 editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack); 486 } 487 488 494 protected void firePropertyChange(int action) 495 { 496 super.firePropertyChange(action); 497 } 498 499 505 public void setSelectionToViewer(Collection collection) 506 { 507 final Collection theSelection = collection; 508 if (theSelection != null && !theSelection.isEmpty()) 511 { 512 Runnable runnable = 518 new Runnable () 519 { 520 public void run() 521 { 522 if (currentViewer != null) 525 { 526 currentViewer.setSelection(new StructuredSelection(theSelection.toArray()), true); 527 } 528 } 529 }; 530 runnable.run(); 531 } 532 } 533 534 542 public EditingDomain getEditingDomain() 543 { 544 return editingDomain; 545 } 546 547 552 public class ReverseAdapterFactoryContentProvider extends AdapterFactoryContentProvider 553 { 554 public ReverseAdapterFactoryContentProvider(AdapterFactory adapterFactory) 555 { 556 super(adapterFactory); 557 } 558 559 public Object [] getElements(Object object) 560 { 561 Object parent = super.getParent(object); 562 return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray(); 563 } 564 565 public Object [] getChildren(Object object) 566 { 567 Object parent = super.getParent(object); 568 return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray(); 569 } 570 571 public boolean hasChildren(Object object) 572 { 573 Object parent = super.getParent(object); 574 return parent != null; 575 } 576 577 public Object getParent(Object object) 578 { 579 return null; 580 } 581 } 582 583 584 591 public void setCurrentViewer(Viewer viewer) 592 { 593 if (currentViewer != viewer) 596 { 597 if (selectionChangedListener == null) 598 { 599 selectionChangedListener = 602 new ISelectionChangedListener() 603 { 604 public void selectionChanged(SelectionChangedEvent selectionChangedEvent) 607 { 608 setSelection(selectionChangedEvent.getSelection()); 609 } 610 }; 611 } 612 613 if (currentViewer != null) 616 { 617 currentViewer.removeSelectionChangedListener(selectionChangedListener); 618 } 619 620 if (viewer != null) 623 { 624 viewer.addSelectionChangedListener(selectionChangedListener); 625 } 626 627 currentViewer = viewer; 630 631 setSelection(currentViewer == null ? StructuredSelection.EMPTY : currentViewer.getSelection()); 634 } 635 } 636 637 643 public Viewer getViewer() 644 { 645 return currentViewer; 646 } 647 648 654 protected void createContextMenuFor(StructuredViewer viewer) 655 { 656 MenuManager contextMenu = new MenuManager("#PopUp"); 657 contextMenu.add(new Separator("additions")); 658 contextMenu.setRemoveAllWhenShown(true); 659 contextMenu.addMenuListener(this); 660 Menu menu= contextMenu.createContextMenu(viewer.getControl()); 661 viewer.getControl().setMenu(menu); 662 getSite().registerContextMenu(contextMenu, viewer); 663 664 int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; 665 Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() }; 666 viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer)); 667 viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer)); 668 } 669 670 676 public void createPages() 677 { 678 IFileEditorInput modelFile = (IFileEditorInput)getEditorInput(); 681 682 editingDomain.getResourceSet().getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap()); 683 684 try 685 { 686 Resource resource = 689 editingDomain.loadResource 690 (URI.createPlatformResourceURI(modelFile.getFile().getFullPath().toString()).toString()); 691 692 GenModel genModel = (GenModel)resource.getContents().get(0); 695 initialize(genModel); 696 } 697 catch (Exception exception) 698 { 699 GenModelEditPlugin.INSTANCE.log(exception); 700 } 701 702 { 705 Tree tree = new Tree(getContainer(), SWT.MULTI); 706 TreeViewer treeViewer = new TreeViewer(tree); 707 setCurrentViewer(treeViewer); 708 709 treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); 710 treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); 711 treeViewer.setInput(editingDomain.getResourceSet().getResources().get(0)); 712 713 new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory); 714 715 createContextMenuFor(treeViewer); 716 addPage(tree); 717 } 718 setActivePage(0); 719 720 getContainer().addControlListener 721 (new ControlAdapter() 722 { 723 boolean guard = false; 724 public void controlResized(ControlEvent event) 725 { 726 if (!guard) 727 { 728 guard = true; 729 hideTabs(); 730 guard = false; 731 } 732 } 733 }); 734 } 735 736 protected void hideTabs() 737 { 738 if (getPageCount() <= 1) 739 { 740 setPageText(0, ""); 741 if (getContainer() instanceof CTabFolder) 742 { 743 ((CTabFolder)getContainer()).setTabHeight(1); 744 Point point = getContainer().getSize(); 745 getContainer().setSize(point.x, point.y + 6); 746 } 747 } 748 } 749 750 756 protected void pageChange(int pageIndex) 757 { 758 super.pageChange(pageIndex); 759 760 Control control = getControl(pageIndex); 763 if (control != null) 764 { 765 control.setVisible(true); 766 control.setFocus(); 767 } 768 } 769 770 776 public Object getAdapter(Class key) 777 { 778 if (key.equals(IPropertySheetPage.class)) return getPropertySheetPage(); 779 return super.getAdapter(key); 780 } 781 782 783 789 public IPropertySheetPage getPropertySheetPage() 790 { 791 if (propertySheetPage == null) 792 { 793 propertySheetPage = 794 new PropertySheetPage() 795 { 796 public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager) 797 { 798 super.makeContributions(menuManager, toolBarManager, statusLineManager); 799 } 800 801 public void setActionBars(IActionBars actionBars) 802 { 803 super.setActionBars(actionBars); 804 getActionBarContributor().shareGlobalActions(this, actionBars); 805 } 806 }; 807 propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(adapterFactory)); 808 } 809 810 return propertySheetPage; 811 } 812 813 819 public boolean isDirty() 820 { 821 return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded(); 822 } 823 824 830 public void doSave(IProgressMonitor progressMonitor) 831 { 832 WorkspaceModifyOperation operation = 835 new WorkspaceModifyOperation() 836 { 837 protected void execute(IProgressMonitor monitor) throws CoreException 840 { 841 try 842 { 843 Resource savedResource = (Resource)editingDomain.getResourceSet().getResources().get(0); 846 savedResources.add(savedResource); 847 savedResource.save(Collections.EMPTY_MAP); 848 } 849 catch (Exception exception) 850 { 851 GenModelEditPlugin.INSTANCE.log(exception); 852 } 853 } 854 }; 855 856 try 857 { 858 new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); 862 863 ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone(); 866 firePropertyChange(IEditorPart.PROP_DIRTY); 867 } 868 catch (Exception exception) 869 { 870 GenModelEditPlugin.INSTANCE.log(exception); 873 } 874 } 875 876 882 public boolean isSaveAsAllowed() 883 { 884 return true; 885 } 886 887 893 public void doSaveAs() 894 { 895 SaveAsDialog saveAsDialog= new SaveAsDialog(getSite().getShell()); 896 saveAsDialog.open(); 897 IPath path= saveAsDialog.getResult(); 898 if (path != null) 899 { 900 IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); 901 if (file != null) 902 { 903 ((Resource)editingDomain.getResourceSet().getResources().get(0)).setURI 904 (URI.createPlatformResourceURI(file.getFullPath().toString())); 905 IFileEditorInput modelFile = new FileEditorInput(file); 906 setInput(modelFile); 907 setPartName(file.getName()); 908 doSave(getActionBars().getStatusLineManager().getProgressMonitor()); 909 } 910 } 911 } 912 913 918 public void gotoMarker(IMarker marker) 919 { 920 } 921 922 928 public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException, PartInitException, PartInitException, PartInitException, PartInitException, PartInitException, PartInitException, PartInitException, PartInitException, PartInitException 929 { 930 if (editorInput instanceof IFileEditorInput) 931 { 932 setSite(site); 933 setInput(editorInput); 934 setPartName(((IFileEditorInput)editorInput).getFile().getName()); 935 site.setSelectionProvider(this); 936 site.getPage().addPartListener(partListener); 937 ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE); 938 } 939 else 940 { 941 throw new PartInitException("Invalid Input: Must be IFileEditorInput."); 942 } 943 } 944 945 950 public void setFocus() 951 { 952 getControl(getActivePage()).setFocus(); 953 } 954 955 961 public void addSelectionChangedListener(ISelectionChangedListener listener) 962 { 963 selectionChangedListeners.add(listener); 964 } 965 966 972 public void removeSelectionChangedListener(ISelectionChangedListener listener) 973 { 974 selectionChangedListeners.remove(listener); 975 } 976 977 983 public ISelection getSelection() 984 { 985 return editorSelection; 986 } 987 988 995 public void setSelection(ISelection selection) 996 { 997 editorSelection = selection; 998 for (Iterator listeners = selectionChangedListeners.iterator(); listeners.hasNext(); ) 999 { 1000 ISelectionChangedListener listener = (ISelectionChangedListener)listeners.next(); 1001 listener.selectionChanged(new SelectionChangedEvent(this, selection)); 1002 } 1003 setStatusLineManager(selection); 1004 } 1005 1006 1011 public void setStatusLineManager(ISelection selection) 1012 { 1013 IStatusLineManager statusLineManager = getActionBars().getStatusLineManager(); 1014 if(statusLineManager != null) 1015 { 1016 if (selection instanceof IStructuredSelection) 1017 { 1018 Collection collection = ((IStructuredSelection)selection).toList(); 1019 switch (collection.size()) 1020 { 1021 case 0: 1022 { 1023 statusLineManager.setMessage(getString("_UI_NoObjectSelected")); 1024 break; 1025 } 1026 case 1: 1027 { 1028 String text = new AdapterFactoryItemDelegator(adapterFactory).getText(collection.iterator().next()); 1029 statusLineManager.setMessage(getString("_UI_SingleObjectSelected", text)); 1030 break; 1031 } 1032 default: 1033 { 1034 statusLineManager.setMessage(getString("_UI_MultiObjectSelected", Integer.toString(collection.size()))); 1035 break; 1036 } 1037 } 1038 } 1039 else 1040 { 1041 statusLineManager.setMessage(""); 1042 } 1043 } 1044 } 1045 1046 1052 private static String getString(String key) 1053 { 1054 return GenModelEditPlugin.INSTANCE.getString(key); 1055 } 1056 1057 1063 private static String getString(String key, Object s1) 1064 { 1065 return GenModelEditPlugin.INSTANCE.getString(key, new Object [] { s1 }); 1066 } 1067 1068 1074 public void menuAboutToShow(IMenuManager menuManager) 1075 { 1076 ((IMenuListener)getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager); 1077 } 1078 1079 1084 public EditingDomainActionBarContributor getActionBarContributor() 1085 { 1086 return (EditingDomainActionBarContributor)getEditorSite().getActionBarContributor(); 1087 } 1088 1089 1094 public IActionBars getActionBars() 1095 { 1096 return getActionBarContributor().getActionBars(); 1097 } 1098 1099 1104 public AdapterFactory getAdapterFactory() 1105 { 1106 return adapterFactory; 1107 } 1108 1109 1114 public void dispose() 1115 { 1116 ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener); 1117 1118 getSite().getPage().removePartListener(partListener); 1119 1120 adapterFactory.dispose(); 1121 1122 getActionBarContributor().setActiveEditor(null); 1123 1124 if (propertySheetPage != null) 1125 { 1126 propertySheetPage.dispose(); 1127 } 1128 1129 super.dispose(); 1130 } 1131 1132 public void validate() 1133 { 1134 Resource mainResource = (Resource)editingDomain.getResourceSet().getResources().get(0); 1135 GenModel genModel = (GenModel)mainResource.getContents().get(0); 1136 IStatus status = genModel.validate(); 1137 if (!status.isOK()) 1138 { 1139 ErrorDialog.openError 1140 (getSite().getShell(), 1141 GenModelEditPlugin.INSTANCE.getString("_UI_ModelProblems_title"), 1142 "", 1143 status); 1144 } 1145 } 1146} 1147 | Popular Tags |