Java Code Examples for org.eclipse.swt.widgets.Tree.getSelection()

The following are Jave code examples for showing how to use getSelection() of the org.eclipse.swt.widgets.Tree class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: bdf2   File: SelectClassPage.java   Source Code and License Vote up 7 votes
private void removeSelectedPackage(SelectionEvent e, TreeViewer treeViewer) {
	Tree tree = getTree(e);
	if (tree == null) {
		return;
	}
	TreeItem[] selection = tree.getSelection();
	if (selection != null && selection.length > 0) {
		for (TreeItem item : selection) {
			TreeItem parent = item.getParentItem();
			if (parent == null) {
				removePackage(item);
				updatePageComplete(tree);
			} else {
				alert("请选择要删除的包!");
			}
		}
	} else {
		alert("请选择要删除的包!");
	}
}
 
Example 2
Project: logbook   File: TreeToClipboardAdapter.java   Source Code and License Vote up 6 votes
/**
 * ツリーの選択されている部分をヘッダー付きでクリップボードにコピーします
 * 
 * @param header ヘッダー
 * @param tree ツリー
 */
public static void copyTree(String[] header, Tree tree) {
    TreeItem[] treeItems = tree.getSelection();
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.join(header, "\t"));
    sb.append("\r\n");
    for (TreeItem column : treeItems) {
        String[] columns = new String[header.length];
        for (int i = 0; i < header.length; i++) {
            columns[i] = column.getText(i);
        }
        sb.append(StringUtils.join(columns, "\t"));
        sb.append("\r\n");
    }
    Clipboard clipboard = new Clipboard(Display.getDefault());
    clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
 
Example 3
Project: scouter   File: MainProcessor.java   Source Code and License Vote up 6 votes
public TreeItem getSelectedRootItemFromMainTree(){
	Tree tree = this.getMainTree();
	if(tree == null){
		return null;
	}
	
	TreeItem [] items = tree.getSelection();
	if(items == null || items.length == 0){
		return null;
	}
	
	if(items[0].getData() instanceof StackAnalyzedInfo){
		return items[0].getParentItem();
	}
	return items[0];
}
 
Example 4
Project: convertigo-eclipse   File: ConvertigoPlugin.java   Source Code and License Vote up 5 votes
/**
 * Gets the property descriptor of the selected property for this databaseObjectBeanInfo 
 * @param databaseObjectBeanInfo : BeanInfo of the selected databaseObject in the TreeExplorerView
 * @return PropertyDescriptor
 */
public PropertyDescriptor getSelectedPropertyDescriptor(BeanInfo databaseObjectBeanInfo) {
	PropertyDescriptor propertyDescriptor = null;
	
	// gets the properties editor
	PropertySheet view = ConvertigoPlugin.getDefault().getPropertiesView();
	Tree tree = (Tree) view.getCurrentPage().getControl();
	// gets the property selected in the property editor if one is selected
	TreeItem[] items = tree.getSelection();
	if (items.length > 0) {
		TreeItem selectedItem = items[0];
	
		// gets the local name of the selected property
		String text = selectedItem.getText();
        
        // gets the PropertyDescriptors of this databaseObject
        PropertyDescriptor[] descriptors = databaseObjectBeanInfo.getPropertyDescriptors();
        
        String displayName = null;
		int i = 0;
		
		// gets the PropertyDescriptor of the selected property 
		while (i < descriptors.length && propertyDescriptor == null) {
			displayName = descriptors[i].getDisplayName();
			if (displayName.equals(text))
				propertyDescriptor = descriptors[i];
			i++;
		}
	}	
	return propertyDescriptor;
}
 
Example 5
Project: typescript.java   File: AbstractInformationControl.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse up action for the tree viewer
 * 
 * @param tree
 *            current tree
 * @param e
 *            mouse event
 */
private void handleTreeViewerMouseUp(final Tree tree, MouseEvent e) {
	// Ensure a selection was made, the first mouse button was
	// used and the event happened in the tree
	if ((tree.getSelectionCount() < 1) || (e.button != 1) || !tree.equals(e.getSource())) {
		return;
	}
	// Selection is made in the selection changed listener
	Object object = tree.getItem(new Point(e.x, e.y));
	TreeItem selection = tree.getSelection()[0];
	if (selection.equals(object)) {
		gotoSelectedElement();
	}
}
 
Example 6
Project: cft   File: CloudSpacesSelectionPart.java   Source Code and License Vote up 5 votes
protected void refresh() {
	if (orgsSpacesViewer != null) {

		Tree tree = orgsSpacesViewer.getTree();
		TreeItem[] selectedItems = tree.getSelection();
		if (selectedItems != null && selectedItems.length > 0) {
			// It's a single selection tree, so only get the first selection
			Object selectedObj = selectedItems[0].getData();
			CloudSpace selectedSpace = selectedObj instanceof CloudSpace ? (CloudSpace) selectedObj : null;
			setSpaceSelection(selectedSpace);
		}
	}
}
 
Example 7
Project: NEXCORE-UML-Modeler   File: RenameAction.java   Source Code and License Vote up 5 votes
/**
 * create text editor parent.
 * 
 * @return Composite
 */
Composite createParent() {
    Tree tree = navigatorTree;
    Composite result = new Composite(tree, SWT.NONE);
    TreeItem[] selectedItems = tree.getSelection();

    if (selectedItems == null || selectedItems.length < 1) {
        return null;
    }

    treeEditor.horizontalAlignment = SWT.LEFT;
    treeEditor.grabHorizontal = true;
    treeEditor.setEditor(result, selectedItems[0]);
    return result;
}
 
Example 8
Project: bts   File: TreeViewerNavigator.java   Source Code and License Vote up 5 votes
private TreeItem getCurrentItem(boolean forward) {
	Tree tree = viewer.getTree();
	TreeItem[] selection = tree.getSelection();
	if (selection.length == 0) {
		selection = tree.getItems();
	}

	TreeItem nextItem = null;
	if (selection.length > 0) {
		nextItem = forward ? selection[0] : selection[selection.length - 1];
	}
	return nextItem;
}
 
Example 9
Project: scouter   File: MainProcessor.java   Source Code and License Vote up 5 votes
public TreeItem getSelectedItemFromMainTree(){
	Tree tree = this.getMainTree();
	if(tree == null){
		return null;
	}
	
	TreeItem [] items = tree.getSelection();
	if(items == null || items.length == 0){
		return null;
	}
	return items[0];
}
 
Example 10
Project: PDFReporter-Studio   File: RefactoringHandler.java   Source Code and License Vote up 4 votes
/**
 * Gets called if triggered
 *
 * @param event
 *            The {@link ExecutionEvent}
 */
public Object execute(ExecutionEvent event) throws ExecutionException {

    Event e = ((Event) event.getTrigger());
    Widget widget = e.widget;

    ISelectionService selectionService = PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow().getSelectionService();
    ISelection selection = selectionService.getSelection();

    if (selection instanceof TextSelection && widget instanceof StyledText) { // Java-File
        TextSelection txtSel = (TextSelection) selection;
        IEditorPart activeEditor = PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow().getActivePage()
                .getActiveEditor();
        FileEditorInput input = (FileEditorInput) activeEditor
                .getEditorInput();
        IFile file = input.getFile();

        RBManager.getRefactorService().openRefactorDialog(file,
                txtSel.getOffset());
    }

    if (widget != null && widget instanceof Tree) { // Messages-Editor or
                                                    // TapiJI-View
        Tree tree = (Tree) widget;
        TreeItem[] treeItems = tree.getSelection();
        if (treeItems.length == 1) {
            TreeItem item = treeItems[0];
            Object data = item.getData();
            String oldKey = item.getText();
            if (data != null && data instanceof KeyTreeNode) {
            	oldKey = ((KeyTreeNode)data).getMessageKey();
            }
            if (tree.getData() instanceof AbstractKeyTreeModel) {
                AbstractKeyTreeModel model = (AbstractKeyTreeModel) tree
                        .getData();
                MessagesBundleGroup messagesBundleGroup = model
                        .getMessagesBundleGroup();
                String projectName = messagesBundleGroup.getProjectName();
                String resourceBundleId = messagesBundleGroup
                        .getResourceBundleId();

                RBManager.getRefactorService().openRefactorDialog(
                        projectName, resourceBundleId, oldKey, null);

            }
        }
    }

    return null;
}
 
Example 11
Project: mytourbook   File: DialogMPProfile.java   Source Code and License Vote up 4 votes
/**
 * toggle visibility of the map provider or wms layer
 */
private void toggleMapVisibility(final Tree tree) {

	final TreeItem[] items = tree.getSelection();
	if (items.length > 0) {

		// get tree custom item
		final Object itemData = items[0].getData();

		if (itemData instanceof TVIMapProvider) {

			final MPWrapper mpWrapper = ((TVIMapProvider) itemData).getMapProviderWrapper();
			boolean isWmsDisplayed = mpWrapper.isDisplayedInMap();

			final MP mapProvider = mpWrapper.getMP();
			if (mapProvider instanceof MPWms) {

				// visibility for a wms map provider can be toggled only a layer

				if (isWmsDisplayed) {
					// hide wms
					isWmsDisplayed = false;
				} else {
					// show wms only when one layer is displayed
					isWmsDisplayed = canWmsBeDisplayed((MPWms) mapProvider);
				}

			} else {

				// toggle state

				isWmsDisplayed = !isWmsDisplayed;
			}

			if (isWmsDisplayed) {

				/*
				 * remove parent tiles from loading cache because they can have loading errors
				 * (from their children) which prevents them to be loaded again
				 */
				_mpProfile.resetParentTiles();
			}

			mpWrapper.setIsDisplayedInMap(isWmsDisplayed);
			enableProfileMapButton();

		} else if (itemData instanceof TVIWmsLayer) {

			final TVIWmsLayer tviLayer = (TVIWmsLayer) itemData;
			final MtLayer mtLayer = tviLayer.getMtLayer();

			// toggle layer state
			mtLayer.setIsDisplayedInMap(!mtLayer.isDisplayedInMap());

			// update parent state
			updateMVMapProvider(tviLayer);
		}

		// update viewer
		_treeViewer.update(itemData, null);

		updateLiveView();
	}
}
 
Example 12
Project: mytourbook   File: DialogMPProfile.java   Source Code and License Vote up 4 votes
/**
 * toggle visibility of the map provider or wms layer
 */
private void toggleMapVisibility(final Tree tree) {

	final TreeItem[] items = tree.getSelection();
	if (items.length > 0) {

		// get tree custom item
		final Object itemData = items[0].getData();

		if (itemData instanceof TVIMapProvider) {

			final MPWrapper mpWrapper = ((TVIMapProvider) itemData).getMapProviderWrapper();
			boolean isWmsDisplayed = mpWrapper.isDisplayedInMap();

			final MP mapProvider = mpWrapper.getMP();
			if (mapProvider instanceof MPWms) {

				// visibility for a wms map provider can be toggled only a layer

				if (isWmsDisplayed) {
					// hide wms
					isWmsDisplayed = false;
				} else {
					// show wms only when one layer is displayed
					isWmsDisplayed = canWmsBeDisplayed((MPWms) mapProvider);
				}

			} else {

				// toggle state

				isWmsDisplayed = !isWmsDisplayed;
			}

			if (isWmsDisplayed) {

				/*
				 * remove parent tiles from loading cache because they can have loading
				 * errors (from their children) which prevents them to be loaded again
				 */
				_mpProfile.resetParentTiles();
			}

			mpWrapper.setIsDisplayedInMap(isWmsDisplayed);
			enableProfileMapButton();

		} else if (itemData instanceof TVIWmsLayer) {

			final TVIWmsLayer tviLayer = (TVIWmsLayer) itemData;
			final MtLayer mtLayer = tviLayer.getMtLayer();

			// toggle layer state
			mtLayer.setIsDisplayedInMap(!mtLayer.isDisplayedInMap());

			// update parent state
			updateMVMapProvider(tviLayer);
		}

		// update viewer
		_treeViewer.update(itemData, null);

		updateLiveView();
	}
}
 
Example 13
Project: PDFReporter-Studio   File: GetinputNewWizardPage.java   Source Code and License Vote up 2 votes
/**
 * Return an array of the TreeItem selected in the tree 
 * 
 * @return a not null array of the selected element
 */
private TreeItem[] getSelectedElements(){
	Tree tree = (Tree) resourceList.getControl();
	return tree.getSelection();
}