Java Code Examples for org.eclipse.jface.viewers.IStructuredSelection

The following examples show how to use org.eclipse.jface.viewers.IStructuredSelection. These examples are extracted from open source projects.
Example 1
Project: eip-designer   File: InvocableEndpointPropertiesEditionPartImpl.java    License: 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 2
Project: eip-designer   File: ContentFilterPropertiesEditionPartForm.java    License: 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 3
/**
 * 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 4
Project: xtext-eclipse   File: OutlineTreeState.java    License: 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 5
Project: Eclipse-Postfix-Code-Completion   File: FatJarPackageWizard.java    License: 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 6
Project: translationstudio8   File: XmlConvertManagerDialog.java    License: 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 7
Project: xtext-eclipse   File: XbaseBreakpointDetailPaneFactory.java    License: 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 8
Project: eip-designer   File: RecipientListRouterPropertiesEditionPartImpl.java    License: 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 9
Project: tmxeditor8   File: PropertiesView.java    License: 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 10
Project: tmxeditor8   File: TmDbManagerDialog.java    License: 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 11
Project: neoscada   File: AbstractItemHandler.java    License: 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 12
Project: APICloud-Studio   File: MergeFileAssociationPreferencePage.java    License: 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 13
Project: tmxeditor8   File: LanguageCodesPreferencePage.java    License: 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 14
Project: APICloud-Studio   File: TeamAction.java    License: 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 15
Project: Eclipse-Postfix-Code-Completion   File: JavaCompareAction.java    License: 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 16
Project: Eclipse-Postfix-Code-Completion   File: JavaBrowsingPart.java    License: 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 17
Project: eip-designer   File: GatewayPropertiesEditionPartForm.java    License: 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 18
Project: gama   File: RevealInWorkspace.java    License: 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 19
Project: Eclipse-Postfix-Code-Completion   File: InferTypeArgumentsAction.java    License: 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 20
Project: Eclipse-Postfix-Code-Completion   File: RefactoringAvailabilityTester.java    License: 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 21
Project: tlaplus   File: ToolboxExplorer.java    License: 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 22
Project: n4js   File: N4JSProjectActionGroup.java    License: 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 23
Project: birt   File: CutAction.java    License: 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 24
Project: Eclipse-Postfix-Code-Completion   File: RenameTypeWizardSimilarElementsPage.java    License: 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 25
Project: M2Doc   File: GenconfEditorLauncher.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void open(IPath file) {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    final Shell shell = workbench.getActiveWorkbenchWindow().getShell();
    final ISelection selection = workbench.getActiveWorkbenchWindow().getSelectionService().getSelection();

    if (selection instanceof IStructuredSelection) {
        openNewGenerationWizard(workbench, shell, (IStructuredSelection) selection);
    }
}
 
Example 26
Project: eclipse-cs   File: SimpleFileSetsEditor.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void selectionChanged(SelectionChangedEvent event) {
  IStructuredSelection selection = (IStructuredSelection) event.getSelection();
  ICheckConfiguration config = (ICheckConfiguration) selection.getFirstElement();

  if (config != null) {
    mDefaultFileSet.setCheckConfig(config);
    mTxtConfigDescription
            .setText(config.getDescription() != null ? config.getDescription() : ""); //$NON-NLS-1$
  } else {
    mComboViewer.setSelection(new StructuredSelection(mComboViewer.getElementAt(0)));
  }

  mPropertyPage.getContainer().updateButtons();
}
 
Example 27
Project: Eclipse-Postfix-Code-Completion   File: GenerateNewConstructorUsingFieldsAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private IField[] getSelectedFields(IStructuredSelection selection) {
	List<?> elements= selection.toList();
	if (elements.size() > 0) {
		IField[] fields= new IField[elements.size()];
		ICompilationUnit unit= null;
		for (int index= 0; index < elements.size(); index++) {
			if (elements.get(index) instanceof IField) {
				IField field= (IField) elements.get(index);
				if (index == 0) {
					// remember the CU of the first element
					unit= field.getCompilationUnit();
					if (unit == null) {
						return null;
					}
				} else if (!unit.equals(field.getCompilationUnit())) {
					// all fields must be in the same CU
					return null;
				}
				try {
					final IType declaringType= field.getDeclaringType();
					if (declaringType.isInterface() || declaringType.isAnnotation() || declaringType.isAnonymous())
						return null;
				} catch (JavaModelException exception) {
					JavaPlugin.log(exception);
					return null;
				}
				fields[index]= field;
			} else {
				return null;
			}
		}
		return fields;
	}
	return null;
}
 
Example 28
Project: tmxeditor8   File: TermDbManagerDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 初始化树右键菜单 ;
 */
private void initTreePopMenu() {
	MenuManager menuManager = new MenuManager("");
	menuManager.add(new Action(Messages.getString("dialog.TermDbManagerDialog.deleteAction")) {
		@Override
		public void run() {
			ISelection selection = getTreeViewer().getSelection();
			if (selection.isEmpty()) {
				return;
			}
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
			Object obj = structuredSelection.getFirstElement();
			if (obj instanceof DatabaseModelBean) {
				List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(currDbType);
				configer.deleteServerById(((DatabaseModelBean) obj).getId());
				int i = currDbTypeServers.indexOf(obj);
				currDbTypeServers.remove(i);
				getTreeViewer().refresh();
				// selectSaveItem();
				// setLastSelectedServer(null);

				if (currDbTypeServers.size() != 0) {
					if (i > currDbTypeServers.size() - 1) {
						setLastSelectedServer(currDbTypeServers.get(i - 1).getId());
					} else {
						setLastSelectedServer(currDbTypeServers.get(i).getId());
					}
					initUI(false);
				} else {
					setLastSelectedServer(null);
					initUI(true);
				}
				selectSaveItem();

			}
		}
	});
	Tree tree = treeViewer.getTree();
	this.treePopMenu = menuManager.createContextMenu(tree);
}
 
Example 29
Project: tesb-studio-se   File: ServicesButtonPart.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void buttonSelected(SelectionEvent e) {
    RepositoryReviewDialog dialog = new RepositoryReviewDialog(getShell(), ERepositoryObjectType.METADATA,
            "SERVICES:OPERATION") {

        @Override
        protected boolean isSelectionValid(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() == 1) {
                return true;
            }
            return false;
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            return createDialogArea(parent, "org.talend.rcp.perspective");
        }
    };

    int open = dialog.open();
    if (open == Dialog.OK) {
        RepositoryNode result = dialog.getResult();
        if (result != null) {
            listener.serviceNodeSelected(result);
        }
    }
}
 
Example 30
Project: neoscada   File: VisualInterfaceModelWizard.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This just records the information.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public void init ( final IWorkbench workbench, final IStructuredSelection selection )
{
    this.workbench = workbench;
    this.selection = selection;
    setWindowTitle ( VisualInterfaceEditorPlugin.INSTANCE.getString ( "_UI_Wizard_label" ) ); //$NON-NLS-1$
    setDefaultPageImageDescriptor ( ExtendedImageRegistry.INSTANCE.getImageDescriptor ( VisualInterfaceEditorPlugin.INSTANCE.getImage ( "full/wizban/NewVisualInterface.png" ) ) ); //$NON-NLS-1$
}
 
Example 31
Project: gwt-eclipse-plugin   File: AbstractOpenWizardAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private IStructuredSelection evaluateCurrentSelection() {
  IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow();
  if (window != null) {
    ISelection localSelection = window.getSelectionService().getSelection();
    if (localSelection instanceof IStructuredSelection) {
      return (IStructuredSelection) localSelection;
    }
  }
  return StructuredSelection.EMPTY;
}
 
Example 32
Project: Eclipse-Postfix-Code-Completion   File: UserLibraryPreferencePage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private IPath getWorkbenchWindowSelection() {
	IWorkbenchWindow window= fWorkbench.getActiveWorkbenchWindow();
	if (window != null) {
		ISelection selection= window.getSelectionService().getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection= (IStructuredSelection) selection;
			Object element= structuredSelection.getFirstElement();
			if (element != null) {
				Object resource= Platform.getAdapterManager().getAdapter(element, IResource.class);
				if (resource != null) {
					return ((IResource) resource).getFullPath();
				}
				if (structuredSelection instanceof ITreeSelection) {
					TreePath treePath= ((ITreeSelection) structuredSelection).getPaths()[0];
					while ((treePath = treePath.getParentPath()) != null) {
						element= treePath.getLastSegment();
						resource= Platform.getAdapterManager().getAdapter(element, IResource.class);
						if (resource != null) {
							return ((IResource) resource).getFullPath();
						}
					}
				}
			}
			
		}
	}
	return null;
}
 
Example 33
Project: tmxeditor8   File: WorkspaceDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获得当前选择的 container ;
 */
private void getSelectedContainer() {
	Object obj = ((IStructuredSelection) wsTreeViewer.getSelection()).getFirstElement();

	if (obj instanceof IContainer) {
		wsContainer = (IContainer) obj;
	} else if (obj instanceof IFile) {
		wsContainer = ((IFile) obj).getParent();
	}
}
 
Example 34
Project: translationstudio8   File: ResourceDragAdapterAssistant.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IResource[] getSelectedResources(IStructuredSelection aSelection) {
	Set resources = new LinkedHashSet();
	IResource resource = null;
	for (Iterator iter = aSelection.iterator(); iter.hasNext();) {
		Object selected = iter.next();
		resource = adaptToResource(selected);
		if (resource != null) {
			resources.add(resource);
	}
	}
	return (IResource[]) resources.toArray(new IResource[resources.size()]);
}
 
Example 35
Project: xtext-eclipse   File: WizardSelectImportedEPackagePage.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public EClass getRootElementClass() {
	ISelection selection = rootElementComboViewer.getSelection();
	if (selection instanceof IStructuredSelection) {
		return (EClass) ((IStructuredSelection) selection).getFirstElement();
	}
	return null;
}
 
Example 36
Project: tlaplus   File: StopLaunchHandler.java    License: MIT License 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException
{
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !((IStructuredSelection) selection).isEmpty())
    {
        IStructuredSelection structSelection = ((IStructuredSelection) selection);

        Iterator modelIterator = structSelection.iterator();
        while (modelIterator.hasNext())
        {
            Object element = modelIterator.next();
            if (element instanceof Model)
            {
            	Model model = (Model) element;
                if (model.isRunning())
                {
                    Job[] runningSpecJobs = Job.getJobManager().find(model.getLaunchConfiguration());
                    for (int i = 0; i < runningSpecJobs.length; i++)
                    {
                        // send cancellations to all jobs...
                        runningSpecJobs[i].cancel();
                    }
                }
            }
        }
    }
    return null;
}
 
Example 37
Project: Eclipse-Postfix-Code-Completion   File: CreateJavadocActionDelegate.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void run(IAction action) {
	if (fCurrentSelection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) fCurrentSelection;
		Object first= structuredSelection.getFirstElement();
		if (first instanceof IFile) {
			JavadocWizard wizard= new JavadocWizard((IFile) first);
			JavadocWizard.openJavadocWizard(wizard, fCurrentShell, structuredSelection);
		}
	}
}
 
Example 38
Project: thym   File: PluginUninstallAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private IStructuredSelection getSelection() {
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		ISelection selection = window.getSelectionService().getSelection();
		if (selection instanceof IStructuredSelection)
			return (IStructuredSelection) selection;
	}
	return StructuredSelection.EMPTY;
}
 
Example 39
Project: codewind-eclipse   File: AddConnectionAction.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void selectionChanged(IStructuredSelection sel) {
	if (sel.size() == 1) {
		Object obj = sel.getFirstElement();
		if (obj instanceof CodewindManager) {
			setEnabled(true);
			return;
		}
	}
	setEnabled(false);
}
 
Example 40
Project: Eclipse-Postfix-Code-Completion   File: MoveInstanceMethodAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		Assert.isTrue(RefactoringAvailabilityTester.isMoveMethodAvailable(selection));
		IMethod method= getSingleSelectedMethod(selection);
		Assert.isNotNull(method);
		if (!ActionUtil.isEditable(fEditor, getShell(), method))
			return;
		RefactoringExecutionStarter.startMoveMethodRefactoring(method, getShell());
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), RefactoringMessages.MoveInstanceMethodAction_dialog_title, RefactoringMessages.MoveInstanceMethodAction_unexpected_exception);
	}
	}