List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:de.marw.cdt.cmake.core.ui.DefinesViewer.java
License:Open Source License
private void handleDefineDelButton(TableViewer tableViewer) { final IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); final Shell shell = tableViewer.getControl().getShell(); if (MessageDialog.openQuestion(shell, "CMake-Define deletion confirmation", "Are you sure to delete the selected CMake-defines?")) { @SuppressWarnings("unchecked") ArrayList<CmakeDefine> defines = (ArrayList<CmakeDefine>) tableViewer.getInput(); defines.removeAll(selection.toList()); tableViewer.remove(selection.toArray());// updates the display }//from w w w. jav a 2s .c o m }
From source file:de.marw.cdt.cmake.core.ui.UnDefinesViewer.java
License:Open Source License
private void handleUnDefineDelButton(TableViewer tableViewer) { final IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); final Shell shell = tableViewer.getControl().getShell(); if (MessageDialog.openQuestion(shell, "CMake-Undefine deletion confirmation", "Are you sure to delete the selected CMake-undefines?")) { @SuppressWarnings("unchecked") ArrayList<String> undefines = (ArrayList<String>) tableViewer.getInput(); undefines.removeAll(selection.toList()); tableViewer.remove(selection.toArray());// updates the display }/*from w w w. ja v a2s .co m*/ }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.actions.colors.SetFeatureColorAction.java
License:Open Source License
/** * @param selection/*from ww w . jav a 2 s .co m*/ * Creates a featureList with the selected features of the feature diagram. */ public void updateFeatureList(IStructuredSelection selection) { if (!selection.isEmpty()) { featureList.clear(); Object[] editPartArray = selection.toArray(); for (int i = 0; i < selection.size(); i++) { Object editPart = editPartArray[i]; if (editPart instanceof FeatureEditPart) { FeatureEditPart editP = (FeatureEditPart) editPart; IGraphicalFeature feature = editP.getFeature(); if (!featureList.contains(feature)) featureList.add(feature); } } return; } else { return; } }
From source file:de.quamoco.adaptation.view.tasks.actions.AbstractViewHandler.java
License:Apache License
/** * Returns all selected {@link AdaptationTask}s. * @param event the execution event.//from w w w. ja v a 2s .com * @return the selected {@link AdaptationTask}s in the {@link AdaptationTasksView} */ public List<AdaptationTask> getSelectedTasks(ExecutionEvent event) { final IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); // iterate over selection and add adaptation tasks. LinkedList<AdaptationTask> taskList = new LinkedList<AdaptationTask>(); for (Object selectedObject : selection.toArray()) { if (selectedObject instanceof AdaptationTask) { taskList.add((AdaptationTask) selectedObject); } } return taskList; }
From source file:de.tud.cs.st.vespucci.diagram.handler.ChangeDependenciesKindHandler.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final IStructuredSelection currentSelection = (IStructuredSelection) HandlerUtil .getCurrentSelectionChecked(event); final Object[] currentSelectionArr = currentSelection.toArray(); // This array will contain the casted selection-objects. final ConnectionEditPart[] selectedConnections = new ConnectionEditPart[currentSelection.size()]; for (int i = 0; i < currentSelection.size(); ++i) { if (currentSelectionArr[i] instanceof ConnectionEditPart) { selectedConnections[i] = (ConnectionEditPart) currentSelectionArr[i]; } else {// ww w . j a va 2 s. c o m // If this exception is reached, then there should be something wrong with the // visibleWhen entry of the popUp-menu. return new ExecutionException("Selection is not a connection!"); } } final Event trigger = (Event) event.getTrigger(); // Dependency kind to be toggled (added or removed). final String dependencyKind = ((MenuItem) trigger.widget).getText(); for (final ConnectionEditPart connection : selectedConnections) { // Editing domain. Must be used to keep consistency. final TransactionalEditingDomain editDomain = connection.getEditingDomain(); // EObject representing the connection. final EObject semanticConnection = connection.resolveSemanticElement(); // Feature to be set or unset. Here: The dependencies of the constraint. final EStructuralFeature toggleFeature = semanticConnection.eClass() .getEStructuralFeature(Vespucci_modelPackage.CONNECTION__NAME); // get current dependencies String[] currentDependencies = ((String) semanticConnection.eGet(toggleFeature, true)).split(", "); // only one empty string should be empty array if (Arrays.equals(currentDependencies, new String[] { "" })) { currentDependencies = new String[0]; } // toggle dependency final String[] newDependencies = transformedCopy(currentDependencies, dependencyKind); // Command that will update the connection final SetCommand setCommand = new SetCommand(editDomain, semanticConnection, toggleFeature, joinString(newDependencies)); editDomain.getCommandStack().execute(setCommand); } return null; }
From source file:de.tud.cs.st.vespucci.diagram.handler.GeneratePrologFacts.java
License:Open Source License
/** * Handles the event, if it is a IStructuredSelection. Should only be used * for Vespucci diagram files. Generates the prolog facts of the given * SAD-files./*from w w w. ja va2 s. c om*/ * * @return null */ @Override public Object execute(final ExecutionEvent event) { // current Package Explorer selection final IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); for (final Object o : selection.toArray()) { if (o instanceof IFile) { final IFile file = (IFile) o; final File diagramFile = file.getRawLocation().toFile(); if (PrologFileCreator.isDiagramFile(diagramFile)) { createPrologFileFrom(diagramFile); refreshPageView(file); } } } return null; }
From source file:de.tud.cs.st.vespucci.diagram.handler.SetDependencyConstraintHandler.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final SetConstraintTypeParameter typeParams = new SetConstraintTypeParameter(); final IElementType setType = typeParams.getParameterValues() .get(event.getParameter("de.tud.cs.st.vespucci.diagram.SetConstraintTypeParam")); final IStructuredSelection currentSelection = (IStructuredSelection) HandlerUtil .getCurrentSelectionChecked(event); // ensure selection is not empty if (currentSelection.size() == 0) { // nothing to do return null; }//w ww .j a va 2s .c o m final Object[] currentSelectionArr = currentSelection.toArray(); // This array will contain the casted selection-objects. final ConnectionEditPart[] selectedConnections = new ConnectionEditPart[currentSelection.size()]; for (int i = 0; i < currentSelection.size(); ++i) { if (currentSelectionArr[i] instanceof ConnectionEditPart) { selectedConnections[i] = (ConnectionEditPart) currentSelectionArr[i]; } else { // If this exception is reached, then there should be something wrong with the // visibleWhen entry of the popUp-menu. return new VespucciUnexpectedException(COMMAND_LABEL + ": Selection is not a connection!"); } } CompoundCommand cmd = new CompoundCommand(COMMAND_LABEL); for (ConnectionEditPart conn : selectedConnections) { cmd.append(new SetConnectionTypeCommand(conn, setType)); } selectedConnections[0].getEditingDomain().getCommandStack().execute(cmd); return null; }
From source file:de.tud.cs.st.vespucci.diagram.menuItems.SetDependencyConstraintEntries.java
License:Open Source License
/** * @return The connections currently selected in the active window. *//*w ww.j a v a2 s .c o m*/ private static ConnectionEditPart[] getSelectedConnectionEditParts() { final IStructuredSelection selection = (IStructuredSelection) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getSelectionService().getSelection(); final Object[] selectionArr = selection.toArray(); // This array will contain the casted selection-objects. final ConnectionEditPart[] selectedConnections = new ConnectionEditPart[selectionArr.length]; for (int i = 0; i < selectionArr.length; ++i) { selectedConnections[i] = (ConnectionEditPart) selectionArr[i]; } return selectedConnections; }
From source file:de.tud.cs.st.vespucci.diagram.menuItems.SetDependencyKindEntries.java
License:Open Source License
/** * This method traverses all selected constraints and returns, which check mark should be used. * /*from w ww . java2 s . c o m*/ * @param dependency * Dependency to be checked. * @return The index for the correct check mark in {@link #checkmark}. */ private static int getCheckMarkIndex(final String dependency) { final IStructuredSelection selection = (IStructuredSelection) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getSelectionService().getSelection(); final Object[] selectionArr = selection.toArray(); // This array will contain the casted selection-objects. final ConnectionEditPart[] selectedConnections = new ConnectionEditPart[selection.size()]; for (int i = 0; i < selection.size(); ++i) { selectedConnections[i] = (ConnectionEditPart) selectionArr[i]; } boolean selectionContainsDep = false; boolean firstConstraint = true; for (final ConnectionEditPart connection : selectedConnections) { // Get dependencies of constraint a.k.a. name of connection final EObject semanticConnection = connection.resolveSemanticElement(); final EStructuralFeature feature = semanticConnection.eClass() .getEStructuralFeature(Vespucci_modelPackage.CONNECTION__NAME); final String conName = (String) semanticConnection.eGet(feature); // check if given dependency is set boolean conContainsDep = false; for (final String str : conName.split(", ")) { if (dependency.equals(str)) { if (!firstConstraint && !selectionContainsDep) { // dependency set, but there are constraints without this dependency return 0; } selectionContainsDep = true; conContainsDep = true; break; } } if (!firstConstraint && selectionContainsDep && !conContainsDep) { // dependency not set, but there are constraints with this dependency return 0; } firstConstraint = false; } if (selectionContainsDep) { // all constraints have the given dependency set. return 1; } // 2 indicates, that entry is not checked. return 2; }
From source file:de.tud.cs.st.vespucci.versioning.handler.UpdateSadFileHandler.java
License:Open Source License
/** * Custom execute method with a IStructuredSelection argument which is more simple to call programmatically. * /*from ww w. j av a2s. c o m*/ * @param selection * The selection on which to execute the transformation. * @return null Has to be null. */ public Object execute(final IStructuredSelection selection) { for (final Object o : selection.toArray()) { if (o instanceof IFile) { final IFile file = (IFile) o; final VespucciVersionChain versionChain = VespucciVersionChain.getInstance(); VespucciVersionTemplate currentVersion = versionChain.getVersionOfFile(file); while (!currentVersion.isNewestVersion()) { final VespucciVersionTemplate nextVersion = versionChain.getNextVersion(currentVersion); if (nextVersion == null) { return null; } final File backupFile = getUniqueFilePointerForVersion(file, currentVersion); final URI outputUri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); final Job job = new Job(String.format("Updating Vespucci file %s from version %s to %s.", file, currentVersion.getIdentifier(), nextVersion.getIdentifier())) { @Override protected IStatus run(final IProgressMonitor monitor) { return nextVersion.updateFromDirectPredecessorVersion(file, backupFile, outputUri, monitor); } }; // Jobs must be blocking in order to prevent conflicts during usage // of the static methods in TransformationHelperLibrary job.setRule(ResourcesPlugin.getWorkspace().getRoot()); job.setPriority(Job.SHORT); job.setUser(true); job.schedule(); currentVersion = nextVersion; } } } return null; }