List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:org.eclipse.andmore.android.db.core.ui.wizards.CreateTableWizardPage.java
License:Apache License
@Override public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.FILL); composite.setLayout(new GridLayout(2, false)); GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false); Composite nameComposite = new Composite(composite, SWT.FILL); nameComposite.setLayout(new GridLayout(2, false)); nameComposite.setLayoutData(layoutData); layoutData = new GridData(SWT.LEFT, SWT.NONE, false, false); Label tableNameLabel = new Label(nameComposite, SWT.NONE); tableNameLabel.setLayoutData(layoutData); tableNameLabel.setText(DbCoreNLS.CreateTableWizardPage_UI_TableName); layoutData = new GridData(SWT.FILL, SWT.NONE, true, false); tableName = new Text(nameComposite, SWT.BORDER | SWT.SINGLE); tableName.setLayoutData(layoutData); tableName.addModifyListener(new ModifyListener() { @Override// w ww . ja va2s . c om public void modifyText(ModifyEvent e) { if (viewer != null) { viewer.refresh(); validatePage(); ((TableModel) viewer.getInput()).setName(tableName.getText()); } } }); if ((table != null) && (table.getName() != null)) { tableName.setText(table.getName()); } Composite emptyComposite = new Composite(composite, SWT.RIGHT); emptyComposite.setLayout(new GridLayout(1, false)); emptyComposite.layout(); viewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.FULL_SELECTION); layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(DbCoreNLS.CreateTableWizardPage_UI_Name); column.getColumn().setResizable(true); column.getColumn().setWidth(100); column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(DbCoreNLS.CreateTableWizardPage_UI_Type); column.getColumn().setResizable(true); column.getColumn().setWidth(100); column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(DbCoreNLS.CreateTableWizardPage_UI_Default); column.getColumn().setResizable(true); column.getColumn().setWidth(100); column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(DbCoreNLS.CreateTableWizardPage_UI_Primary); column.getColumn().setResizable(true); column.getColumn().setWidth(100); viewer.getTable().setHeaderVisible(true); viewer.getTable().setLinesVisible(true); viewer.getTable().setLayoutData(layoutData); viewer.setContentProvider(new TableWizardContentProvider()); viewer.setLabelProvider(new TableWizardLabelProvider()); Composite buttonBar = new Composite(composite, SWT.NONE); layoutData = new GridData(SWT.RIGHT, SWT.TOP, false, true); buttonBar.setLayoutData(layoutData); buttonBar.setLayout(new FillLayout(SWT.VERTICAL)); Button add = new Button(buttonBar, SWT.PUSH); add.setText(DbCoreNLS.CreateTableWizardPage_UI_Add); add.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { AddTableFieldDialog diag = new AddTableFieldDialog(getShell()); if (diag.open() == Window.OK) { ((TableModel) viewer.getInput()).addField(diag.getField()); viewer.refresh(); validatePage(); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); final Button edit = new Button(buttonBar, SWT.PUSH); edit.setText(DbCoreNLS.CreateTableWizardPage_UI_Edit); edit.setEnabled(false); edit.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (viewer.getTable().getSelectionCount() == 1) { AddTableFieldDialog diag = new AddTableFieldDialog(getShell(), ((TableModel) viewer.getInput()) .getFields().get(viewer.getTable().getSelectionIndex())); if (diag.open() == Window.OK) { viewer.update(diag.getField(), null); validatePage(); } } } }); final Button remove = new Button(buttonBar, SWT.PUSH); remove.setText(DbCoreNLS.CreateTableWizardPage_UI_Remove); remove.setEnabled(false); remove.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Object obj : structuredSelection.toList()) { if (obj instanceof Field) { ((TableModel) viewer.getInput()).removeField(((Field) obj)); } } viewer.refresh(); validatePage(); } } }); if (table == null) { table = new TableModel(); } viewer.setInput(table); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { int selectionCount = viewer.getTable().getSelectionCount(); remove.setEnabled(selectionCount > 0); edit.setEnabled(selectionCount == 1); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { if (viewer.getTable().getSelectionCount() == 1) { AddTableFieldDialog diag = new AddTableFieldDialog(getShell(), ((TableModel) viewer.getInput()) .getFields().get(viewer.getTable().getSelectionIndex())); if (diag.open() == Window.OK) { viewer.update(diag.getField(), null); validatePage(); } } } }); viewer.refresh(); composite.pack(); composite.layout(); setPageComplete(false); setErrorMessage(null); setControl(composite); // table fields will be not empty at this point when user is editing a // table, so page must be validated to enable finish button if (!table.getFields().isEmpty()) { validatePage(); } PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, TABLE_CONTEXT_HELP_ID); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, TABLE_CONTEXT_HELP_ID); }
From source file:org.eclipse.andmore.android.DDMSUtils.java
License:Apache License
public static InstallPackageBean installPackageWizard() { final InstallPackageBean bean = new InstallPackageBean(); final Display display = PlatformUI.getWorkbench().getDisplay(); display.syncExec(new Runnable() { @Override// w w w.jav a 2s . c o m public void run() { try { String defaultPath = null; DeployWizard wizard; IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { ISelection selection = window.getSelectionService().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection workbenchSSelection = (IStructuredSelection) selection; for (Object o : workbenchSSelection.toList()) { if (o instanceof IFile) { IFile file = (IFile) o; if (file.getFileExtension().equalsIgnoreCase(APK_FILE_EXTENSION)) { defaultPath = file.getLocation().toOSString(); } } } } } wizard = new DeployWizard(defaultPath); wizard.init(PlatformUI.getWorkbench(), new StructuredSelection()); WizardDialog dialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard); dialog.setPageSize(500, 200); if (dialog.open() == IDialogConstants.OK_ID) { bean.setPackagePath(wizard.getPackagePath()); bean.setCanOverwrite(wizard.canOverwrite()); } } catch (Throwable e) { AndmoreLogger.error(DDMSFacade.class, "Error executing deploy wizard", e); } } }); return bean; }
From source file:org.eclipse.andmore.internal.assetstudio.CreateAssetSetWizard.java
License:Open Source License
private IProject guessProject(IStructuredSelection selection) { if (selection == null) { return null; }// w w w. ja va 2 s .c o m for (Object element : selection.toList()) { if (element instanceof IAdaptable) { IResource res = (IResource) ((IAdaptable) element).getAdapter(IResource.class); IProject project = res != null ? res.getProject() : null; // Is this an Android project? try { if (project == null || !project.hasNature(AndmoreAndroidConstants.NATURE_DEFAULT)) { continue; } } catch (CoreException e) { // checking the nature failed, ignore this resource continue; } return project; } else if (element instanceof Pair<?, ?>) { // Pair of Project/String @SuppressWarnings("unchecked") Pair<IProject, String> pair = (Pair<IProject, String>) element; return pair.getFirst(); } } // Try to figure out the project from the active editor IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof AndroidXmlEditor) { Object input = ((AndroidXmlEditor) activeEditor).getEditorInput(); if (input instanceof FileEditorInput) { FileEditorInput fileInput = (FileEditorInput) input; return fileInput.getFile().getProject(); } } } } IJavaProject[] projects = AdtUtils.getOpenAndroidProjects(); if (projects != null && projects.length == 1) { return projects[0].getProject(); } return null; }
From source file:org.eclipse.andmore.internal.wizards.newxmlfile.NewXmlFileCreationPage.java
License:Open Source License
/** * Called by {@link NewXmlFileWizard} to initialize the page with the selection * received by the wizard -- typically the current user workbench selection. * <p/>//w ww . ja va 2s .c om * Things we expect to find out from the selection: * <ul> * <li>The project name, valid if it's an android nature.</li> * <li>The current folder, valid if it's a folder under /res</li> * <li>An existing filename, in which case the user will be asked whether to override it.</li> * </ul> * <p/> * The selection can also be set to a {@link Pair} of {@link IProject} and a workspace * resource path (where the resource path does not have to exist yet, such as res/anim/). * * @param selection The selection when the wizard was initiated. */ private boolean initializeFromSelection(IStructuredSelection selection) { if (selection == null) { return false; } // Find the best match in the element list. In case there are multiple selected elements // select the one that provides the most information and assign them a score, // e.g. project=1 + folder=2 + file=4. IProject targetProject = null; String targetWsFolderPath = null; String targetFileName = null; int targetScore = 0; for (Object element : selection.toList()) { if (element instanceof IAdaptable) { IResource res = (IResource) ((IAdaptable) element).getAdapter(IResource.class); IProject project = res != null ? res.getProject() : null; // Is this an Android project? try { if (project == null || !project.hasNature(AndmoreAndroidConstants.NATURE_DEFAULT)) { continue; } } catch (CoreException e) { // checking the nature failed, ignore this resource continue; } int score = 1; // we have a valid project at least IPath wsFolderPath = null; String fileName = null; assert res != null; // Eclipse incorrectly thinks res could be null, so tell it no if (res.getType() == IResource.FOLDER) { wsFolderPath = res.getProjectRelativePath(); } else if (res.getType() == IResource.FILE) { if (SdkUtils.endsWithIgnoreCase(res.getName(), DOT_XML)) { fileName = res.getName(); } wsFolderPath = res.getParent().getProjectRelativePath(); } // Disregard this folder selection if it doesn't point to /res/something if (wsFolderPath != null && wsFolderPath.segmentCount() > 1 && SdkConstants.FD_RESOURCES.equals(wsFolderPath.segment(0))) { score += 2; } else { wsFolderPath = null; fileName = null; } score += fileName != null ? 4 : 0; if (score > targetScore) { targetScore = score; targetProject = project; targetWsFolderPath = wsFolderPath != null ? wsFolderPath.toString() : null; targetFileName = fileName; } } else if (element instanceof Pair<?, ?>) { // Pair of Project/String @SuppressWarnings("unchecked") Pair<IProject, String> pair = (Pair<IProject, String>) element; targetScore = 1; targetProject = pair.getFirst(); targetWsFolderPath = pair.getSecond(); targetFileName = ""; } } if (targetProject == null) { // Try to figure out the project from the active editor IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof AndroidXmlEditor) { Object input = ((AndroidXmlEditor) activeEditor).getEditorInput(); if (input instanceof FileEditorInput) { FileEditorInput fileInput = (FileEditorInput) input; targetScore = 1; IFile file = fileInput.getFile(); targetProject = file.getProject(); IPath path = file.getParent().getProjectRelativePath(); targetWsFolderPath = path != null ? path.toString() : null; } } } } } if (targetProject == null) { // If we didn't find a default project based on the selection, check how many // open Android projects we can find in the current workspace. If there's only // one, we'll just select it by default. IJavaProject[] projects = AdtUtils.getOpenAndroidProjects(); if (projects != null && projects.length == 1) { targetScore = 1; targetProject = projects[0].getProject(); } } // Now set the UI accordingly if (targetScore > 0) { mValues.project = targetProject; mValues.folderPath = targetWsFolderPath; mProjectButton.setSelectedProject(targetProject); mFileNameTextField.setText(targetFileName != null ? targetFileName : ""); //$NON-NLS-1$ // If the current selection context corresponds to a specific file type, // select it. if (targetWsFolderPath != null) { int pos = targetWsFolderPath.lastIndexOf(WS_SEP_CHAR); if (pos >= 0) { targetWsFolderPath = targetWsFolderPath.substring(pos + 1); } String[] folderSegments = targetWsFolderPath.split(RES_QUALIFIER_SEP); if (folderSegments.length > 0) { mValues.configuration = FolderConfiguration.getConfig(folderSegments); String folderName = folderSegments[0]; selectTypeFromFolder(folderName); } } } return true; }
From source file:org.eclipse.ant.internal.ui.editor.outline.AntEditorContentOutlinePage.java
License:Open Source License
public void select(AntElementNode node) { if (getTreeViewer() != null) { ISelection s = getTreeViewer().getSelection(); if (s instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) s; List<?> nodes = ss.toList(); if (!nodes.contains(node)) { s = (node == null ? StructuredSelection.EMPTY : new StructuredSelection(node)); getTreeViewer().setSelection(s, true); }/* ww w . j a v a2 s . co m*/ } } }
From source file:org.eclipse.birt.report.designer.internal.ui.command.SelectionHandler.java
License:Open Source License
/** * Returns a <code>List</code> containing the currently selected objects. * /*from w w w.ja v a2s . co m*/ * @return A List containing the currently selected objects. */ protected List getSelectedObjects() { IStructuredSelection selectVariable = getSelection(); if (selectVariable == null) return Collections.EMPTY_LIST; return selectVariable.toList(); }
From source file:org.eclipse.birt.report.designer.internal.ui.dnd.DesignElementDragAdapter.java
License:Open Source License
/** * @see DragSourceAdapter#dragStart(DragSourceEvent) *//*from w w w . j a v a2 s. c o m*/ public void dragStart(DragSourceEvent event) { boolean doit = !getViewer().getSelection().isEmpty(); if (doit) { IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); selectionList = selection.toList(); Object[] objects = selection.toList().toArray(); if (validateType(objects)) { for (int i = 0; i < objects.length; i++) if (!validateTransfer(objects[i])) { doit = false; break; } } else doit = false; if (doit) TemplateTransfer.getInstance().setTemplate(objects); } event.doit = doit; if (Policy.TRACING_DND_DRAG && doit) { System.out.println("DND >> Drag starts."); //$NON-NLS-1$ } }
From source file:org.eclipse.birt.report.designer.internal.ui.views.data.dnd.ParameterDragListener.java
License:Open Source License
/** * @see DragSourceAdapter#dragSetData(DragSourceEvent) *//* ww w . jav a 2 s .c o m*/ public void dragSetData(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); Object[] objects = selection.toList().toArray(); if (TemplateTransfer.getInstance().isSupportedType(event.dataType)) { event.data = objects; } }
From source file:org.eclipse.birt.report.designer.internal.ui.wizards.WizardTemplateChoicePage.java
License:Open Source License
private ReportDesignHandle getSelectionHandle() { IStructuredSelection selection = (IStructuredSelection) templateList.getSelection(); List<?> list = selection.toList(); if (list.size() != 1) { return null; }//from ww w . j a v a 2 s . c o m Object data = list.get(0); if (data instanceof ReportDesignHandle) { return (ReportDesignHandle) data; } ReportDesignHandle handle = provider.getReportDesignHandle(data); return handle; }
From source file:org.eclipse.birt.report.designer.ui.actions.ApplyStyleMenuAction.java
License:Open Source License
private StyleHandle getStyleHandle() { IStructuredSelection selection = InsertInLayoutUtil.editPart2Model(getSelection()); if (!selection.isEmpty()) { Object firstElement = DNDUtil.unwrapToModel(selection.getFirstElement()); if (firstElement instanceof DesignElementHandle) { if (firstElement instanceof RowHandle || firstElement instanceof ColumnHandle) { selection = InsertInLayoutUtil .editPart2Model(TableUtil.filletCellInSelectionEditorpart(getSelection())); }/* www.j ava 2s.c o m*/ List modelList = DNDUtil.unwrapToModel(selection.toList()); SharedStyleHandle style = ((DesignElementHandle) firstElement).getStyle(); for (Iterator iterator = modelList.iterator(); iterator.hasNext();) { Object obj = iterator.next(); if (!(obj instanceof DesignElementHandle)) { return null; } if (((DesignElementHandle) obj).getStyle() != style) { return null; } } return style; } } return null; }