List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:org.bonitasoft.studio.contract.ui.property.input.ContractInputController.java
License:Open Source License
@Override public void remove(final ColumnViewer viewer) { final IObservableValue contractObservable = (IObservableValue) viewer.getInput(); final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); final List<?> selectedInput = selection.toList(); Contract contract = (Contract) contractObservable.getValue(); if (openConfirmation(selectedInput)) { final RefactorContractInputOperation refactorOperation = newRefactorOperation(contract); final TransactionalEditingDomain editingDomain = editingDomain(contract); refactorOperation.setEditingDomain(editingDomain); refactorOperation.setAskConfirmation(shouldAskConfirmation()); final CompoundCommand compoundCommand = refactorOperation.getCompoundCommand(); for (final Object input : selectedInput) { final ContractInput contractInput = (ContractInput) input; contract = ModelHelper.getFirstContainerOfType(contractInput, Contract.class); //Parent input has been removed in current selection if (contract == null) { continue; }//w w w .j a v a2s . c om refactorOperation.addItemToRefactor(null, contractInput); compoundCommand.append(DeleteCommand.create(editingDomain, contractInput)); final Collection<ContractConstraint> constraintsReferencingInput = constraintsReferencingSingleInput( contract, contractInput); if (!constraintsReferencingInput.isEmpty()) { compoundCommand.append(DeleteCommand.create(editingDomain, constraintsReferencingInput)); } } try { if (refactorOperation.canExecute()) { progressService.run(true, true, refactorOperation); } } catch (final InvocationTargetException | InterruptedException e) { BonitaStudioLog.error("Failed to remove contract input.", e); openErrorDialog(e); } } }
From source file:org.bonitasoft.studio.data.ui.property.section.AbstractDataSection.java
License:Open Source License
protected void removeData(IStructuredSelection structuredSelection) { String[] buttonList = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; OutlineDialog dialog = new OutlineDialog(Display.getDefault().getActiveShell(), Messages.deleteDataDialogTitle, Display.getCurrent().getSystemImage(SWT.ICON_WARNING), createMessage(structuredSelection), MessageDialog.CONFIRM, buttonList, 1, structuredSelection.toList()); if (dialog.open() == Dialog.OK) { IProgressService service = PlatformUI.getWorkbench().getProgressService(); CompoundCommand cc = new CompoundCommand("Remove list of data"); boolean canExecute = false; for (Object d : structuredSelection.toList()) { RefactorDataOperation op = new RefactorDataOperation( BonitaGroovyRefactoringAction.REMOVE_OPERATION); op.setCompoundCommand(cc);//from w ww . jav a2s . co m op.setContainer(ModelHelper.getParentProcess(eObject)); op.setEditingDomain(getEditingDomain()); op.setOldData((Data) d); op.updateReferencesInScripts(); try { if (op.isCanExecute()) { service.run(true, false, op); cc.append(DeleteCommand.create(getEditingDomain(), d)); canExecute = canExecute || true; } else { canExecute = canExecute || false; } } catch (InvocationTargetException e) { BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID); } catch (InterruptedException e) { BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID); } } if (canExecute) { getEditingDomain().getCommandStack().execute(cc); } else { cc.dispose(); } try { RepositoryManager.getInstance().getCurrentRepository().getProject().build( IncrementalProjectBuilder.FULL_BUILD, XtextProjectHelper.BUILDER_ID, new HashMap<String, String>(), null); } catch (CoreException e) { BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID); } } }
From source file:org.bonitasoft.studio.data.ui.property.section.AbstractDataSection.java
License:Open Source License
@SuppressWarnings("unchecked") protected void moveData(IStructuredSelection structuredSelection) { MoveDataWizard moveDataWizard = new MoveDataWizard((DataAware) getEObject()); if (new WizardDialog(Display.getDefault().getActiveShell(), moveDataWizard).open() == Dialog.OK) { DataAware dataAware = moveDataWizard.getSelectedDataAwareElement(); try {/* w ww . j ava 2 s.c om*/ MoveDataCommand cmd = new MoveDataCommand(getEditingDomain(), (DataAware) getEObject(), structuredSelection.toList(), dataAware); OperationHistoryFactory.getOperationHistory().execute(cmd, null, null); if (!(cmd.getCommandResult().getStatus().getSeverity() == Status.OK)) { List<Object> data = (List<Object>) cmd.getCommandResult().getReturnValue(); String dataNames = ""; for (Object d : data) { dataNames = dataNames + ((Element) d).getName() + ","; } dataNames = dataNames.substring(0, dataNames.length() - 1); MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.PromoteDataWarningTitle, Messages.bind(Messages.PromoteDataWarningMessage, dataNames)); } } catch (ExecutionException e1) { BonitaStudioLog.error(e1); } refresh(); } }
From source file:org.bonitasoft.studio.data.ui.property.section.control.ProcessDataViewer.java
License:Open Source License
protected void moveData(final IStructuredSelection structuredSelection) { final DataAware container = (DataAware) getDataContainerObservable().getValue(); final MoveDataWizard moveDataWizard = new MoveDataWizard(container); if (createWizardDialog(moveDataWizard, IDialogConstants.FINISH_LABEL).open() == Dialog.OK) { final DataAware dataAware = moveDataWizard.getSelectedDataAwareElement(); try {/*from w ww. jav a2 s .c o m*/ final MoveDataCommand cmd = new MoveDataCommand(TransactionUtil.getEditingDomain(dataAware), container, structuredSelection.toList(), dataAware); OperationHistoryFactory.getOperationHistory().execute(cmd, null, null); if (!(cmd.getCommandResult().getStatus().getSeverity() == Status.OK)) { final List<Object> data = (List<Object>) cmd.getCommandResult().getReturnValue(); String dataNames = ""; for (final Object d : data) { dataNames = dataNames + ((Element) d).getName() + ","; } dataNames = dataNames.substring(0, dataNames.length() - 1); MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.PromoteDataWarningTitle, Messages.bind(Messages.PromoteDataWarningMessage, dataNames)); } } catch (final ExecutionException e1) { BonitaStudioLog.error(e1); } } }
From source file:org.bonitasoft.studio.data.ui.property.section.RemoveDataHandler.java
License:Open Source License
public void execute(final IStructuredSelection structuredSelection, final EObject container, final EStructuralFeature dataFeature) { final String[] buttonList = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; final OutlineDialog dialog = new OutlineDialog(Display.getDefault().getActiveShell(), org.bonitasoft.studio.common.Messages.removalConfirmationDialogTitle, Display.getCurrent().getSystemImage(SWT.ICON_WARNING), createMessage(structuredSelection), MessageDialog.CONFIRM, buttonList, 1, structuredSelection.toList()); if (dialog.open() == Dialog.OK) { final IProgressService service = PlatformUI.getWorkbench().getProgressService(); final RefactorDataOperation op = new RefactorDataOperation(RefactoringOperationType.REMOVE); for (final Object d : structuredSelection.toList()) { op.setEditingDomain(TransactionUtil.getEditingDomain(container)); op.addItemToRefactor(null, (Data) d); op.setDataContainer((DataAware) container); op.setDataContainmentFeature(dataFeature); op.setAskConfirmation(true); }//from w w w . j av a 2 s . c o m try { if (op.canExecute()) { service.run(true, true, op); } } catch (final InvocationTargetException e) { BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID); } catch (final InterruptedException e) { BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID); } try { RepositoryManager.getInstance().getCurrentRepository().getProject().build( IncrementalProjectBuilder.FULL_BUILD, XTEXT_BUILDER_ID, Collections.<String, String>emptyMap(), null); } catch (final CoreException e) { BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID); } } }
From source file:org.bonitasoft.studio.dependencies.ui.dialog.ManageJarDialog.java
License:Open Source License
protected void addRemoveJarButton(Composite rightPanel) { removeButton = new Button(rightPanel, SWT.FLAT); removeButton.setText(Messages.removeJar); removeButton.setEnabled(false);// w ww .ja va 2 s . c o m removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.beginToRemoveJars, selection.size()); for (Object selected : selection.toList()) { if (monitor.isCanceled()) { return; } if (selected instanceof IRepositoryFileStore) { try { monitor.worked(1); monitor.setTaskName(Messages.removingJar + " : " + ((IRepositoryFileStore) selected).getName()); ((IRepositoryFileStore) selected).delete(); } catch (Exception e1) { BonitaStudioLog.error(e1); } } } } }; try { new ProgressMonitorDialog(getShell()).run(true, true, runnable); } catch (InvocationTargetException e1) { BonitaStudioLog.error(e1); } catch (InterruptedException e2) { BonitaStudioLog.error(e2); } /*Due to some file handle issue and lock on windows we need to warn user if the jars are not correctly deleted*/ if (Platform.getOS().equals(Platform.OS_WIN32)) { boolean shouldRestart = false; for (Object selected : selection.toList()) { if (selected instanceof IRepositoryFileStore) { if (((IRepositoryFileStore) selected).getResource().exists()) { shouldRestart = true; break; } } } if (shouldRestart) { MessageDialog.openInformation(getShell(), Messages.informationDeleteJarTitle, Messages.informationDeleteJarMessage); } } /*Refresh viewer*/ tableViewer.setInput(libStore.getChildren()); tableViewer.refresh(true); } }); }
From source file:org.bonitasoft.studio.diagram.custom.clipboard.CustomClipboardSupportGlobalActionHandler.java
License:Open Source License
/** * @return/*from w ww . jav a 2 s . c o m*/ */ private List<IGraphicalEditPart> getSelectedEditParts(IGlobalActionContext cntxt) { List<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>(); IStructuredSelection selection = (IStructuredSelection) cntxt.getSelection(); for (Object item : selection.toList()) { if (item instanceof IGraphicalEditPart) { res.add((IGraphicalEditPart) item); } } return res; }
From source file:org.bonitasoft.studio.document.ui.DocumentPropertySection.java
License:Open Source License
private int openOutlineDialog(final IStructuredSelection selection) { final StringBuilder sb = new StringBuilder(); for (final Object selectionElement : selection.toList()) { if (selectionElement instanceof Document) { sb.append(((Document) selectionElement).getName() + "\n"); }/*www . j a v a2 s . c o m*/ } if (sb.length() > 0) { sb.delete(sb.length() - 1, sb.length()); } final String[] buttonList = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; final java.util.List<Object> selectionList = ((IStructuredSelection) documentListViewer.getSelection()) .toList(); final OutlineDialog dialog = new OutlineDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), removalConfirmationDialogTitle, Display.getCurrent().getSystemImage(SWT.ICON_WARNING), NLS.bind(Messages.areYouSureMessage, sb.toString()), MessageDialog.CONFIRM, buttonList, 1, selectionList); return dialog.open(); }
From source file:org.bonitasoft.studio.parameters.property.section.ParameterPropertySection.java
License:Open Source License
protected void createRemoveParameterButton(final Composite buttonsComposite) { removeButton = widgetFactory.createButton(buttonsComposite, Messages.remove, SWT.FLAT); removeButton.setLayoutData(GridDataFactory.fillDefaults().hint(85, SWT.DEFAULT).create()); removeButton.addSelectionListener(new SelectionAdapter() { @Override/*www . j a va 2 s . c o m*/ public void widgetSelected(final SelectionEvent e) { final IStructuredSelection selection = (IStructuredSelection) parameterTableViewer.getSelection(); final StringBuilder sb = new StringBuilder(); for (final Object selectionElement : selection.toList()) { if (selectionElement instanceof Parameter) { sb.append(((Parameter) selectionElement).getName() + "\n"); } } if (sb.length() > 0) { sb.delete(sb.length() - 1, sb.length()); } final String[] buttonList = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; final List<Object> selectionList = ((IStructuredSelection) parameterTableViewer.getSelection()) .toList(); final OutlineDialog dialog = new OutlineDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), removalConfirmationDialogTitle, Display.getCurrent().getSystemImage(SWT.ICON_WARNING), NLS.bind(Messages.areYouSureMessage, sb.toString()), MessageDialog.CONFIRM, buttonList, 1, selectionList); final int ok = 0; if (ok == dialog.open()) { for (final Object parameter : selection.toList()) { final RemoveParametersOperation op = new RemoveParametersOperation((Parameter) parameter, (AbstractProcess) getEObject()); op.setEditingDomain(getEditingDomain()); op.setAskConfirmation(true); final IProgressService service = PlatformUI.getWorkbench().getProgressService(); try { service.busyCursorWhile(op); } catch (final InvocationTargetException ex) { BonitaStudioLog.error(ex); } catch (final InterruptedException ex) { BonitaStudioLog.error(ex); } } parameterTableViewer.refresh(); try { RepositoryManager.getInstance().getCurrentRepository().getProject().build( IncrementalProjectBuilder.FULL_BUILD, XtextProjectHelper.BUILDER_ID, Collections.<String, String>emptyMap(), null); } catch (final CoreException e1) { BonitaStudioLog.error(e1, ParameterPlugin.PLUGIN_ID); } } } }); }
From source file:org.bonitasoft.studio.validators.ui.wizard.ValidatorWizardPage.java
License:Open Source License
protected void createDependenciesViewer(Composite mainComposite) { Label dependencyLabel = new Label(mainComposite, SWT.NONE); dependencyLabel.setText(Messages.dependencies); dependencyLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create()); final TableViewer viewer = new TableViewer(mainComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); viewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); viewer.setContentProvider(new ArrayContentProvider()); viewer.addSelectionChangedListener(this); viewer.setLabelProvider(new LabelProvider() { @Override/*from w w w . j a v a 2 s .c o m*/ public Image getImage(Object element) { return Pics.getImage("jar.gif", ValidatorPlugin.getDefault()); } }); context.bindValue(ViewersObservables.observeInput(viewer), EMFObservables.observeValue(validator, ValidatorPackage.Literals.VALIDATOR_DESCRIPTOR__DEPENDENCIES)); final Composite buttonComposite = new Composite(mainComposite, SWT.NONE); buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create()); buttonComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create()); final Button addButton = new Button(buttonComposite, SWT.FLAT); addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); addButton.setText(Messages.Add); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SelectJarsDialog dialog = new SelectJarsDialog(Display.getDefault().getActiveShell()); if (dialog.open() == Dialog.OK) { for (IRepositoryFileStore jarFile : dialog.getSelectedJars()) { String jar = jarFile.getName(); if (!validator.getDependencies().contains(jar)) { validator.getDependencies().add(jar); } } } } }); removeButton = new Button(buttonComposite, SWT.FLAT); removeButton.setLayoutData( GridDataFactory.fillDefaults().hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create()); removeButton.setText(Messages.Remove); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); for (Object selected : selection.toList()) { if (selected instanceof String) { validator.getDependencies().remove(selected); } } viewer.refresh(); } }); }