List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:com.trivadis.loganalysis.ui.internal.view.ProfilesView.java
License:Open Source License
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) { if (selection instanceof StructuredSelection) { final StructuredSelection ss = (StructuredSelection) selection; if (ss.getFirstElement() instanceof IProfile) { final IProfile profile = (IProfile) ss.getFirstElement(); uiContext.setSelectedProfile(profile); }//from w w w. j a va2 s .c o m if (ss.getFirstElement() instanceof IConfiguration) { final IConfiguration configuration = (IConfiguration) ss.getFirstElement(); uiContext.setSelectedConfiguration(configuration); } } }
From source file:com.trivadis.loganalysis.ui.internal.wizard.NewProfileWizardPage.java
License:Open Source License
public IConfiguration getSelectedConfiguration() { IConfiguration retVal = null;//from ww w . j a va 2 s. com if (viewer.getSelection() instanceof StructuredSelection) { final StructuredSelection ss = (StructuredSelection) viewer.getSelection(); retVal = (IConfiguration) ss.getFirstElement(); } return retVal; }
From source file:com.twinsoft.convertigo.eclipse.PrintDialog.java
License:Open Source License
public PrintDialog(Shell parentShell) { super(parentShell); try {/*from www . j a v a2 s. c o m*/ StructuredSelection selection = (StructuredSelection) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getSelection(); Object element = selection.getFirstElement(); if (element == null) { MessageDialog.openInformation(parentShell, "Error", "Please select a convertigo object before printing"); } else if (element instanceof UnloadedProjectTreeObject) { MessageDialog.openInformation(parentShell, "Error", "Please select an opened project or an opened project item before printing"); } else if (element instanceof ProjectTreeObject) { ProjectTreeObject dboto = (ProjectTreeObject) element; project = dboto.getObject(); } else { DatabaseObjectTreeObject dboto = (DatabaseObjectTreeObject) element; DatabaseObject dbo = dboto.getObject(); project = dbo.getProject(); } } catch (Exception e) { MessageDialog.openInformation(parentShell, "Error", "Wrong object selectid, please select a Convertigo object before printing"); } }
From source file:com.vectrace.MercurialEclipse.history.ChangedPathsPage.java
License:Open Source License
private void contributeActions() { Action toggleShowComments = new Action(Messages.getString("HistoryView.showComments"), //$NON-NLS-1$ MercurialEclipsePlugin.getImageDescriptor(IMG_COMMENTS)) { @Override/*from www.jav a 2s.c o m*/ public void run() { showComments = isChecked(); setViewerVisibility(); store.setValue(PREF_SHOW_COMMENTS, showComments); } }; toggleShowComments.setChecked(showComments); Action toggleShowDiffs = new Action(Messages // TODO create new text & image .getString("HistoryView.showDiffs"), //$NON-NLS-1$ MercurialEclipsePlugin.getImageDescriptor(IMG_DIFFS)) { @Override public void run() { showDiffs = isChecked(); setViewerVisibility(); store.setValue(PREF_SHOW_DIFFS, showDiffs); } }; toggleShowDiffs.setChecked(showDiffs); // Toggle wrap comments action Action toggleWrapCommentsAction = new Action(Messages.getString("HistoryView.wrapComments")) { @Override public void run() { wrapCommentsText = isChecked(); setViewerVisibility(); store.setValue(PREF_WRAP_COMMENTS, wrapCommentsText); } }; toggleWrapCommentsAction.setChecked(wrapCommentsText); // Toggle path visible action Action toggleShowAffectedPathsAction = new Action(Messages.getString("HistoryView.showAffectedPaths"), //$NON-NLS-1$ MercurialEclipsePlugin.getImageDescriptor(IMG_AFFECTED_PATHS_FLAT_MODE)) { @Override public void run() { showAffectedPaths = isChecked(); setViewerVisibility(); store.setValue(PREF_SHOW_PATHS, showAffectedPaths); } }; toggleShowAffectedPathsAction.setChecked(showAffectedPaths); IHistoryPageSite parentSite = getHistoryPageSite(); IPageSite pageSite = parentSite.getWorkbenchPageSite(); IActionBars actionBars = pageSite.getActionBars(); // Contribute toggle text visible to the toolbar drop-down IMenuManager actionBarsMenu = actionBars.getMenuManager(); actionBarsMenu.add(toggleWrapCommentsAction); actionBarsMenu.add(new Separator()); actionBarsMenu.add(toggleShowComments); actionBarsMenu.add(toggleShowAffectedPathsAction); actionBarsMenu.add(toggleShowDiffs); actionBarsMenu.add(new Separator()); for (int i = 0; i < toggleAffectedPathsLayoutActions.length; i++) { actionBarsMenu.add(toggleAffectedPathsLayoutActions[i]); } // Create the local tool bar IToolBarManager tbm = actionBars.getToolBarManager(); tbm.add(toggleShowComments); tbm.add(toggleShowAffectedPathsAction); tbm.add(toggleShowDiffs); tbm.update(false); actionBars.updateActionBars(); final BaseSelectionListenerAction openAction = page.getOpenAction(); final BaseSelectionListenerAction openEditorAction = page.getOpenEditorAction(); final BaseSelectionListenerAction compareWithCurrent = page.getCompareWithCurrentAction(); final BaseSelectionListenerAction compareWithPrevious = page.getCompareWithPreviousAction(); final BaseSelectionListenerAction compareWithOther = page.getCompareWithOtherAction(); final BaseSelectionListenerAction actionRevert = page.getRevertAction(); final BaseSelectionListenerAction focusOnSelected = page.getFocusOnSelectedFileAction(); changePathsViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { FileStatus fileStatus = (FileStatus) ((IStructuredSelection) event.getSelection()) .getFirstElement(); MercurialRevision derived = getDerivedRevision(fileStatus, getCurrentRevision()); if (derived == null) { return; } StructuredSelection selection = new StructuredSelection(new Object[] { derived, fileStatus }); compareWithPrevious.selectionChanged(selection); compareWithPrevious.run(); } }); // Contribute actions to popup menu final MenuManager menuMgr = new MenuManager(); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menuMgr1) { IStructuredSelection selection = (IStructuredSelection) changePathsViewer.getSelection(); if (selection.isEmpty()) { return; } FileStatus fileStatus = (FileStatus) selection.getFirstElement(); MercurialRevision base = getCurrentRevision(); MercurialRevision derived = getDerivedRevision(fileStatus, base); if (derived == null) { // XXX currently files outside workspace are not supported... return; } selection = new StructuredSelection(derived); openAction.selectionChanged(selection); focusOnSelected.selectionChanged(selection); openEditorAction.selectionChanged(selection); compareWithCurrent.selectionChanged(selection); compareWithOther.selectionChanged(selection); selection = new StructuredSelection(new Object[] { derived, fileStatus }); compareWithPrevious.selectionChanged(selection); menuMgr1.add(openAction); menuMgr1.add(openEditorAction); menuMgr1.add(focusOnSelected); menuMgr1.add(new Separator(IWorkbenchActionConstants.GROUP_FILE)); menuMgr1.add(compareWithCurrent); menuMgr1.add(compareWithPrevious); menuMgr1.add(compareWithOther); menuMgr1.add(new Separator()); selection = new StructuredSelection(new Object[] { derived }); actionRevert.selectionChanged(selection); menuMgr1.add(actionRevert); menuMgr1.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); } }); menuMgr.setRemoveAllWhenShown(true); changePathsViewer.getTable().setMenu(menuMgr.createContextMenu(changePathsViewer.getTable())); }
From source file:com.versant.core.jdo.tools.eclipse.Utils.java
License:Open Source License
public static IProject findSelectedProject(ISelection iSelection) { IProject proj = null;//from w w w . j a v a 2 s. c o m if (iSelection instanceof StructuredSelection) { StructuredSelection sS = (StructuredSelection) iSelection; Object el = sS.getFirstElement(); if (el instanceof IJavaProject) { proj = ((IJavaProject) el).getProject(); } else if (el instanceof IResource) { proj = ((IResource) el).getProject(); } else if (el instanceof IJavaElement) { proj = ((IJavaElement) el).getJavaProject().getProject(); } } return proj; }
From source file:com.versant.core.jdo.tools.plugins.eclipse.popup.actions.AddPersistentClass.java
License:Open Source License
public void setISelection(ISelection iSelection) { className = null;//w ww.ja v a2s . c o m iProject = null; IProject proj = null; if (iSelection instanceof StructuredSelection) { StructuredSelection sS = (StructuredSelection) iSelection; Object el = sS.getFirstElement(); if (el instanceof IJavaElement) { IJavaElement javaElement = ((IJavaElement) el); proj = javaElement.getJavaProject().getProject(); IType selectedClass = (IType) javaElement.getAncestor(IJavaElement.TYPE); if (selectedClass != null) { className = selectedClass.getFullyQualifiedName(); } } } if (proj != null) { iProject = proj; } }
From source file:com.versant.core.jdo.tools.plugins.eclipse.popup.actions.TogglePersistentField.java
License:Open Source License
public void setISelection(ISelection iSelection) { fieldName = null;//from w w w . ja v a 2s. c o m className = null; iProject = null; IProject proj = null; if (iSelection instanceof StructuredSelection) { StructuredSelection sS = (StructuredSelection) iSelection; Object el = sS.getFirstElement(); if (el instanceof IJavaElement) { IJavaElement javaElement = ((IJavaElement) el); proj = javaElement.getJavaProject().getProject(); IType selectedClass = (IType) javaElement.getAncestor(IJavaElement.TYPE); if (selectedClass != null) { className = selectedClass.getFullyQualifiedName(); } IField selectedField = (IField) javaElement.getAncestor(IJavaElement.FIELD); if (selectedField != null) { fieldName = selectedField.getElementName(); } } } if (proj != null) { iProject = proj; } }
From source file:com.versant.core.jdo.tools.plugins.eclipse.VOAProjectControler.java
License:Open Source License
public String getClassName(ISelection iSelection) { if (iSelection instanceof StructuredSelection) { StructuredSelection sS = (StructuredSelection) iSelection; Object el = sS.getFirstElement(); if (el instanceof IJavaElement) { IJavaElement javaElement = ((IJavaElement) el); IType type = (IType) javaElement.getAncestor(IJavaElement.TYPE); if (type != null) { return type.getFullyQualifiedName(); }//from w w w. j a va 2s .c o m } } return null; }
From source file:com.versant.core.jdo.tools.plugins.eclipse.VOAProjectControler.java
License:Open Source License
public String getFieldName(ISelection iSelection) { if (iSelection instanceof StructuredSelection) { StructuredSelection sS = (StructuredSelection) iSelection; Object el = sS.getFirstElement(); if (el instanceof IJavaElement) { IJavaElement javaElement = ((IJavaElement) el); IType type = (IType) javaElement.getAncestor(IJavaElement.FIELD); if (type != null) { return type.getFullyQualifiedName(); }//from www . j a va 2s . c o m } } return null; }
From source file:com.wdev91.eclipse.copyright.preferences.CopyrightPreferencePage.java
License:Open Source License
/** * Returns the current Copyright object selected in the list. * /*from w w w. jav a 2 s . co m*/ * @return Selected Copyright, or null if none. */ protected Copyright getSelection() { StructuredSelection selection = (StructuredSelection) copyrightsList.getSelection(); return (Copyright) selection.getFirstElement(); }