List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:ch.elexis.views.rechnung.RechnungsListeView.java
License:Open Source License
@SuppressWarnings("unchecked") List<Rechnung> createList() { IStructuredSelection sel = (IStructuredSelection) cv.getViewerWidget().getSelection(); List<Tree> at = sel.toList(); List<Rechnung> ret = new LinkedList<Rechnung>(); for (Tree<PersistentObject> t : at) { if (t.contents instanceof Patient) { for (Tree<PersistentObject> tp : t.getChildren()) { for (Tree<PersistentObject> tf : tp.getChildren()) { ret.add((Rechnung) tf.contents); }/*from w ww .ja va 2 s.co m*/ } } else if (t.contents instanceof Fall) { for (Tree<PersistentObject> tr : t.getChildren()) { ret.add((Rechnung) tr.contents); } } else if (t.contents instanceof Rechnung) { Rechnung r = (Rechnung) t.contents; ret.add(r); } } return ret; }
From source file:com.amalto.workbench.actions.XSDNewBrowseItemViewAction.java
License:Open Source License
protected List getSelectedXSDElementDeclarations() { IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); return selection.toList(); }
From source file:com.amalto.workbench.dialogs.datacontainer.UpdateAutoIncrementDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { if (resetAllBtnId == buttonId) { List<Line> lines = (List<Line>) resultsViewer.getInput(); for (Line line : lines) { line.keyValues.get(1).value = DEFAULT_VALUE; }/*from w w w . j a va2s .c o m*/ resultsViewer.refresh(); } if (resetBtnId == buttonId) { IStructuredSelection selection = (IStructuredSelection) resultsViewer.getSelection(); for (Object obj : selection.toList()) { Line line = (Line) obj; line.keyValues.get(1).value = DEFAULT_VALUE; } resultsViewer.refresh(); } super.buttonPressed(buttonId); }
From source file:com.amalto.workbench.editors.actions.DeleteItemsAction.java
License:Open Source License
@Override public void run() { try {//w ww . j a v a2 s. c o m super.run(); // retrieve the list of items IStructuredSelection selection = ((IStructuredSelection) viewer.getSelection()); List<WSRoutingOrderV2> lineItems = selection.toList(); if (lineItems.size() == 0) { return; } if (!MessageDialog.openConfirm(this.shell, Messages.RoutingEngineV2BrowserMainPage_ConfirmDeletion, Messages.bind(Messages.RoutingEngineV2BrowserMainPage_ErrorMsg2, lineItems.size()))) { return; } // Instantiate the Monitor with actual deletes DeleteItemsWithProgress diwp = new DeleteItemsWithProgress( (TMDMService) routingEngineV2BrowserMainPage.getAdapter(TMDMService.class), lineItems, this.shell); // run new ProgressMonitorDialog(this.shell).run(false, // fork true, // cancelable diwp); // refresh the search routingEngineV2BrowserMainPage.doSearch(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(shell, Messages._Error, Messages.bind(Messages.RoutingEngineV2BrowserMainPage_ErrorMsg3, e.getLocalizedMessage())); } }
From source file:com.amalto.workbench.editors.actions.ExecuteRoutingOrdersAction.java
License:Open Source License
@Override public void run() { try {//from ww w . ja v a 2s . c om super.run(); // retrieve the list of items IStructuredSelection selection = ((IStructuredSelection) viewer.getSelection()); List<WSRoutingOrderV2> lineItems = selection.toList(); if (lineItems.size() == 0) { return; } if (!MessageDialog.openConfirm(this.shell, Messages.RoutingEngineV2BrowserMainPage_ConfirmTitle, Messages.RoutingEngineV2BrowserMainPage_ConfirmContent + (synchronously ? Messages.RoutingEngineV2BrowserMainPage_Text2 : Messages.RoutingEngineV2BrowserMainPage_Text3) + Messages.RoutingEngineV2BrowserMainPage_ConfirmContentA + lineItems.size() + Messages.RoutingEngineV2BrowserMainPage_B)) { return; } // Instantiate the Monitor with actual deletes ExecuteRoutingOrdersWithProgress diwp = new ExecuteRoutingOrdersWithProgress( (TMDMService) routingEngineV2BrowserMainPage.getAdapter(TMDMService.class), lineItems, this.shell); // run new ProgressMonitorDialog(this.shell).run(false, // fork true, // cancelable diwp); // refresh the search routingEngineV2BrowserMainPage.doSearch(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(shell, Messages._Error, Messages.bind(Messages.RoutingEngineV2BrowserMainPage_ErrorMsg4, e.getLocalizedMessage())); } }
From source file:com.amalto.workbench.widgets.RepositoryCheckTreeViewer.java
License:Open Source License
public RepositoryCheckTreeViewer(IStructuredSelection selection) { this.selection = selection; Object firstElement = selection.getFirstElement(); if (firstElement != null && firstElement instanceof TreeObject) { serverRoot = ((TreeObject) firstElement).getServerRoot(); }//w w w . ja v a 2s . com checkItems = selection.toList(); }
From source file:com.amazonaws.eclipse.explorer.s3.actions.S3ActionProvider.java
License:Apache License
@Override public void fillContextMenu(IMenuManager menu) { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); if (selection.size() == 1 && selection.toList().get(0) instanceof Bucket) { Bucket bucket = (Bucket) selection.toList().get(0); menu.add(new OpenBucketEditorAction(bucket.getName())); menu.add(new Separator()); }// w ww. j av a2s .c om boolean onlyBucketsSelected = true; for (Object obj : selection.toList()) { if (obj instanceof Bucket == false) { onlyBucketsSelected = false; break; } } menu.add(new CreateBucketAction()); if (onlyBucketsSelected) { menu.add(new DeleteBucketAction(selection.toList())); } }
From source file:com.android.ide.eclipse.adt.internal.assetstudio.CreateAssetSetWizard.java
License:Open Source License
private IProject guessProject(IStructuredSelection selection) { if (selection == null) { return null; }//from w w w . j av a2 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(AdtConstants.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:com.android.ide.eclipse.adt.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. j av a2 s . co m * 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(AdtConstants.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:com.android.ide.eclipse.adt.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. jav a 2 s .co m*/ * 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> * * @param selection The selection when the wizard was initiated. */ private void initializeFromSelection(IStructuredSelection selection) { if (selection == null) { return; } // 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(AndroidConstants.NATURE)) { 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; if (res.getType() == IResource.FOLDER) { wsFolderPath = res.getProjectRelativePath(); } else if (res.getType() == IResource.FILE) { 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; } } } // Now set the UI accordingly if (targetScore > 0) { mProject = targetProject; mProjectTextField.setText(targetProject != null ? targetProject.getName() : ""); //$NON-NLS-1$ mFileNameTextField.setText(targetFileName != null ? targetFileName : ""); //$NON-NLS-1$ mWsFolderPathTextField.setText(targetWsFolderPath != null ? targetWsFolderPath : ""); //$NON-NLS-1$ } }