/** * This just records the information. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void init(IWorkbench workbench, IStructuredSelection selection) { this.workbench = workbench; this.selection = selection; setWindowTitle(WorkflowEditorPlugin.INSTANCE.getString("_UI_Wizard_label")); setDefaultPageImageDescriptor( ExtendedImageRegistry.INSTANCE.getImageDescriptor( WorkflowEditorPlugin.INSTANCE.getImage("full/wizban/NewWorkflow"))); }
/** * This populates the pop-up menu before it appears. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void menuAboutToShow(IMenuManager menuManager) { super.menuAboutToShow(menuManager); MenuManager submenuManager = null; submenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item")); populateManager(submenuManager, createChildActions, null); menuManager.insertBefore("edit", submenuManager); submenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item")); populateManager(submenuManager, createSiblingActions, null); menuManager.insertBefore("edit", submenuManager); }
/** * Returns the label for the specified type name. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected String getLabel(String typeName) { try { return WorkflowEditPlugin.INSTANCE.getString("_UI_" + typeName + "_type"); } catch (MissingResourceException mre) { WorkflowEditorPlugin.INSTANCE.log(mre); } return typeName; }
@Override public void run() { try { getPage().showView("org.eclipse.ui.views.PropertySheet"); } catch (PartInitException exception) { WorkflowEditorPlugin.INSTANCE.log(exception); } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<String> getEncodings() { if (encodings == null) { encodings = new ArrayList<String>(); for (StringTokenizer stringTokenizer = new StringTokenizer( WorkflowEditorPlugin.INSTANCE.getString("_UI_XMLEncodingChoices")); stringTokenizer.hasMoreTokens(); ) { encodings.add(stringTokenizer.nextToken()); } } return encodings; }
/** * This adds to the menu bar a menu and some separators for editor additions, as well as the * sub-menus for object creation items. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void contributeToMenu(IMenuManager menuManager) { super.contributeToMenu(menuManager); IMenuManager submenuManager = new MenuManager( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowEditor_menu"), "com.bluexml.side.workflowMenuID"); menuManager.insertAfter("additions", submenuManager); submenuManager.add(new Separator("settings")); submenuManager.add(new Separator("actions")); submenuManager.add(new Separator("additions")); submenuManager.add(new Separator("additions-end")); // Prepare for CreateChild item addition or removal. // createChildMenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item")); submenuManager.insertBefore("additions", createChildMenuManager); // Prepare for CreateSibling item addition or removal. // createSiblingMenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item")); submenuManager.insertBefore("additions", createSiblingMenuManager); // Force an update because Eclipse hides empty menus now. // submenuManager.addMenuListener( new IMenuListener() { public void menuAboutToShow(IMenuManager menuManager) { menuManager.updateAll(true); } }); addGlobalActions(submenuManager); }
/** * The framework calls this to create the contents of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void addPages() { // Create a page, set the title, and the initial model file name. // newFileCreationPage = new WorkflowModelWizardNewFileCreationPage("Whatever", selection); newFileCreationPage.setTitle( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowModelWizard_label")); newFileCreationPage.setDescription( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowModelWizard_description")); newFileCreationPage.setFileName( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowEditorFilenameDefaultBase") + "." + FILE_EXTENSIONS.get(0)); addPage(newFileCreationPage); // Try and get the resource selection to determine a current directory for the file dialog. // if (selection != null && !selection.isEmpty()) { // Get the resource... // Object selectedElement = selection.iterator().next(); if (selectedElement instanceof IResource) { // Get the resource parent, if its a file. // IResource selectedResource = (IResource) selectedElement; if (selectedResource.getType() == IResource.FILE) { selectedResource = selectedResource.getParent(); } // This gives us a directory... // if (selectedResource instanceof IFolder || selectedResource instanceof IProject) { // Set this for the container. // newFileCreationPage.setContainerFullPath(selectedResource.getFullPath()); // Make up a unique new name here. // String defaultModelBaseFilename = WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowEditorFilenameDefaultBase"); String defaultModelFilenameExtension = FILE_EXTENSIONS.get(0); String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; for (int i = 1; ((IContainer) selectedResource).findMember(modelFilename) != null; ++i) { modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; } newFileCreationPage.setFileName(modelFilename); } } } initialObjectCreationPage = new WorkflowModelWizardInitialObjectCreationPage("Whatever2"); initialObjectCreationPage.setTitle( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowModelWizard_label")); initialObjectCreationPage.setDescription( WorkflowEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description")); addPage(initialObjectCreationPage); }
/** * The framework calls this to see if the file is correct. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override protected boolean validatePage() { if (super.validatePage()) { String extension = new Path(getFileName()).getFileExtension(); if (extension == null || !FILE_EXTENSIONS.contains(extension)) { String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; setErrorMessage( WorkflowEditorPlugin.INSTANCE.getString( key, new Object[] {FORMATTED_FILE_EXTENSIONS})); return false; } return true; } return false; }
/** * This is a simple wizard for creating a new model file. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public class WorkflowModelWizard extends Wizard implements INewWizard { /** * The supported extensions for created files. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public static final List<String> FILE_EXTENSIONS = Collections.unmodifiableList( Arrays.asList( WorkflowEditorPlugin.INSTANCE .getString("_UI_WorkflowEditorFilenameExtensions") .split("\\s*,\\s*"))); /** * A formatted list of supported file extensions, suitable for display. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public static final String FORMATTED_FILE_EXTENSIONS = WorkflowEditorPlugin.INSTANCE .getString("_UI_WorkflowEditorFilenameExtensions") .replaceAll("\\s*,\\s*", ", "); /** * This caches an instance of the model package. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected WorkflowPackage workflowPackage = WorkflowPackage.eINSTANCE; /** * This caches an instance of the model factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected WorkflowFactory workflowFactory = workflowPackage.getWorkflowFactory(); /** * This is the file creation page. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected WorkflowModelWizardNewFileCreationPage newFileCreationPage; /** * This is the initial object creation page. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected WorkflowModelWizardInitialObjectCreationPage initialObjectCreationPage; /** * Remember the selection during initialization for populating the default container. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IStructuredSelection selection; /** * Remember the workbench during initialization. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IWorkbench workbench; /** * Caches the names of the types that can be created as the root object. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected List<String> initialObjectNames; /** * This just records the information. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void init(IWorkbench workbench, IStructuredSelection selection) { this.workbench = workbench; this.selection = selection; setWindowTitle(WorkflowEditorPlugin.INSTANCE.getString("_UI_Wizard_label")); setDefaultPageImageDescriptor( ExtendedImageRegistry.INSTANCE.getImageDescriptor( WorkflowEditorPlugin.INSTANCE.getImage("full/wizban/NewWorkflow"))); } /** * Returns the names of the types that can be created as the root object. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<String> getInitialObjectNames() { if (initialObjectNames == null) { initialObjectNames = new ArrayList<String>(); for (EClassifier eClassifier : workflowPackage.getEClassifiers()) { if (eClassifier instanceof EClass) { EClass eClass = (EClass) eClassifier; if (!eClass.isAbstract()) { initialObjectNames.add(eClass.getName()); } } } Collections.sort(initialObjectNames, CommonPlugin.INSTANCE.getComparator()); } return initialObjectNames; } /** * Create a new model. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected EObject createInitialModel() { EClass eClass = (EClass) workflowPackage.getEClassifier(initialObjectCreationPage.getInitialObjectName()); EObject rootObject = workflowFactory.create(eClass); return rootObject; } /** * Do the work after everything is specified. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public boolean performFinish() { try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { WorkflowEditorPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell() .getDisplay() .asyncExec( new Runnable() { public void run() { ((ISetSelectionTarget) activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor( new FileEditorInput(modelFile), workbench .getEditorRegistry() .getDefaultEditor(modelFile.getFullPath().toString()) .getId()); } catch (PartInitException exception) { MessageDialog.openError( workbenchWindow.getShell(), WorkflowEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); return false; } return true; } catch (Exception exception) { WorkflowEditorPlugin.INSTANCE.log(exception); return false; } } /** * This is the one page of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public class WorkflowModelWizardNewFileCreationPage extends WizardNewFileCreationPage { /** * Pass in the selection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public WorkflowModelWizardNewFileCreationPage(String pageId, IStructuredSelection selection) { super(pageId, selection); } /** * The framework calls this to see if the file is correct. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override protected boolean validatePage() { if (super.validatePage()) { String extension = new Path(getFileName()).getFileExtension(); if (extension == null || !FILE_EXTENSIONS.contains(extension)) { String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; setErrorMessage( WorkflowEditorPlugin.INSTANCE.getString( key, new Object[] {FORMATTED_FILE_EXTENSIONS})); return false; } return true; } return false; } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public IFile getModelFile() { return ResourcesPlugin.getWorkspace() .getRoot() .getFile(getContainerFullPath().append(getFileName())); } } /** * This is the page where the type of object to create is selected. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public class WorkflowModelWizardInitialObjectCreationPage extends WizardPage { /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Combo initialObjectField; /** * @generated * <!-- begin-user-doc --> * <!-- end-user-doc --> */ protected List<String> encodings; /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Combo encodingField; /** * Pass in the selection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public WorkflowModelWizardInitialObjectCreationPage(String pageId) { super(pageId); } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); { GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.verticalSpacing = 12; composite.setLayout(layout); GridData data = new GridData(); data.verticalAlignment = GridData.FILL; data.grabExcessVerticalSpace = true; data.horizontalAlignment = GridData.FILL; composite.setLayoutData(data); } Label containerLabel = new Label(composite, SWT.LEFT); { containerLabel.setText(WorkflowEditorPlugin.INSTANCE.getString("_UI_ModelObject")); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; containerLabel.setLayoutData(data); } initialObjectField = new Combo(composite, SWT.BORDER); { GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; initialObjectField.setLayoutData(data); } for (String objectName : getInitialObjectNames()) { initialObjectField.add(getLabel(objectName)); } if (initialObjectField.getItemCount() == 1) { initialObjectField.select(0); } initialObjectField.addModifyListener(validator); Label encodingLabel = new Label(composite, SWT.LEFT); { encodingLabel.setText(WorkflowEditorPlugin.INSTANCE.getString("_UI_XMLEncoding")); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; encodingLabel.setLayoutData(data); } encodingField = new Combo(composite, SWT.BORDER); { GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; encodingField.setLayoutData(data); } for (String encoding : getEncodings()) { encodingField.add(encoding); } encodingField.select(0); encodingField.addModifyListener(validator); setPageComplete(validatePage()); setControl(composite); } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected ModifyListener validator = new ModifyListener() { public void modifyText(ModifyEvent e) { setPageComplete(validatePage()); } }; /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected boolean validatePage() { return getInitialObjectName() != null && getEncodings().contains(encodingField.getText()); } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void setVisible(boolean visible) { super.setVisible(visible); if (visible) { if (initialObjectField.getItemCount() == 1) { initialObjectField.clearSelection(); encodingField.setFocus(); } else { encodingField.clearSelection(); initialObjectField.setFocus(); } } } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public String getInitialObjectName() { String label = initialObjectField.getText(); for (String name : getInitialObjectNames()) { if (getLabel(name).equals(label)) { return name; } } return null; } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public String getEncoding() { return encodingField.getText(); } /** * Returns the label for the specified type name. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected String getLabel(String typeName) { try { return WorkflowEditPlugin.INSTANCE.getString("_UI_" + typeName + "_type"); } catch (MissingResourceException mre) { WorkflowEditorPlugin.INSTANCE.log(mre); } return typeName; } /** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<String> getEncodings() { if (encodings == null) { encodings = new ArrayList<String>(); for (StringTokenizer stringTokenizer = new StringTokenizer( WorkflowEditorPlugin.INSTANCE.getString("_UI_XMLEncodingChoices")); stringTokenizer.hasMoreTokens(); ) { encodings.add(stringTokenizer.nextToken()); } } return encodings; } } /** * The framework calls this to create the contents of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void addPages() { // Create a page, set the title, and the initial model file name. // newFileCreationPage = new WorkflowModelWizardNewFileCreationPage("Whatever", selection); newFileCreationPage.setTitle( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowModelWizard_label")); newFileCreationPage.setDescription( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowModelWizard_description")); newFileCreationPage.setFileName( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowEditorFilenameDefaultBase") + "." + FILE_EXTENSIONS.get(0)); addPage(newFileCreationPage); // Try and get the resource selection to determine a current directory for the file dialog. // if (selection != null && !selection.isEmpty()) { // Get the resource... // Object selectedElement = selection.iterator().next(); if (selectedElement instanceof IResource) { // Get the resource parent, if its a file. // IResource selectedResource = (IResource) selectedElement; if (selectedResource.getType() == IResource.FILE) { selectedResource = selectedResource.getParent(); } // This gives us a directory... // if (selectedResource instanceof IFolder || selectedResource instanceof IProject) { // Set this for the container. // newFileCreationPage.setContainerFullPath(selectedResource.getFullPath()); // Make up a unique new name here. // String defaultModelBaseFilename = WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowEditorFilenameDefaultBase"); String defaultModelFilenameExtension = FILE_EXTENSIONS.get(0); String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; for (int i = 1; ((IContainer) selectedResource).findMember(modelFilename) != null; ++i) { modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; } newFileCreationPage.setFileName(modelFilename); } } } initialObjectCreationPage = new WorkflowModelWizardInitialObjectCreationPage("Whatever2"); initialObjectCreationPage.setTitle( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowModelWizard_label")); initialObjectCreationPage.setDescription( WorkflowEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description")); addPage(initialObjectCreationPage); } /** * Get the file from the page. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public IFile getModelFile() { return newFileCreationPage.getModelFile(); } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); { GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.verticalSpacing = 12; composite.setLayout(layout); GridData data = new GridData(); data.verticalAlignment = GridData.FILL; data.grabExcessVerticalSpace = true; data.horizontalAlignment = GridData.FILL; composite.setLayoutData(data); } Label containerLabel = new Label(composite, SWT.LEFT); { containerLabel.setText(WorkflowEditorPlugin.INSTANCE.getString("_UI_ModelObject")); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; containerLabel.setLayoutData(data); } initialObjectField = new Combo(composite, SWT.BORDER); { GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; initialObjectField.setLayoutData(data); } for (String objectName : getInitialObjectNames()) { initialObjectField.add(getLabel(objectName)); } if (initialObjectField.getItemCount() == 1) { initialObjectField.select(0); } initialObjectField.addModifyListener(validator); Label encodingLabel = new Label(composite, SWT.LEFT); { encodingLabel.setText(WorkflowEditorPlugin.INSTANCE.getString("_UI_XMLEncoding")); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; encodingLabel.setLayoutData(data); } encodingField = new Combo(composite, SWT.BORDER); { GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; encodingField.setLayoutData(data); } for (String encoding : getEncodings()) { encodingField.add(encoding); } encodingField.select(0); encodingField.addModifyListener(validator); setPageComplete(validatePage()); setControl(composite); }
/** * Do the work after everything is specified. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public boolean performFinish() { try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { WorkflowEditorPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell() .getDisplay() .asyncExec( new Runnable() { public void run() { ((ISetSelectionTarget) activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor( new FileEditorInput(modelFile), workbench .getEditorRegistry() .getDefaultEditor(modelFile.getFullPath().toString()) .getId()); } catch (PartInitException exception) { MessageDialog.openError( workbenchWindow.getShell(), WorkflowEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); return false; } return true; } catch (Exception exception) { WorkflowEditorPlugin.INSTANCE.log(exception); return false; } }
/** * This is the action bar contributor for the Workflow model editor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public class WorkflowActionBarContributor extends EditingDomainActionBarContributor implements ISelectionChangedListener { /** * This keeps track of the active editor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IEditorPart activeEditorPart; /** * This keeps track of the current selection provider. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected ISelectionProvider selectionProvider; /** * This action opens the Properties view. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IAction showPropertiesViewAction = new Action(WorkflowEditorPlugin.INSTANCE.getString("_UI_ShowPropertiesView_menu_item")) { @Override public void run() { try { getPage().showView("org.eclipse.ui.views.PropertySheet"); } catch (PartInitException exception) { WorkflowEditorPlugin.INSTANCE.log(exception); } } }; /** * This action refreshes the viewer of the current editor if the editor implements {@link * org.eclipse.emf.common.ui.viewer.IViewerProvider}. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IAction refreshViewerAction = new Action(WorkflowEditorPlugin.INSTANCE.getString("_UI_RefreshViewer_menu_item")) { @Override public boolean isEnabled() { return activeEditorPart instanceof IViewerProvider; } @Override public void run() { if (activeEditorPart instanceof IViewerProvider) { Viewer viewer = ((IViewerProvider) activeEditorPart).getViewer(); if (viewer != null) { viewer.refresh(); } } } }; /** * This will contain one {@link org.eclipse.emf.edit.ui.action.CreateChildAction} corresponding to * each descriptor generated for the current selection by the item provider. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<IAction> createChildActions; /** * This is the menu manager into which menu contribution items should be added for CreateChild * actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IMenuManager createChildMenuManager; /** * This will contain one {@link org.eclipse.emf.edit.ui.action.CreateSiblingAction} corresponding * to each descriptor generated for the current selection by the item provider. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<IAction> createSiblingActions; /** * This is the menu manager into which menu contribution items should be added for CreateSibling * actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected IMenuManager createSiblingMenuManager; /** * This creates an instance of the contributor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public WorkflowActionBarContributor() { super(ADDITIONS_LAST_STYLE); loadResourceAction = new LoadResourceAction(); validateAction = new ValidateAction(); controlAction = new ControlAction(); } /** * This adds Separators for editor additions to the tool bar. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void contributeToToolBar(IToolBarManager toolBarManager) { toolBarManager.add(new Separator("workflow-settings")); toolBarManager.add(new Separator("workflow-additions")); } /** * This adds to the menu bar a menu and some separators for editor additions, as well as the * sub-menus for object creation items. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void contributeToMenu(IMenuManager menuManager) { super.contributeToMenu(menuManager); IMenuManager submenuManager = new MenuManager( WorkflowEditorPlugin.INSTANCE.getString("_UI_WorkflowEditor_menu"), "com.bluexml.side.workflowMenuID"); menuManager.insertAfter("additions", submenuManager); submenuManager.add(new Separator("settings")); submenuManager.add(new Separator("actions")); submenuManager.add(new Separator("additions")); submenuManager.add(new Separator("additions-end")); // Prepare for CreateChild item addition or removal. // createChildMenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item")); submenuManager.insertBefore("additions", createChildMenuManager); // Prepare for CreateSibling item addition or removal. // createSiblingMenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item")); submenuManager.insertBefore("additions", createSiblingMenuManager); // Force an update because Eclipse hides empty menus now. // submenuManager.addMenuListener( new IMenuListener() { public void menuAboutToShow(IMenuManager menuManager) { menuManager.updateAll(true); } }); addGlobalActions(submenuManager); } /** * When the active editor changes, this remembers the change and registers with it as a selection * provider. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void setActiveEditor(IEditorPart part) { super.setActiveEditor(part); activeEditorPart = part; // Switch to the new selection provider. // if (selectionProvider != null) { selectionProvider.removeSelectionChangedListener(this); } if (part == null) { selectionProvider = null; } else { selectionProvider = part.getSite().getSelectionProvider(); selectionProvider.addSelectionChangedListener(this); // Fake a selection changed event to update the menus. // if (selectionProvider.getSelection() != null) { selectionChanged( new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection())); } } } /** * This implements {@link org.eclipse.jface.viewers.ISelectionChangedListener}, handling {@link * org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings * that can be added to the selected object and updating the menus accordingly. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void selectionChanged(SelectionChangedEvent event) { // Remove any menu items for old selection. // if (createChildMenuManager != null) { depopulateManager(createChildMenuManager, createChildActions); } if (createSiblingMenuManager != null) { depopulateManager(createSiblingMenuManager, createSiblingActions); } // Query the new selection for appropriate new child/sibling descriptors // Collection<?> newChildDescriptors = null; Collection<?> newSiblingDescriptors = null; ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) { Object object = ((IStructuredSelection) selection).getFirstElement(); EditingDomain domain = ((IEditingDomainProvider) activeEditorPart).getEditingDomain(); newChildDescriptors = domain.getNewChildDescriptors(object, null); newSiblingDescriptors = domain.getNewChildDescriptors(null, object); } // Generate actions for selection; populate and redraw the menus. // createChildActions = generateCreateChildActions(newChildDescriptors, selection); createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection); if (createChildMenuManager != null) { populateManager(createChildMenuManager, createChildActions, null); createChildMenuManager.update(true); } if (createSiblingMenuManager != null) { populateManager(createSiblingMenuManager, createSiblingActions, null); createSiblingMenuManager.update(true); } } /** * This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in * <code>descriptors</code>, and returns the collection of these actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<IAction> generateCreateChildActions( Collection<?> descriptors, ISelection selection) { Collection<IAction> actions = new ArrayList<IAction>(); if (descriptors != null) { for (Object descriptor : descriptors) { actions.add(new CreateChildAction(activeEditorPart, selection, descriptor)); } } return actions; } /** * This generates a {@link org.eclipse.emf.edit.ui.action.CreateSiblingAction} for each object in * <code>descriptors</code>, and returns the collection of these actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected Collection<IAction> generateCreateSiblingActions( Collection<?> descriptors, ISelection selection) { Collection<IAction> actions = new ArrayList<IAction>(); if (descriptors != null) { for (Object descriptor : descriptors) { actions.add(new CreateSiblingAction(activeEditorPart, selection, descriptor)); } } return actions; } /** * This populates the specified <code>manager</code> with {@link * org.eclipse.jface.action.ActionContributionItem}s based on the {@link * org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection, by * inserting them before the specified contribution item <code>contributionID</code>. If <code> * contributionID</code> is <code>null</code>, they are simply added. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected void populateManager( IContributionManager manager, Collection<? extends IAction> actions, String contributionID) { if (actions != null) { for (IAction action : actions) { if (contributionID != null) { manager.insertBefore(contributionID, action); } else { manager.add(action); } } } } /** * This removes from the specified <code>manager</code> all {@link * org.eclipse.jface.action.ActionContributionItem}s based on the {@link * org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected void depopulateManager( IContributionManager manager, Collection<? extends IAction> actions) { if (actions != null) { IContributionItem[] items = manager.getItems(); for (int i = 0; i < items.length; i++) { // Look into SubContributionItems // IContributionItem contributionItem = items[i]; while (contributionItem instanceof SubContributionItem) { contributionItem = ((SubContributionItem) contributionItem).getInnerItem(); } // Delete the ActionContributionItems with matching action. // if (contributionItem instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) contributionItem).getAction(); if (actions.contains(action)) { manager.remove(contributionItem); } } } } } /** * This populates the pop-up menu before it appears. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void menuAboutToShow(IMenuManager menuManager) { super.menuAboutToShow(menuManager); MenuManager submenuManager = null; submenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item")); populateManager(submenuManager, createChildActions, null); menuManager.insertBefore("edit", submenuManager); submenuManager = new MenuManager(WorkflowEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item")); populateManager(submenuManager, createSiblingActions, null); menuManager.insertBefore("edit", submenuManager); } /** * This inserts global actions before the "additions-end" separator. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override protected void addGlobalActions(IMenuManager menuManager) { menuManager.insertAfter("additions-end", new Separator("ui-actions")); menuManager.insertAfter("ui-actions", showPropertiesViewAction); refreshViewerAction.setEnabled(refreshViewerAction.isEnabled()); menuManager.insertAfter("ui-actions", refreshViewerAction); super.addGlobalActions(menuManager); } /** * This ensures that a delete action will clean up all references to deleted objects. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override protected boolean removeAllReferencesOnDelete() { return true; } }