org.eclipse.jface.viewers.IStructuredSelection Java Examples

The following examples show how to use org.eclipse.jface.viewers.IStructuredSelection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TeamAction.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void selectionChanged(IAction action, ISelection sel) {
	if (sel instanceof IStructuredSelection) {
		this.selection = (IStructuredSelection) sel;
		if (action != null) {
			setActionEnablement(action);
		}
	}
	if (sel instanceof ITextSelection){
			IEditorPart part = getTargetPage().getActiveEditor();
			if (part != null) {
				IEditorInput input = part.getEditorInput();
				IResource r = (IResource) input.getAdapter(IResource.class);
				if (r != null) {
					switch(r.getType()){
						case IResource.FILE:
							this.selection = new StructuredSelection(r);
							if (action != null) {
								setActionEnablement(action);
							}
						break;
					}
				}	//	set selection to current editor file;
			}
	}
}
 
Example #2
Source File: CutAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected DeleteAction createDeleteAction( final Object objects )
{
	return new DeleteAction( objects ) {

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.birt.report.designer.internal.ui.views.actions.DeleteAction#getTransactionLabel()
		 */
		protected String getTransactionLabel( )
		{
			if ( objects instanceof IStructuredSelection )
			{
				return Messages.getString( "CutAction.trans" ); //$NON-NLS-1$
			}
			return DEFAULT_TEXT + " " + DEUtil.getDisplayLabel( objects ); //$NON-NLS-1$
		}
	};
}
 
Example #3
Source File: RevealInWorkspace.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
	final IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);
	if (sel.isEmpty()) { return null; }
	final IWorkbenchPart part = HandlerUtil.getActivePart(event);
	if (!(part instanceof GamaNavigator)) { return null; }
	final GamaNavigator nav = (GamaNavigator) part;
	final List<Object> selection = sel.toList();
	final List<WrappedFile> newSelection = new ArrayList<>();
	for (final Object o : selection) {
		if (o instanceof LinkedFile) {
			newSelection.add(((LinkedFile) o).getTarget());
		}
	}
	if (newSelection.isEmpty()) { return null; }
	nav.selectReveal(new StructuredSelection(newSelection));
	return this;
}
 
Example #4
Source File: N4JSProjectActionGroup.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void performSelectionChanged(final IStructuredSelection structuredSelection) {
	final Object[] array = structuredSelection.toArray();
	final ArrayList<IProject> openProjects = new ArrayList<>();
	final int selectionStatus = evaluateSelection(array, openProjects);
	final StructuredSelection sel = new StructuredSelection(openProjects);

	// If only projects are selected, disable this action group, as all of
	// the project-related contributions will be provided by default action providers
	enableContribution = (selectionStatus & NON_PROJECT_SELECTED) != 0;

	openAction.setEnabled(hasClosedProjectsInWorkspace());
	enableOpenInContextMenu = (selectionStatus & CLOSED_PROJECTS_SELECTED) != 0
			|| (selectionStatus == 0 && array.length == 0 && hasClosedProjectsInWorkspace());
	closeAction.selectionChanged(sel);
	closeUnrelatedAction.selectionChanged(sel);
}
 
Example #5
Source File: InferTypeArgumentsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	IJavaElement[] elements= getSelectedElements(selection);
	try {
		if (! ActionUtil.areProcessable(getShell(), elements))
			return;

		if (RefactoringAvailabilityTester.isInferTypeArgumentsAvailable(elements)) {
			RefactoringExecutionStarter.startInferTypeArgumentsRefactoring(elements, getShell());
		} else {
			MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.InferTypeArgumentsAction_unavailable);
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception);
	}
}
 
Example #6
Source File: CheckConfigurationConfigureDialog.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Opens the module editor for the current selection.
 *
 * @param selection
 *          the selection
 */
private void openModule(ISelection selection) {

  Module m = (Module) ((IStructuredSelection) selection).getFirstElement();
  if (m != null) {

    Module workingCopy = m.clone();

    RuleConfigurationEditDialog dialog = new RuleConfigurationEditDialog(getShell(),
            workingCopy, !mConfigurable,
            Messages.CheckConfigurationConfigureDialog_titleModuleConfigEditor);
    if (Window.OK == dialog.open() && mConfigurable) {
      mModules.set(mModules.indexOf(m), workingCopy);
      mIsDirty = true;
      mTableViewer.refresh(true);
      refreshTableViewerState();
    }
  }
}
 
Example #7
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isPullUpAvailable(final IStructuredSelection selection) throws JavaModelException {
	if (!selection.isEmpty()) {
		if (selection.size() == 1) {
			if (selection.getFirstElement() instanceof ICompilationUnit)
				return true; // Do not force opening
			final IType type= getSingleSelectedType(selection);
			if (type != null)
				return Checks.isAvailable(type) && isPullUpAvailable(new IType[] { type});
		}
		for (final Iterator<?> iterator= selection.iterator(); iterator.hasNext();) {
			if (!(iterator.next() instanceof IMember))
				return false;
		}
		final Set<IMember> members= new HashSet<IMember>();
		@SuppressWarnings("unchecked")
		List<IMember> selectionList= (List<IMember>) (List<?>) Arrays.asList(selection.toArray());
		members.addAll(selectionList);
		return isPullUpAvailable(members.toArray(new IMember[members.size()]));
	}
	return false;
}
 
Example #8
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void saveSelectionState(IMemento memento) {
	Object elements[]= ((IStructuredSelection) fViewer.getSelection()).toArray();
	if (elements.length > 0) {
		IMemento selectionMem= memento.createChild(TAG_SELECTED_ELEMENTS);
		for (int i= 0; i < elements.length; i++) {
			IMemento elementMem= selectionMem.createChild(TAG_SELECTED_ELEMENT);
			Object o= elements[i];
			if (o instanceof IJavaElement)
				elementMem.putString(TAG_SELECTED_ELEMENT_PATH, ((IJavaElement) elements[i]).getHandleIdentifier());
			else if (o instanceof LogicalPackage) {
				IPackageFragment[] packages=((LogicalPackage)o).getFragments();
				for (int j= 0; j < packages.length; j++) {
					IMemento packageMem= elementMem.createChild(TAG_LOGICAL_PACKAGE);
					packageMem.putString(TAG_SELECTED_ELEMENT_PATH, packages[j].getHandleIdentifier());
				}
			}
		}
	}
}
 
Example #9
Source File: ContentFilterPropertiesEditionPartForm.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
protected void addToChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(toChannels.getInput(), toChannelsFilters, toChannelsBusinessFilters,
	"toChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ContentFilterPropertiesEditionPartForm.this, EipViewsRepository.ContentFilter.Properties.toChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			toChannels.refresh();
		}
	};
	dialog.open();
}
 
Example #10
Source File: JavaCompareAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean isEnabled(ISelection selection) {
	if (selection instanceof IStructuredSelection) {
		Object[] sel= ((IStructuredSelection) selection).toArray();
		if (sel.length == 2) {
			for (int i= 0; i < 2; i++) {
				Object o= sel[i];
				if (!(o instanceof ISourceReference))
					return false;
			}
			fLeft= (ISourceReference) sel[0];
			fRight= (ISourceReference) sel[1];
			return true;
		}
	}
	return false;
}
 
Example #11
Source File: GatewayPropertiesEditionPartForm.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
protected void addFromChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(fromChannels.getInput(), fromChannelsFilters, fromChannelsBusinessFilters,
	"fromChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(GatewayPropertiesEditionPartForm.this, EipViewsRepository.Gateway.Properties.fromChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			fromChannels.refresh();
		}
	};
	dialog.open();
}
 
Example #12
Source File: ToolboxExplorer.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Open on double-click
 */
protected void handleDoubleClick(DoubleClickEvent anEvent)
{
    super.handleDoubleClick(anEvent);
    // open the model
    if (anEvent.getSelection() instanceof IStructuredSelection) {
    	IStructuredSelection iss = (IStructuredSelection) anEvent.getSelection();
    	Object firstElement = iss.getFirstElement();
    	if (firstElement instanceof Module) {
    		final Map<String, String> parameters = new HashMap<String, String>();
    		parameters.put(OpenModuleHandler.PARAM_MODULE, ((Module) firstElement).getModuleName());
UIHelper.runCommand(OpenModuleHandler.COMMAND_ID, parameters);
    	} else if (firstElement instanceof IGroup) {
    		// No-Op
    	} else if (firstElement instanceof Spec && ((Spec) firstElement).isCurrentSpec()) {
    		// No-op, do not re-open an open spec again.
    	} else {
    		UIHelper.runCommand(ToolboxExplorer.COMMAND_ID, new HashMap<String, String>());
    	}
    }
}
 
Example #13
Source File: OutlineTreeState.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected Set<IOutlineNode> getSelectedNodes(final TreeViewer treeViewer) {
	DisplayRunHelper.runSyncInDisplayThread(new Runnable() {
		@Override
		public void run() {
			selectedNodes = Sets.newHashSet();
			ISelection selection = treeViewer.getSelection();
			if (selection instanceof IStructuredSelection) {
				for (Iterator<?> selectionIter = ((IStructuredSelection) selection).iterator(); selectionIter
						.hasNext();) {
					Object selectedElement = selectionIter.next();
					if (!(selectedElement instanceof IOutlineNode))
						LOG.error("Content outline contains illegal node " + selectedElement);
					else
						selectedNodes.add((IOutlineNode) selectedElement);
				}
			}
		}
	});
	return selectedNodes;
}
 
Example #14
Source File: FatJarPackageWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return all java projects which contain the selected elements in the active workbench window
 */
protected IStructuredSelection getSelectedJavaProjects() {
	ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection();
	if (currentSelection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection;
		HashSet<IJavaProject> selectedElements= new HashSet<IJavaProject>();
		Iterator<?> iter= structuredSelection.iterator();
		while (iter.hasNext()) {
			Object selectedElement= iter.next();
			if (selectedElement instanceof IJavaElement) {
				IJavaProject javaProject= ((IJavaElement) selectedElement).getJavaProject();
				if (javaProject != null)
					selectedElements.add(javaProject);
			}
		}
		return new StructuredSelection(selectedElements);
	} else
		return StructuredSelection.EMPTY;
}
 
Example #15
Source File: XmlConvertManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 编辑选中的元素 ;
 */
protected void editElement() {
	ISelection selection = tableViewer.getSelection();
	if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
		@SuppressWarnings("unchecked")
		Iterator<ElementBean> iter = structuredSelection.iterator();
		ElementBean bean = iter.next();

		AddOrEditElementOfXmlConvertDialog dialog = new AddOrEditElementOfXmlConvertDialog(getShell(), false,
				elementsList);
		dialog.create();
		dialog.setInitEditData(bean);
		int result = dialog.open();
		if (result == IDialogConstants.OK_ID) {
			refreshTable(dialog.getCurrentElement());
		}
	} else {
		MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle2"),
				Messages.getString("dialogs.XmlConvertManagerDialog.msg3"));
	}
}
 
Example #16
Source File: LanguageCodesPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 根据当前选择的语言,更新数字、货币等的显示示例
 * @param selection
 *            ;
 */
protected void refreshFormatControls(IStructuredSelection selection) {
	Object firstSelected = selection.getFirstElement();
	if (firstSelected instanceof Language) {
		Language language = (Language) firstSelected;
		digitalValue.setText(language.getName());
		digitalValue.setToolTipText(language.getName());

		currencyValue.setText(language.getName());
		currencyValue.setToolTipText(language.getName());

		timeValue.setText(language.getName());
		timeValue.setToolTipText(language.getName());

		shortDateValue.setText(language.getName());
		shortDateValue.setToolTipText(language.getName());

		longDateValue.setText(language.getName());
		longDateValue.setToolTipText(language.getName());
	}
}
 
Example #17
Source File: XbaseBreakpointDetailPaneFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Set<String> getDetailPaneTypes(IStructuredSelection selection) {
	prioritizer.prioritizeXbaseOverJdt();
	if (selection.size() == 1) {
		Object selectedElement = selection.getFirstElement();
		if (selectedElement instanceof IBreakpoint) {
			IBreakpoint b = (IBreakpoint) selectedElement;
			try {
				Object sourceUri = b.getMarker().getAttribute(StratumBreakpointAdapterFactory.ORG_ECLIPSE_XTEXT_XBASE_SOURCE_URI);
				if (sourceUri != null) {
					return Collections.singleton(XBASE_DETAIL_PANE);
				}
			} catch (CoreException e) {}
		}
	}
	return Collections.emptySet();
}
 
Example #18
Source File: RecipientListRouterPropertiesEditionPartImpl.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
protected void addFromChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(fromChannels.getInput(), fromChannelsFilters, fromChannelsBusinessFilters,
	"fromChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(RecipientListRouterPropertiesEditionPartImpl.this, EipViewsRepository.RecipientListRouter.Properties.fromChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			fromChannels.refresh();
		}
	};
	dialog.open();
}
 
Example #19
Source File: PropertiesView.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
	if (part == null || selection == null) {
		return;
	}
	if (!(part instanceof TmxEditorViewer)) {
		return;
	}
	if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
		return;
	}
	// tgtLangcodeInTmxEditor = TmxEditorViewer.getInstance().getTmxEditor().getTgtLang();
	StructuredSelection struct = (StructuredSelection) selection;
	Object obj = struct.getFirstElement();
	if (obj instanceof TmxEditorSelection) {
		currentSelected = (TmxEditorSelection) obj;
		tableViewerManager.get(TU_ATTRS).setInput(new TableViewerInput(TU_ATTRS, currentSelected));
		tableViewerManager.get(TUV_ATTRS).setInput(new TableViewerInput(TUV_ATTRS, currentSelected));
		tableViewerManager.get(TU_NODE_NOTE).setInput(null);
		tableViewerManager.get(TU_NODE_NOTE).setInput(new TableViewerInput(TU_NODE_NOTE, currentSelected));
		tableViewerManager.get(TU_NODE_PROPS).setInput(new TableViewerInput(TU_NODE_PROPS, currentSelected));
		compostie.layout();
		scrolledComposite.setMinSize(compostie.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	}
}
 
Example #20
Source File: TmDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 当使用该对话框作为数据库选择时 ;
 */
private void executeSelectDatabase() {
	ISelection selection = getDbTableViewer().getSelection();
	if (selection.isEmpty()) {
		return;
	}
	hasSelected = new HashMap<DatabaseModelBean, String>();
	IStructuredSelection structuredSelection = (IStructuredSelection) selection;

	Iterator<?> it = structuredSelection.iterator();
	while (it.hasNext()) {
		DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) it.next();
		DatabaseModelBean dbModelBean = new DatabaseModelBean();
		currServer.copyToOtherIntance(dbModelBean);
		dbModelBean.setDbName(dbBean.getDbName());
		hasSelected.put(dbModelBean, dbBean.getLangs());
	}
}
 
Example #21
Source File: AbstractItemHandler.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get all items from the selection
 *
 * @return a data of all selected items
 */
protected Collection<Item> getItems ()
{
    final Collection<Item> result = new LinkedList<Item> ();

    final IStructuredSelection sel = getSelection ();

    if ( sel != null && !sel.isEmpty () )
    {
        for ( final Iterator<?> i = sel.iterator (); i.hasNext (); )
        {
            final Object o = i.next ();

            final Item holder = AdapterHelper.adapt ( o, Item.class );
            if ( holder != null )
            {
                result.add ( holder );
            }
        }
    }

    return result;
}
 
Example #22
Source File: InvocableEndpointPropertiesEditionPartImpl.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
protected void addToChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(toChannels.getInput(), toChannelsFilters, toChannelsBusinessFilters,
	"toChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(InvocableEndpointPropertiesEditionPartImpl.this, EipViewsRepository.InvocableEndpoint.Properties.toChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			toChannels.refresh();
		}
	};
	dialog.open();
}
 
Example #23
Source File: RenameTypeWizardSimilarElementsPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void editCurrentElement() {
	IStructuredSelection selection= (IStructuredSelection) fTreeViewer.getSelection();
	if ( (selection != null) && isSimilarElement(selection.getFirstElement())) {
		IJavaElement element= (IJavaElement) selection.getFirstElement();
		String newName= fSimilarElementsToNewName.get(element);
		if (newName == null)
			return;
		EditElementDialog dialog= new EditElementDialog(getShell(), element, newName);
		if (dialog.open() == Window.OK) {
			String changedName= dialog.getNewName();
			if (!changedName.equals(newName)) {
				fSimilarElementsToNewName.put(element, changedName);
				fTreeViewer.update(element, null);
			}
		}
	}
}
 
Example #24
Source File: MergeFileAssociationPreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void removeFileType() {
	associationsUpdated = true;
	ArrayList associationsList = new ArrayList();
	for (int i = 0; i < mergeFileAssociations.length; i++) associationsList.add(mergeFileAssociations[i]);
	IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
	Iterator iter = selection.iterator();
	while (iter.hasNext()) {
		associationsList.remove(iter.next());
	}
	mergeFileAssociations = new MergeFileAssociation[associationsList.size()];
	associationsList.toArray(mergeFileAssociations);
	viewer.refresh();
	builtInMergeRadioButton.setSelection(false);
	externalMergeRadioButton.setSelection(false);
	customMergeRadioButton.setSelection(false);
	customProgramLocationCombo.setText(""); //$NON-NLS-1$
	customProgramParametersText.setText(""); //$NON-NLS-1$
}
 
Example #25
Source File: UseSupertypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		if (RefactoringAvailabilityTester.isUseSuperTypeAvailable(selection)) {
			IType singleSelectedType= getSingleSelectedType(selection);
			if (! ActionUtil.isEditable(getShell(), singleSelectedType))
				return;
			RefactoringExecutionStarter.startUseSupertypeRefactoring(singleSelectedType, getShell());
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception);
	}
}
 
Example #26
Source File: TableComboViewerSnippet1.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void selectionChanged(SelectionChangedEvent event) {
	listenerGroup.setText("Listener Results - (" + text + ")");

	Model model = (Model) ((IStructuredSelection) event.getSelection()).getFirstElement();
	toggleSelection(model);

	String selectionText = getSelectionText();
	listenerResults.setText(selectionText);

	TableComboViewer viewer = ((TableComboViewer) event.getSource());
	viewer.getTableCombo().setText(selectionText);
	viewer.update(model, null);
}
 
Example #27
Source File: GlobalizeEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example #28
Source File: ExportHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IStructuredSelection currentSelection = getSelectionToUse(event);
	IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

	IExportWizard wizard = getExportWizard(event);
	wizard.init(window.getWorkbench(), currentSelection);

	TSWizardDialog dialog = new TSWizardDialog(window.getShell(), wizard);
	dialog.create();
	dialog.open();
	return null;
}
 
Example #29
Source File: ExternalizeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private List<?> getSelectedTableEntries() {
	ISelection sel= fTableViewer.getSelection();
	if (sel instanceof IStructuredSelection)
		return((IStructuredSelection) sel).toList();
	else
		return Collections.EMPTY_LIST;
}
 
Example #30
Source File: DockerBuildHandler.java    From doclipser with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getCurrentSelection(event);
    if (sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof IFile) {
            System.out.println("Selected file: " + ((IFile)selected).getName());
        }
    }
    
    return null;
}