List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:com.archimatetool.editor.views.tree.TreeModelViewerFindReplaceProvider.java
License:Open Source License
public boolean replace(String toFind, String toReplaceWith) { // Replace All if (isAll()) { List<INameable> elements = getAllMatchingElements(toFind); if (!elements.isEmpty()) { List<String> newNames = new ArrayList<String>(); for (INameable nameable : elements) { String newName = getNewName(nameable.getName(), toFind, toReplaceWith); newNames.add(newName);/*from w w w .j a v a 2 s . c o m*/ } RenameCommandHandler.doRenameCommands(elements, newNames); fTreeModelViewer.setSelection(new StructuredSelection(elements), true); } return !elements.isEmpty(); } // Replace Next/Previous else { // Replace on selected elements if (replaceSelection) { List<Object> selected = getSelectedObjects(); if (!selected.isEmpty()) { List<INameable> elements = new ArrayList<INameable>(); List<String> newNames = new ArrayList<String>(); for (Object object : selected) { if (matches(object, toFind)) { INameable nameable = (INameable) object; elements.add(nameable); String newName = getNewName(nameable.getName(), toFind, toReplaceWith); newNames.add(newName); } } if (!elements.isEmpty()) { RenameCommandHandler.doRenameCommands(elements, newNames); return true; } } } // Replace on next single selection else { Object object = getFirstSelectedObject(); if (matches(object, toFind)) { RenameCommandHandler.doRenameCommand((INameable) object, getNewName(((INameable) object).getName(), toFind, toReplaceWith)); return true; } } // Else move forward return find(toFind); } }
From source file:com.archimatetool.editor.views.tree.TreeModelViewerFindReplaceProviderTests.java
License:Open Source License
@Test public void testFindAll() { // Set to Find All provider.setParameter(IFindReplaceProvider.PARAM_ALL, true); // Relations as well provider.setParameter(IFindReplaceProvider.PARAM_INCLUDE_RELATIONS, true); // Find in all models provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, true); _testFindAll();//from w ww . ja v a 2 s .co m // Find in selected model provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, false); treeViewer.setSelection(new StructuredSelection(model1)); _testFindAll(); }
From source file:com.archimatetool.editor.views.tree.TreeSelectionSynchroniser.java
License:Open Source License
@Override public void selectionChanged(SelectionChangedEvent event) { if (isDispatching) { return;/*from www . j ava2 s. c o m*/ } fLastEvent = event; if (!Preferences.doLinkView() || !fDoSync) { return; } isDispatching = true; ISelection selection = event.getSelection(); Object source = event.getSource(); // Selection from Diagram Editor, so update the Tree if it is showing if (source instanceof GraphicalViewer && fTreeView != null) { List<Object> list = new ArrayList<Object>(); for (Object o : ((IStructuredSelection) selection).toArray()) { if (o instanceof EditPart) { Object model = ((EditPart) o).getModel(); // Archimate element if (model instanceof IDiagramModelArchimateObject) { model = ((IDiagramModelArchimateObject) model).getArchimateElement(); list.add(model); } // Archimate connection else if (model instanceof IDiagramModelArchimateConnection) { model = ((IDiagramModelArchimateConnection) model).getRelationship(); list.add(model); } // Diagram model else if (model instanceof IDiagramModel) { list.add(model); } } } // Select in tree fTreeView.getViewer().setSelection(new StructuredSelection(list), true); } // Archimate objects selection from Tree View, so update any Archimate Diagram Editors else if (source instanceof TreeViewer) { List<IArchimateElement> list = new ArrayList<IArchimateElement>(); // Archimate elements for (Object o : ((IStructuredSelection) selection).toArray()) { if (o instanceof IArchimateElement) { list.add((IArchimateElement) o); } } // Select these in the Diagram Editors for (IDiagramModelEditor diagramEditor : fDiagramEditors) { if (diagramEditor instanceof IArchimateDiagramEditor) { ((IArchimateDiagramEditor) diagramEditor) .selectElements(list.toArray(new IArchimateElement[list.size()])); } } } isDispatching = false; }
From source file:com.archimatetool.hammer.view.ValidatorView.java
License:Open Source License
void selectObjects(IStructuredSelection selection) { if (selection != null) { List<IArchimateConcept> treeList = new ArrayList<IArchimateConcept>(); List<IDiagramModel> viewList = new ArrayList<IDiagramModel>(); List<IDiagramModelComponent> viewComponentList = new ArrayList<IDiagramModelComponent>(); for (Object o : selection.toArray()) { if (o instanceof IIssue) { IIssue issue = (IIssue) o; if (issue.getObject() instanceof IArchimateConcept) { treeList.add((IArchimateConcept) issue.getObject()); } else if (issue.getObject() instanceof IDiagramModel) { viewList.add((IDiagramModel) issue.getObject()); } else if (issue.getObject() instanceof IDiagramModelComponent) { viewList.add(((IDiagramModelComponent) issue.getObject()).getDiagramModel()); viewComponentList.add(((IDiagramModelComponent) issue.getObject())); }//w ww .jav a 2 s .c om } } if (!treeList.isEmpty()) { ITreeModelView view = (ITreeModelView) ViewManager.showViewPart(ITreeModelView.ID, false); if (view != null) { view.getViewer().setSelection(new StructuredSelection(treeList), true); } } if (!viewList.isEmpty()) { for (IDiagramModel dm : viewList) { IDiagramModelEditor editor = EditorManager.openDiagramEditor(dm); if (editor instanceof IArchimateDiagramEditor) { ((IArchimateDiagramEditor) editor).selectObjects(viewComponentList.toArray()); } } } } }
From source file:com.archimatetool.jasperreports.ExportJasperReportsWizardPage2.java
License:Open Source License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); container.setLayout(new GridLayout()); setControl(container);/*w ww. j ava 2s . c om*/ PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID); Composite fieldContainer = new Composite(container, SWT.NULL); fieldContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fieldContainer.setLayout(new GridLayout(2, false)); Label label = new Label(fieldContainer, SWT.NONE); label.setText(Messages.ExportJasperReportsWizardPage2_4); fComboTemplateViewer = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER)); fComboTemplateViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fComboTemplateViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { Template template = (Template) ((IStructuredSelection) event.getSelection()).getFirstElement(); if (template.location == null) { // Custom... handleCustomDialog(); } else { fLastSelectedTemplate = template; } } }); fComboTemplateViewer.setContentProvider(new IStructuredContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void dispose() { } @Override public Object[] getElements(Object inputElement) { return fTemplates.toArray(); } }); fComboTemplateViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ((Template) element).name; } }); fComboTemplateViewer.setInput(""); //$NON-NLS-1$ fComboTemplateViewer.setSelection(new StructuredSelection(fTemplates.get(0))); }
From source file:com.archimatetool.jasperreports.ExportJasperReportsWizardPage2.java
License:Open Source License
private void handleCustomDialog() { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); dialog.setText(Messages.ExportJasperReportsWizardPage2_5); if (!PlatformUtils.isMac()) { // Single file filtering in the Open dialog doesn't work on Mac dialog.setFilterExtensions(new String[] { "main.jrxml", "*.jrxml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ dialog.setFileName("main.jrxml"); //$NON-NLS-1$ } else {/*w ww.j a va2 s .c o m*/ dialog.setFilterExtensions(new String[] { "*.jrxml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ } String path = dialog.open(); if (path != null) { File file = new File(path); // Do we have it already? for (Template template : fTemplates) { if (file.equals(template.location)) { fComboTemplateViewer.setSelection(new StructuredSelection(template)); return; } } // No, add new one Template template = new Template(getShortPath(file), file); fTemplates.add(fTemplates.size() - 1, template); fComboTemplateViewer.refresh(); fComboTemplateViewer.setSelection(new StructuredSelection(template)); } else { fComboTemplateViewer.setSelection(new StructuredSelection(fLastSelectedTemplate)); } }
From source file:com.archimatetool.templates.dialog.TemplateManagerDialog.java
License:Open Source License
/** * Add a new group// ww w . j a va 2 s. co m */ protected void newGroup() { IInputValidator validator = new IInputValidator() { @Override public String isValid(String newText) { return "".equals(newText) ? "" : hasGroup(newText) ? Messages.TemplateManagerDialog_21 : null; //$NON-NLS-1$ //$NON-NLS-2$ } boolean hasGroup(String name) { for (ITemplateGroup group : fTemplateManager.getUserTemplateGroups()) { if (name.equals(group.getName())) { return true; } } return false; } }; InputDialog dialog = new InputDialog(getShell(), Messages.TemplateManagerDialog_22, Messages.TemplateManagerDialog_23, "", //$NON-NLS-1$ validator); if (dialog.open() == Window.OK) { String name = dialog.getValue(); if (StringUtils.isSetAfterTrim(name)) { ITemplateGroup group = new TemplateGroup(name); fTemplateManager.getUserTemplateGroups().add(group); fTreeViewer.refresh(); fTreeViewer.setSelection(new StructuredSelection(group), true); } } }
From source file:com.archimatetool.templates.impl.wizard.SaveArchimateModelAsTemplateWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { GridData gd;/* w w w .j ava 2 s . c o m*/ Label label; Composite container = new Composite(parent, SWT.NULL); container.setLayout(new GridLayout()); setControl(container); PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID); Group fileComposite = new Group(container, SWT.NULL); fileComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(3, false); fileComposite.setLayout(layout); label = new Label(fileComposite, SWT.NULL); label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_4); fFileTextField = new Text(fileComposite, SWT.BORDER | SWT.SINGLE); fFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); File newFile = new File(CURRENT_FOLDER, Messages.SaveArchimateModelAsTemplateWizardPage_5 + ArchimateTemplateManager.ARCHIMATE_TEMPLATE_FILE_EXTENSION); fFileTextField.setText(newFile.getPath()); // Single text control so strip CRLFs UIUtils.conformSingleTextControl(fFileTextField); fFileTextField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validateFields(); } }); Button fileButton = new Button(fileComposite, SWT.PUSH); fileButton.setText(Messages.SaveArchimateModelAsTemplateWizardPage_6); fileButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { File file = chooseFile(); if (file != null) { fFileTextField.setText(file.getPath()); CURRENT_FOLDER = file.getParentFile(); } } }); Group fieldGroup = new Group(container, SWT.NULL); fieldGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout = new GridLayout(2, false); fieldGroup.setLayout(layout); label = new Label(fieldGroup, SWT.NULL); label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_7); fNameTextField = new Text(fieldGroup, SWT.BORDER | SWT.SINGLE); fNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); if (StringUtils.isSet(fModel.getName())) { fNameTextField.setText(fModel.getName()); } // Single text control so strip CRLFs UIUtils.conformSingleTextControl(fNameTextField); fNameTextField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validateFields(); } }); label = new Label(fieldGroup, SWT.NULL); label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_8); gd = new GridData(SWT.NULL, SWT.TOP, false, false); label.setLayoutData(gd); fDescriptionTextField = new Text(fieldGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 120; fDescriptionTextField.setLayoutData(gd); if (StringUtils.isSet(fModel.getPurpose())) { fDescriptionTextField.setText(fModel.getPurpose()); } // Thumbnails boolean thumbsEnabled = !fModel.getDiagramModels().isEmpty(); Group thumbsGroup = new Group(container, SWT.NULL); thumbsGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); layout = new GridLayout(); thumbsGroup.setLayout(layout); fButtonIncludeThumbs = new Button(thumbsGroup, SWT.CHECK); fButtonIncludeThumbs.setText(Messages.SaveArchimateModelAsTemplateWizardPage_9); fButtonIncludeThumbs.setSelection(thumbsEnabled); fButtonIncludeThumbs.setEnabled(thumbsEnabled); fButtonIncludeThumbs.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { fModelViewsTreeViewer.getControl().setEnabled(fButtonIncludeThumbs.getSelection()); fPreviewLabel.setEnabled(fButtonIncludeThumbs.getSelection()); } }); label = new Label(thumbsGroup, SWT.NULL); label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_10); label.setEnabled(thumbsEnabled); Composite thumbContainer = new Composite(thumbsGroup, SWT.NULL); thumbContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); layout = new GridLayout(2, false); layout.marginWidth = 0; thumbContainer.setLayout(layout); fModelViewsTreeViewer = new ModelViewsTreeViewer(thumbContainer, SWT.NONE); fModelViewsTreeViewer.setInput(fModel.getFolder(FolderType.DIAGRAMS)); gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 120; //gd.widthHint = 140; fModelViewsTreeViewer.getControl().setLayoutData(gd); fModelViewsTreeViewer.getControl().setEnabled(thumbsEnabled); fPreviewLabel = new Label(thumbContainer, SWT.BORDER); gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 120; gd.widthHint = 150; fPreviewLabel.setLayoutData(gd); // Dispose of the image here not in the main dispose() method because if the help system is showing then // the TrayDialog is resized and this label is asked to relayout. fPreviewLabel.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { disposePreviewImage(); } }); fModelViewsTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { disposePreviewImage(); Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (o instanceof IDiagramModel) { TemplateUtils.createThumbnailPreviewImage((IDiagramModel) o, fPreviewLabel); } else { fPreviewLabel.setImage(null); } } }); // Select first Template item on tree (on a thread so that thumbnail preview is right size) fModelViewsTreeViewer.expandAll(); Display.getCurrent().asyncExec(new Runnable() { @Override public void run() { for (TreeItem item : fModelViewsTreeViewer.getTree().getItems()) { Object o = item.getData(); if (o instanceof IDiagramModel) { fModelViewsTreeViewer.setSelection(new StructuredSelection(o)); break; } } } }); validateFields(); }
From source file:com.archimatetool.templates.wizard.NewModelFromTemplateWizardPage.java
License:Open Source License
/** * Select first group on user table if there is one, else first group on inbuilt table *//*from w ww .j a va2 s .co m*/ private void selectFirstTableItem() { TableViewer tableViewer; if (!fTemplateManager.getUserTemplates().isEmpty()) { tableViewer = fUserTableViewer; } else { tableViewer = fInbuiltTableViewer; } Object o = tableViewer.getElementAt(0); if (o != null) { tableViewer.setSelection(new StructuredSelection(o)); tableViewer.getControl().setFocus(); } }
From source file:com.archimatetool.templates.wizard.SaveModelAsTemplateToCollectionWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { GridData gd;//from ww w. jav a 2 s . c om Label label; Composite container = new Composite(parent, SWT.NULL); container.setLayout(new GridLayout()); setControl(container); PlatformUI.getWorkbench().getHelpSystem().setHelp(container, getHelpID()); fDoStoreInCollectionButton = new Button(container, SWT.CHECK); fDoStoreInCollectionButton.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_0); fDoStoreInCollectionButton.setSelection(true); fDoStoreInCollectionButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean enabled = fDoStoreInCollectionButton.getSelection(); fCategoriesTableViewer.getControl().setEnabled(enabled); fNewGroupButton.setEnabled(enabled); // Select first group, or none if (enabled) { Object o = fCategoriesTableViewer.getElementAt(0); if (o != null) { fCategoriesTableViewer.setSelection(new StructuredSelection(o)); } } else { fCategoriesTableViewer.setSelection(new StructuredSelection()); } } }); label = new Label(container, SWT.NULL); label.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_1); Composite fieldContainer = new Composite(container, SWT.NULL); fieldContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 0; fieldContainer.setLayout(layout); Composite tableComp = new Composite(fieldContainer, SWT.NULL); tableComp.setLayout(new TableColumnLayout()); gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 120; tableComp.setLayoutData(gd); fCategoriesTableViewer = new TemplateGroupsTableViewer(tableComp, SWT.BORDER | SWT.MULTI); fCategoriesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { fSelectedTemplateGroup = (ITemplateGroup) ((IStructuredSelection) event.getSelection()) .getFirstElement(); } }); fCategoriesTableViewer.setInput(fTemplateManager.getUserTemplateGroups()); fNewGroupButton = new Button(fieldContainer, SWT.NULL); fNewGroupButton.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_2); gd = new GridData(SWT.TOP, SWT.TOP, false, false); fNewGroupButton.setLayoutData(gd); fNewGroupButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IInputValidator validator = new IInputValidator() { @Override public String isValid(String newText) { return "".equals(newText) ? "" //$NON-NLS-1$//$NON-NLS-2$ : hasGroup(newText) ? Messages.SaveModelAsTemplateToCollectionWizardPage_3 : null; } boolean hasGroup(String name) { for (ITemplateGroup group : fTemplateManager.getUserTemplateGroups()) { if (name.equals(group.getName())) { return true; } } return false; } }; InputDialog dialog = new InputDialog(getShell(), Messages.SaveModelAsTemplateToCollectionWizardPage_4, Messages.SaveModelAsTemplateToCollectionWizardPage_5, "", //$NON-NLS-1$ validator); if (dialog.open() == Window.OK) { String name = dialog.getValue(); if (StringUtils.isSetAfterTrim(name)) { ITemplateGroup group = new TemplateGroup(name); fTemplateManager.getUserTemplateGroups().add(group); fCategoriesTableViewer.refresh(); fCategoriesTableViewer.setSelection(new StructuredSelection(group), true); } } } }); setPageComplete(true); }