public void init(IWorkbench workbench, IStructuredSelection selection) { boolean false_file = true; if (selection.getFirstElement() instanceof IFile) { IFile file = (IFile) selection.getFirstElement(); reportFileName = file.getName(); reportFile = file; if (file.getFileExtension().equals("rptdesign")) false_file = false; } if (false_file) { MessageDialog.openError( getShell(), "Wizzard Error", //$NON-NLS-1$ "Das gewählte File ist kein MAXIMO-BIRT Report File (.rptdesign)!"); //$NON-NLS-1$ // abort wizard. There is no clean way to do it. /** * Remove the exception here 'cause It's safe since the wizard won't create any file without * an open project. */ throw new RuntimeException(); } // OK this.selection = selection; setWindowTitle("New MAXIMO Report"); }
@Override public void doRun( IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) { instrumentation.metric("command", command); if (!selection.isEmpty() && selection.getFirstElement() instanceof IResource) { Object object = selection.getFirstElement(); if (object instanceof IFile) { object = ((IFile) object).getParent(); } while (object != null && ((IContainer) object).findMember(DartCore.PUBSPEC_FILE_NAME) == null) { object = ((IContainer) object).getParent(); } if (object instanceof IContainer) { IContainer container = (IContainer) object; instrumentation.data("name", container.getName()); savePubspecFile(container); runPubJob(container); return; } else { instrumentation.metric("Problem", "Object was null").log(); } } instrumentation.metric("Problem", "pubspec.yaml file not selected, showing dialog"); MessageDialog.openError( getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound); instrumentation.log(); }
/** Runs the operation, basically invert the value of isDefault property on the sequence edge. */ @Override protected void doRun(IProgressMonitor progressMonitor) { IStructuredSelection selection = getStructuredSelection(); if (selection == null || (selection.isEmpty())) { return; } if (selection.getFirstElement() instanceof IGraphicalEditPart) { IGraphicalEditPart part = (IGraphicalEditPart) selection.getFirstElement(); final EObject object = ((IGraphicalEditPart) selection.getFirstElement()).getNotationView().getElement(); if (object instanceof Activity) { part.getDiagramEditDomain() .getDiagramCommandStack() .execute( new ICommandProxy( new MyCommand(object) { @Override protected CommandResult doExecuteWithResult( IProgressMonitor monitor, IAdaptable info) throws ExecutionException { if (object instanceof Activity) { ((Activity) object).setLooping(!(((Activity) object).isLooping())); } return CommandResult.newOKCommandResult(); } }), progressMonitor); } } }
private static void buildTextQueryPart( Query query, Map<IQueryField, ComboViewer> operators, Map<IQueryField, Text> values) { for (Entry<IQueryField, Text> entry : values.entrySet()) { IQueryField queryField = entry.getKey(); Text text = entry.getValue(); ComboViewer opCombo = operators.get(queryField); IStructuredSelection selection = (IStructuredSelection) opCombo.getSelection(); if (selection.getFirstElement() instanceof CompareOperator) { CompareOperator operator = (CompareOperator) selection.getFirstElement(); if (queryField instanceof CustomField) { CustomField customField = (CustomField) queryField; if (customField.getFieldFormat() == CustomField.Format.BOOL) { query.addFilter( customField, QueryField.BOOLEAN_TYPE, operator, IRedmineConstants.BOOLEAN_TRUE_SUBMIT_VALUE); } else { QueryField definition = customField.getQueryField(); query.addFilter(customField, definition, operator, text.getText().trim()); } } else { query.addFilter((QueryField) queryField, operator, text.getText().trim()); } } } }
@Override protected void okPressed() { BpmnModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram())).getBpmnModel(); result.setId(idText.getText()); if (sourceRefViewer.getInput() != null) { IStructuredSelection selection = (IStructuredSelection) sourceRefViewer.getSelection(); if (selection.getFirstElement() instanceof IData) { result.setSourceRef(((IData) selection.getFirstElement()).getId()); // model.registerSubscriber(result); } else { result.setSourceRef(null); } } if (targetRefViewer.getInput() != null) { IStructuredSelection selection = (IStructuredSelection) targetRefViewer.getSelection(); if (selection.getFirstElement() instanceof IData) { result.setTargetRef(((IData) selection.getFirstElement()).getId()); } } if (StringUtils.isNotEmpty(transformationText.getText())) { result.setTransformation(transformationText.getText()); } super.okPressed(); }
/** Called when master selection changes. */ public void selectionChanged(IFormPart part, ISelection selection) { IStructuredSelection ssel = (IStructuredSelection) selection; m_input = null; // clear old input if (ssel.size() == 1 && ssel.getFirstElement() instanceof ProvidedCapabilityBuilder) m_input = (ProvidedCapabilityBuilder) (ssel.getFirstElement()); refresh(); }
/** {@inheritDoc} */ public boolean selectionChanged(IStructuredSelection selection) { if (selection.size() == 1 && selection.getFirstElement() instanceof IScriptProject) { fSelectedProject = (IScriptProject) selection.getFirstElement(); return true; } return false; }
private boolean isOneFeatureSelected(IStructuredSelection selection) { return selection.size() == 1 && (selection.getFirstElement() instanceof FeatureEditPart || selection.getFirstElement() instanceof ConnectionEditPart || selection.getFirstElement() instanceof FmOutlineGroupStateStorage || selection.getFirstElement() instanceof IFeature); }
/** Handler for tree selection. */ void handleTreeSelection() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); ElementSymbol element = null; if (!selection.isEmpty()) { ICriteriaStrategy strategy = ElementViewerFactory.getCriteriaStrategy(viewer); strategy.setTreeViewer(viewer); // make sure this viewer is set before using strategy if (strategy.isValid(selection.getFirstElement())) { Object eObj = selection.getFirstElement(); if (eObj instanceof ElementSymbol) { element = ((ElementSymbol) eObj); } else { element = new ElementSymbol(strategy.getRuntimeFullName(eObj), true); // the viewer model contains EObjects. so the objects in the selection will // be EObjects. since the EObject is used later on in the QueryCriteriaStrategy.getNode() // method. save it here. element.setMetadataID(eObj); } } } model.selectElementSymbol(element); }
private boolean canEnable(IStructuredSelection selection) throws JavaModelException { if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { final IType type = (IType) selection.getFirstElement(); return type.getCompilationUnit() != null && !type.isInterface(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) return true; return false; }
/** * @param selection the <code>ISelection</code> to examine. * @return the first element, or null if empty. */ protected IPreferenceNode getSingleSelection(ISelection selection) { if (!selection.isEmpty()) { IStructuredSelection structured = (IStructuredSelection) selection; if (structured.getFirstElement() instanceof IPreferenceNode) { return (IPreferenceNode) structured.getFirstElement(); } } return null; }
@Override public void menuAboutToShow(IMenuManager manager) { if (treeViewer.getSelection().isEmpty()) { return; } final EObject root = ((RootObject) treeViewer.getInput()).getRoot(); if (treeViewer.getSelection() instanceof IStructuredSelection) { final IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); if (selection.size() == 1 && EObject.class.isInstance(selection.getFirstElement())) { final EObject eObject = (EObject) selection.getFirstElement(); final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(eObject); if (domain == null) { return; } final Collection<?> descriptors = childrenDescriptorCollector.getDescriptors(eObject); fillContextMenu(manager, descriptors, editingDomain, eObject); } if (!selection.toList().contains(root)) { manager.add(new Separator(GLOBAL_ADDITIONS)); addDeleteActionToContextMenu(editingDomain, manager, selection); } manager.add(new Separator()); if (selection.getFirstElement() != null && EObject.class.isInstance(selection.getFirstElement())) { final EObject selectedObject = (EObject) selection.getFirstElement(); for (final MasterDetailAction menuAction : menuActions) { if (menuAction.shouldShow(selectedObject)) { final Action newAction = new Action() { @Override public void run() { super.run(); menuAction.execute(selectedObject); } }; newAction.setImageDescriptor( ImageDescriptor.createFromURL( FrameworkUtil.getBundle(menuAction.getClass()) .getResource(menuAction.getImagePath()))); newAction.setText(menuAction.getLabel()); manager.add(newAction); } } } } }
/* * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#updateViewerInput() */ protected void updateViewerInput() { IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection(); SourceViewer viewer = getViewer(); if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) { TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement(); Template template = data.getTemplate(); viewer.getDocument().set(template.getPattern()); } else { viewer.getDocument().set(""); } }
public IBackend getBackend() { final IStructuredSelection sel = (IStructuredSelection) backends.getSelection(); if (sel.getFirstElement() != null) { final IBackend b = (IBackend) sel.getFirstElement(); return b; } final IBackend b = BackendCore.getBackendManager().getIdeBackend(); if (b != null) { backends.setSelection(new StructuredSelection(b)); return b; } return null; }
/** The user has selected a different configuration in table. Update button enablement. */ private void handleTableSelectionChanged() { IStructuredSelection selection = (IStructuredSelection) configsViewer.getSelection(); if (selection.isEmpty()) { removeButton.setEnabled(false); } else { if (selection.getFirstElement() instanceof IBeansConfig && ((IBeansConfig) selection.getFirstElement()).getType() == IBeansConfig.Type.MANUAL) { removeButton.setEnabled(true); } else { removeButton.setEnabled(false); } } }
public StructureElement getStructureElementFor(ISelection selection) { if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; return GetUpdatedStructureUIOperation.getUpdatedStructureElementAt( editor, textSelection.getOffset()); } else if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.getFirstElement() instanceof StructureElement) { return (StructureElement) structuredSelection.getFirstElement(); } } return null; }
/** * Sets the default values applicable from the given {@code selection} argument. * * @param selection the first element selected in the Project Explorer when calling the Wizard. */ public void setDefaultValues(final IStructuredSelection selection) { setSuperClass(JaxrsClassnames.APPLICATION, false); final IJavaElement selectedJavaElement = getInitialJavaElement(selection); if (selectedJavaElement instanceof IPackageFragment) { setDefaultValues((IPackageFragment) selectedJavaElement); } else if (selectedJavaElement instanceof ICompilationUnit) { setDefaultValues((ICompilationUnit) selectedJavaElement); } else if (selectedJavaElement instanceof IType) { setDefaultValues((IType) selectedJavaElement); } else if (selection.getFirstElement() instanceof UriPathTemplateCategory) { setDefaultValues((UriPathTemplateCategory) selection.getFirstElement()); } }
@Override public void setContext(ActionContext context) { if (context.getSelection() instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) context.getSelection(); if (ss.getFirstElement() instanceof IAdaptable) { IWaypoint wp = (IWaypoint) ((IAdaptable) ss.getFirstElement()).getAdapter(IWaypoint.class); if (wp != null) { deleteAction.setEnabled(TagSEAPlugin.getDefault().getUI().canUIDelete(wp)); } } } super.setContext(context); }
/** @param selection the testRT to remove */ protected void removeTestRT(IStructuredSelection selection) { if (selection.getFirstElement() instanceof EObject) { EObject selectedElement = (EObject) selection.getFirstElement(); testRTEditUtil.removeElement(selectedElement); propertiesEditionComponent.firePropertiesChanged( new PropertiesEditionEvent( TestFilterPropertiesEditionPartForm.this, NonregViewsRepository.TestFilter.testRT, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.REMOVE, null, testRTEditUtil.foundCorrespondingEObject(selectedElement))); } }
public void disconnectServer(boolean needAlert) { if (needAlert && IMessageBox.Confirm(shell, NBLabel.get(0x0094)) != SWT.OK) return; Server server = null; IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); if (selection.getFirstElement() instanceof Server) { server = (Server) selection.getFirstElement(); } else { IMessageBox.Error(shell, NBLabel.get(0x0091)); return; } closeConnection(server); }
public void launch(ISelection selection, String mode) { IStructuredSelection is = (IStructuredSelection) selection; if (is.getFirstElement() != null) { try { Object selected = is.getFirstElement(); launchSelectedObject(selected, mode); } catch (CoreException e) { ErrorDialog.openError( null, "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error configuring launch.", e)); } } }
protected void okPressed() { boolean hasErrors = popupValidationErrorDialogIfNecessary(); if (!hasErrors) { try { conceptUtil.setId(wId.getText()); } catch (ObjectAlreadyExistsException e) { if (logger.isErrorEnabled()) { logger.error("an exception occurred", e); } MessageDialog.openError( getShell(), Messages.getString("General.USER_TITLE_ERROR"), Messages.getString( "PhysicalTableDialog.USER_ERROR_PHYSICAL_TABLE_ID_EXISTS", wId.getText())); return; } // attempt to set the connection IStructuredSelection selection = (IStructuredSelection) comboViewer.getSelection(); DatabaseMeta con = (DatabaseMeta) selection.getFirstElement(); BusinessModel busModel = (BusinessModel) conceptUtil; if (!DUMMY_CON_NAME.equals(con.getName())) { busModel.setConnection((DatabaseMeta) con); } else { busModel.clearConnection(); } super.okPressed(); } }
@Override public void fillContextMenu(IMenuManager aMenu) { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); if (selection.size() != 1) { return; } Object object = selection.getFirstElement(); IFolder folder = Adapters.adapt(object, IFolder.class); if (folder == null) { return; } if (folder.getFile(IProjectDescription.DESCRIPTION_FILE_NAME).exists()) { for (IProject project : folder.getWorkspace().getRoot().getProjects()) { if (project.getLocation().equals(folder.getLocation())) { // project already in workspace SelectProjectForFolderAction action = new SelectProjectForFolderAction(project, this.viewer); aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, action); return; } } OpenFolderAsProjectAction action = new OpenFolderAsProjectAction(folder, this.viewer); aMenu.prependToGroup(ICommonMenuConstants.GROUP_PORT, action); } }
/** Constructor for JCPWizard. */ public DownloadSpectraWizard(IWorkbenchPart view) { super(); setNeedsProgressMonitor(true); this.view = view; ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); if (sel.isEmpty() == false) { if (sel instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) sel; try { IFile cdkres = (IFile) ssel.getFirstElement(); Activator.getDefault() .getJavaCDKManager() .loadMolecule( cdkres, new BioclipseUIJob<ICDKMolecule>() { @Override public void runInUI() { ac = getReturnValue().getAtomContainer(); } }); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } } }
@Override public void run(IAction action) { UserDBDAO userDB = (UserDBDAO) sel.getFirstElement(); if (DBDefine.getDBDefine(userDB) == DBDefine.MYSQL_DEFAULT || DBDefine.getDBDefine(userDB) == DBDefine.MARIADB_DEFAULT || DBDefine.getDBDefine(userDB) == DBDefine.ORACLE_DEFAULT || DBDefine.getDBDefine(userDB) == DBDefine.MSSQL_DEFAULT) { try { SessionListEditorInput sleInput = new SessionListEditorInput(userDB); PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(sleInput, SessionListEditor.ID); } catch (PartInitException e) { logger.error("open session list", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.AbstractQueryAction_1, errStatus); // $NON-NLS-1$ } } else { MessageDialog.openWarning(null, "Information", "Not support database."); } }
private void edit(IStructuredSelection selection) { IStructuredSelection sel = (IStructuredSelection) selection; EnvironmentVariable var = (EnvironmentVariable) sel.getFirstElement(); if (var == null) { return; } String originalName = var.getName(); String value = var.getValue(); MultipleInputDialog dialog = new MultipleInputDialog( fDialog.getShell(), InterpretersMessages.AbstractInterpreterEnvironmentVariablesBlock_editVariable); dialog.addTextField(NAME_LABEL, originalName, false); dialog.addVariablesField(VALUE_LABEL, value, true); if (dialog.open() != Window.OK) { return; } String name = dialog.getStringValue(NAME_LABEL); value = dialog.getStringValue(VALUE_LABEL); if (!originalName.equals(name)) { fEnvironmentVariablesContentProvider.add( new EnvironmentVariable[] {new EnvironmentVariable(name, value)}, selection); } else { var.setValue(value); fVariablesViewer.refresh(true); } }
/** Runs the default action (open file). */ public void runDefaultAction(IStructuredSelection selection) { Object element = selection.getFirstElement(); if (element instanceof IPage) { openFileAction.selectionChanged(selection); openFileAction.run(); } }
public static IStructuredSelection processSelection(IStructuredSelection selection) { IStructuredSelection processedSelection = null; if (selection != null) { Object selectedObject = selection.getFirstElement(); if (selectedObject instanceof IFile) { selectedObject = ((IFile) selectedObject).getParent(); processedSelection = null; } if (selectedObject instanceof IFolder) { IFolder currentFolder = (IFolder) selectedObject; IJavaElement parentJavaElement = JavaCore.create(currentFolder); if (parentJavaElement instanceof IPackageFragment) { // Don't let you put WO's in a package processedSelection = new StructuredSelection(currentFolder.getProject()); } else if (parentJavaElement instanceof IPackageFragmentRoot) { // Don't let you put WO's in a source folder processedSelection = new StructuredSelection(currentFolder.getProject()); } else if (currentFolder.getName().endsWith(".wo")) { // Don't let you put WO's inside of WO's by accident processedSelection = new StructuredSelection(currentFolder.getParent()); } } } return processedSelection; }
private List<EObject> getSelfContainedModelElementTree(ExecutionEvent event) { List<EObject> result = new ArrayList<EObject>(); ISelection selection = HandlerUtil.getCurrentSelection(event); IStructuredSelection strucSel = null; EObject copyModelElement = null; if (selection != null && selection instanceof IStructuredSelection) { strucSel = (IStructuredSelection) selection; Object firstElement = strucSel.getFirstElement(); if (firstElement instanceof EObject) { // TODO: ChainSaw - check whether specific clone functionality of ModelUtil is needed here copyModelElement = EcoreUtil.copy((EObject) firstElement); // copyModelElement = ModelUtil.clone((EObject) firstElement); // only export the rootnode makes xml with references, otherwise (see (commented) line two) // the children // will be "real" nested as containments of the node (is not necessary) result.add(copyModelElement); // result.addAll(copyModelElement.getAllContainedModelElements()); } else { // do nothing System.out.println("NOT A MODELELEMENT"); } } return result; }
public static boolean enableDelete(IStructuredSelection graphicalSelection) { boolean enableDel = false; List<Object> elements = new ArrayList<Object>(); IStructuredSelection selection = Selection.getInstance().getStructuredSelection(); if (!selection.isEmpty()) { if (graphicalSelection.getFirstElement() instanceof DiagramEditPart) return false; enableDel = true; // Iterate through removing elements that are only graphical for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) { Object current = iter.next(); if (current instanceof GraphicalElement_c) { GraphicalElement_c ge = (GraphicalElement_c) current; if (ge.getRepresents() == null) { elements.add(current); Selection.getInstance().removeFromSelection(ge); } } } } selection = Selection.getInstance().getStructuredSelection(); if (!selection.isEmpty()) { // Check the remaining items against the usual DeleteAction, enableDel = DeleteAction.canDeleteAction(); } // Add the graphical only elements back to the selection for (int i = 0; i < elements.size(); ++i) { Selection.getInstance().addToSelection(elements.get(i)); } return enableDel; }