org.eclipse.jface.viewers.TreeSelection Java Examples

The following examples show how to use org.eclipse.jface.viewers.TreeSelection. 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: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.ColumnViewer#editElement(java.lang.Object, int)
 */
public void editElement(Object element, int column) {
	if (element instanceof TreePath) {
		try {
			getControl().setRedraw(false);
			setSelection(new TreeSelection((TreePath) element));
			CTreeComboItem[] items = tree.getSelection();

			if (items.length == 1) {
				ViewerRow row = getViewerRowFromItem(items[0]);

				if (row != null) {
					ViewerCell cell = row.getCell(column);
					if (cell != null) {
						triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
					}
				}
			}
		} finally {
			getControl().setRedraw(true);
		}
	} else {
		super.editElement(element, column);
	}
}
 
Example #2
Source File: GalleryTreeViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void editElement(Object element, int column) {
	if (element instanceof TreePath) {
		setSelection(new TreeSelection((TreePath) element));
		GalleryItem[] items = gallery.getSelection();

		if (items.length == 1) {
			ViewerRow row = getViewerRowFromItem(items[0]);

			if (row != null) {
				ViewerCell cell = row.getCell(column);
				if (cell != null) {
					getControl().setRedraw(false);
					triggerEditorActivationEvent(
							new ColumnViewerEditorActivationEvent(cell));
					getControl().setRedraw(true);
				}
			}
		}
	} else {
		super.editElement(element, column);
	}
}
 
Example #3
Source File: AbapGitStagingObjectMenuFactory.java    From ADT_Frontend with MIT License 6 votes vote down vote up
private void buildContextMenu(IMenuManager menuManager) {
	TreeSelection selection = (TreeSelection) this.treeViewer.getSelection();

	//open object action
	this.menuManager.add(this.openAction);
	this.menuManager.add(new Separator());
	if (this.unstaged) {
		//stage objects action
		this.menuManager.add(this.stageAction);
	} else {
		//unstage objects action
		this.menuManager.add(this.unstageAction);
	}
	//TODO: remove this check after the 2002 upgrade
	if (this.stagingService.isFileCompareSupported(selection.getFirstElement())) {
		//file compare
		this.menuManager.add(this.compareAction);
	}
	if (selection.size() == 1) {
		this.menuManager.add(new Separator());
		//copy name to clipboard action
		this.menuManager.add(this.copyAction);
	}
}
 
Example #4
Source File: SourceContentOutlinePage.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    viewer = getTreeViewer();
    contentProvider = new TreeNodeContentProvider();
    viewer.setContentProvider(contentProvider);
    labelProvider = new TextUMLLabelProvider();
    viewer.setLabelProvider(labelProvider);
    // disabled: used to make elements to show sorted by type
    // viewer.setComparator(new UIModelObjectViewerComparator());
    viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);

    // tracks selections in the outline and reflects them in the editor
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            TreeSelection selection = (TreeSelection) event.getSelection();
            if (!selection.isEmpty()) {
                TreeNode treeNode = (TreeNode) selection.getFirstElement();
                UIModelObject model = (UIModelObject) treeNode.getValue();
                selectInEditor(model.getToken());
            }
        }
    });

    refresh();
}
 
Example #5
Source File: SyncDependenciesAction.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public void selectionChanged(IAction arg0, ISelection arg1) {
	if (arg1 instanceof TreeSelection) {
		TreeSelection treeSelection = (TreeSelection) arg1;
		if (treeSelection.getFirstElement() instanceof IProject) {
			IProject project = (IProject) treeSelection.getFirstElement();
			arg0.setEnabled(project.isOpen());
			this.project = project;
			mavenProjectFile = project.getFile("pom.xml");
			if (mavenProjectFile.exists()) {
				arg0.setText("Sync Project Dependencies with pom.xml");
			}
		} else {
			arg0.setEnabled(false);
		}
	}
}
 
Example #6
Source File: UpgradePluginVersionsAction.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
@Override
public void selectionChanged(IAction action, ISelection selection) {
	if (selection instanceof TreeSelection) {
		TreeSelection treeSelection = (TreeSelection) selection;
		if (treeSelection.getFirstElement() instanceof IProject) {
			IProject project = (IProject) treeSelection.getFirstElement();
			action.setEnabled(project.isOpen());
			this.project = project;
			mavenProjectFile = project.getFile("pom.xml");
			if (mavenProjectFile.exists()) {
				action.setText("Upgrade Plugin Versions in pom.xml");
			}
		} else {
			action.setEnabled(false);
		}
	}

}
 
Example #7
Source File: RemoveConnectionHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
            .getActivePage().getSelection();
	if(selection instanceof TreeSelection) {
		TreeSelection treeSelection = (TreeSelection) selection;
		if(treeSelection.getFirstElement() instanceof File) {
			File file = (File) treeSelection.getFirstElement();
			if(file.getFileExtension().equals("bib")){
				WorkspaceBibTexEntry entry = wm.getWorkspaceBibTexEntryByUri(file.getLocationURI());
				if(entry != null) {
					if(entry.getMendeleyFolder() != null) {
						// by setting the MendeleyFolder of a WorkspaceBibTexEntry to null, the connection will be removed
						entry.setMendeleyFolder(null);
						decoratorManager.update("de.tudresden.slr.model.mendeley.decorators.MendeleyOverlayDecorator");
					}
				}
			}
		}
	}
	return null;
}
 
Example #8
Source File: IndexView.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * fillContextMenu
 * 
 * @param manager
 */
private void fillContextMenu(IMenuManager manager)
{
	ISelection selection = treeViewer.getSelection();

	if (selection instanceof TreeSelection)
	{
		TreeSelection treeSelection = (TreeSelection) selection;
		Object item = treeSelection.getFirstElement();

		if (item != null)
		{
			IAction[] actions = actionProvider.getActions(this, item);

			if (actions != null)
			{
				for (IAction action : actions)
				{
					manager.add(action);
				}
			}
		}
	}
}
 
Example #9
Source File: BundleView.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * fillContextMenu
 * 
 * @param manager
 */
private void fillContextMenu(IMenuManager manager)
{
	ISelection selection = treeViewer.getSelection();

	if (selection instanceof TreeSelection)
	{
		TreeSelection treeSelection = (TreeSelection) selection;
		Object item = treeSelection.getFirstElement();

		if (item instanceof BaseNode)
		{
			BaseNode<?> node = (BaseNode<?>) item;
			Action[] actions = node.getActions();

			if (actions != null)
			{
				for (Action action : actions)
				{
					manager.add(action);
				}
			}
		}
	}
}
 
Example #10
Source File: ColumnCategoriesDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return selected columns index(s) from the tree viewer
 */
private List<Integer> getColumnIndexesFromTreeNodes() {
	Object[] nodes = ((TreeSelection)treeViewer.getSelection()).toArray();

	List<Integer> indexes = new ArrayList<Integer>();
	for (Object object : nodes) {
		Node node = (Node) object;
		if(Type.COLUMN == node.getType()){
			indexes.add(Integer.parseInt(node.getData()));
		}
	}
	return indexes;
}
 
Example #11
Source File: ColumnCategoriesDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return selected columns index(s) from the tree viewer
 */
private List<Integer> getColumnIndexesFromTreeNodes() {
	Object[] nodes = ((TreeSelection)treeViewer.getSelection()).toArray();

	List<Integer> indexes = new ArrayList<Integer>();
	for (Object object : nodes) {
		Node node = (Node) object;
		if(Type.COLUMN == node.getType()){
			indexes.add(Integer.parseInt(node.getData()));
		}
	}
	return indexes;
}
 
Example #12
Source File: HandlerUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the current selected UI element. Can be used instead of
 * {@link org.eclipse.ui.handlers.HandlerUtil#getCurrentSelection} when an
 * ExecutionEvent is not available.
 *
 * @return The element consisting of the selection
 */
public static @Nullable Object getSelectedModelElement() {
    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return null;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return null;
    }
    final ISelection selection = selectionProvider.getSelection();

    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        return sel.getFirstElement();
    }

    return null;
}
 
Example #13
Source File: SelectTracesHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is an experiment
    fExperiment = null;
    if (selection instanceof TreeSelection) {
        TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        Object element = sel.getFirstElement();
        if (element instanceof TmfExperimentElement) {
            fExperiment = (TmfExperimentElement) element;
        }
    }

    return (fExperiment != null);
}
 
Example #14
Source File: OpenTraceHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is a trace
    fTrace = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfTraceElement) {
            fTrace = (TmfTraceElement) element;
        }
    }

    // We only enable opening from the Traces folder for now
    return (fTrace != null);
}
 
Example #15
Source File: OpenAnalysisHelpHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is a trace
    fAnalysis = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfAnalysisElement) {
            fAnalysis = (TmfAnalysisElement) element;
        }
    }

    return (fAnalysis != null);
}
 
Example #16
Source File: OpenAnalysisHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    /* Check if we are closing down */
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    /* Get the selection */
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    /* Make sure there is only one selection and that it is an analysis output */
    fAnalysisElement = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfAnalysisElement) {
            fAnalysisElement = (TmfAnalysisElement) element;
        }
    }

    return (fAnalysisElement != null);
}
 
Example #17
Source File: CTreeViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractViewerEditor createViewerEditor() {
	return new AbstractViewerEditor(this) {

		protected StructuredSelection createSelection(Object element) {
			if (element instanceof TreePath) {
				return new TreeSelection((TreePath) element, getComparer());
			}

			return new StructuredSelection(element);
		}

		protected Item[] getSelection() {
			return ctree.getSelection();
		}

		protected void setEditor(Control w, Item item, int fColumnNumber) {
			ctreeEditor.setEditor(w, (CTreeItem) item, fColumnNumber);
		}

		protected void setLayoutData(LayoutData layoutData) {
			ctreeEditor.grabHorizontal = layoutData.grabHorizontal;
			ctreeEditor.horizontalAlignment = layoutData.horizontalAlignment;
			ctreeEditor.minimumWidth = layoutData.minimumWidth;
		}

		protected void showSelection() {
			ctree.showSelection();
		}

	};
}
 
Example #18
Source File: CreateNewN4JSElementInModuleHandler.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the active tree resource selection if there is one.
 *
 * Examines the active workspace selection and if it is a resource inside of a tree returns it.
 *
 * @param event
 *            The execution event
 * @returns The resource or {@code null} on failure.
 *
 */
private static IResource getActiveTreeResourceSelection(ExecutionEvent event) {

	ISelection activeSelection = HandlerUtil.getCurrentSelection(event);

	if (activeSelection instanceof TreeSelection) {
		Object firstElement = ((TreeSelection) activeSelection).getFirstElement();

		if (firstElement instanceof IResource) {
			return (IResource) firstElement;
		}
	}
	return null;
}
 
Example #19
Source File: XMLAnalysesManagerPreferencePage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Refresh the selected project elements. This is useful after XML files
 * importing/deletion/enabling/disabling.
 *
 * @param elements
 *            the elements to re-open
 */
private static void refreshProject(Collection<TmfCommonProjectElement> elements) {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return;
    }
    ISelection selection = selectionProvider.getSelection();

    if (selection instanceof TreeSelection) {
        TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        Object element = sel.getFirstElement();
        if (element instanceof TmfProjectModelElement) {
            ((TmfProjectModelElement) element).getProject().refresh();
        }
    }

    // Re-open given elements
    elements.forEach(TmfOpenTraceHelper::openFromElement);
}
 
Example #20
Source File: RenameExperimentHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    ISelection selection = selectionProvider.getSelection();

    // Make sure there is only selection and that it is an experiment
    fExperiment = null;
    if (selection instanceof TreeSelection) {
        TreeSelection sel = (TreeSelection) selection;
        Object element = sel.getFirstElement();
        if (element instanceof TmfExperimentElement) {
            fExperiment = (TmfExperimentElement) element;
        }
    }

    return (fExperiment != null);
}
 
Example #21
Source File: TrimTraceHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return false;
    }
    @SuppressWarnings("null")
    IHandlerService service = workbench.getService(IHandlerService.class);
    // we need the current state, and the map, but the command and the
    // trigger are
    // not necessary for getCurrentSelection
    ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.emptyMap(), null, service.getCurrentState());
    final Object element = HandlerUtil.getCurrentSelection(executionEvent);

    if (!(element instanceof TreeSelection)) {
        return false;
    }
    /*
     * plugin.xml should have done type/count verification already
     */
    Object firstElement = ((TreeSelection) element).getFirstElement();
    ITmfTrace trace = null;
    if (firstElement instanceof TmfCommonProjectElement) {
        TmfCommonProjectElement traceElem = (TmfCommonProjectElement) firstElement;
        if (traceElem instanceof TmfTraceElement) {
            traceElem = ((TmfTraceElement) traceElem).getElementUnderTraceFolder();
        }
        trace = traceElem.getTrace();
    }
    if (trace == null || !isValid(trace)) {
        return false;
    }

    /* Only enable the action if a time range is currently selected */
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange selectionRange = tm.getTraceContext(trace).getSelectionRange();
    return !(selectionRange.getStartTime().equals(selectionRange.getEndTime()));
}
 
Example #22
Source File: OpenExperimentHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is an experiment
    fExperiment = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfExperimentElement) {
            fExperiment = (TmfExperimentElement) element;
        }
    }

    // We only enable opening from the Traces folder for now
    return ((fExperiment != null) && (!fExperiment.getTraces().isEmpty()));
}
 
Example #23
Source File: OpenAnalysisOutputHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    /* Check if we are closing down */
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    /* Get the selection */
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    /* Make sure there is only one selection and that it is an analysis output */
    fOutputElement = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfAnalysisOutputElement) {
            fOutputElement = (TmfAnalysisOutputElement) element;
        }
    }

    return (fOutputElement != null);
}
 
Example #24
Source File: NewExperimentHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return Boolean.FALSE;
    }
    ISelection selection = part.getSite().getSelectionProvider().getSelection();
    TmfExperimentFolder experimentFolder = null;
    if (selection instanceof TreeSelection) {
        TreeSelection sel = (TreeSelection) selection;
        Object element = sel.getFirstElement();
        if (element instanceof TmfExperimentFolder) {
            experimentFolder = (TmfExperimentFolder) element;
        }
    }
    if (experimentFolder == null) {
        return null;
    }

    // Fire the New Experiment dialog
    Shell shell = window.getShell();
    NewExperimentDialog dialog = new NewExperimentDialog(shell, experimentFolder);
    dialog.open();

    return null;
}
 
Example #25
Source File: EIPModelAndRouteSelectionDialog.java    From eip-designer with Apache License 2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite base) {
   Composite parent = (Composite) super.createDialogArea(base);
   Composite composite = new Composite(parent, SWT.NONE);
   
   GridLayout layout = new GridLayout();
   layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
   layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
   layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
   layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
   composite.setLayout(layout);
   composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
   
   // Manage dialog tree content.
   FilteredTree tree = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER,
         new PatternFilter(), true);

   projectTree = tree.getViewer();
   projectTree.setLabelProvider(new EIPModelTreeLabelProvider());
   projectTree.setContentProvider(new EIPModelTreeContentProvider());
   projectTree.setInput(ResourcesPlugin.getWorkspace().getRoot());
   
   GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
   
   // Manage dialog tree events.
   projectTree.addSelectionChangedListener(new ISelectionChangedListener() {
      @Override
      public void selectionChanged(SelectionChangedEvent event) {
         if (event.getSelection() instanceof TreeSelection) {
            TreeSelection tSelection = (TreeSelection)event.getSelection();
            if (tSelection.getFirstElement() instanceof IResource) {
               eipModel = (IResource) tSelection.getFirstElement();
            }
         }
      }
   });
   
   setTitle("Choose a target EIP model");
   setMessage("Select the EIP model for designing a new Route from Service");
   applyDialogFont(composite);
   
   return composite;
}
 
Example #26
Source File: CompareTargetSelectionDialog.java    From eip-designer with Apache License 2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite base) {
   Composite parent = (Composite) super.createDialogArea(base);
   Composite composite = new Composite(parent, SWT.NONE);
   
   GridLayout layout = new GridLayout();
   layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
   layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
   layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
   layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
   composite.setLayout(layout);
   composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
   
   // Manage dialog tree content.
   FilteredTree tree = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER,
         new PatternFilter(), true);

   projectTree = tree.getViewer();
   projectTree.setLabelProvider(new RouteTreeLabelProvider());
   projectTree.setContentProvider(new RouteTreeContentProvider());
   projectTree.setInput(ResourcesPlugin.getWorkspace().getRoot());
   
   GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
   
   // Manage dialog tree events.
   projectTree.addSelectionChangedListener(new ISelectionChangedListener() {
      @Override
      public void selectionChanged(SelectionChangedEvent event) {
         if (event.getSelection() instanceof TreeSelection) {
            TreeSelection tSelection = (TreeSelection)event.getSelection();
            if (tSelection.getFirstElement() instanceof Route) {
               selectedRoute = (Route) tSelection.getFirstElement();
            }
         }
      }
   });
   
   setTitle("Compare '" + fileName + "' with an EIP Route model");
   setMessage("Select an EIP Route to compare the resource with");
   applyDialogFont(composite);
   
   return composite;
}
 
Example #27
Source File: PersistTargetSelectionDialog.java    From eip-designer with Apache License 2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite base) {
   Composite parent = (Composite) super.createDialogArea(base);
   Composite composite = new Composite(parent, SWT.NONE);
   
   GridLayout layout = new GridLayout();
   layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
   layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
   layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
   layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
   composite.setLayout(layout);
   composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
   
   // Manage dialog tree content.
   FilteredTree tree = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER,
         new PatternFilter(), true);

   projectTree = tree.getViewer();
   projectTree.setLabelProvider(new EIPModelTreeLabelProvider());
   projectTree.setContentProvider(new EIPModelTreeContentProvider());
   projectTree.setInput(ResourcesPlugin.getWorkspace().getRoot());
   
   GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
   
   // Manage dialog tree events.
   projectTree.addSelectionChangedListener(new ISelectionChangedListener() {
      @Override
      public void selectionChanged(SelectionChangedEvent event) {
         if (event.getSelection() instanceof TreeSelection) {
            TreeSelection tSelection = (TreeSelection)event.getSelection();
            if (tSelection.getFirstElement() instanceof IResource) {
               selectedEIPModel = (IResource) tSelection.getFirstElement();
            }
         }
      }
   });
   
   setTitle("Parse and merge '" + fileName + "' with an EIP Model");
   setMessage("Select an EIP Model to persist the parsed resource within");
   applyDialogFont(composite);
   
   return composite;
}
 
Example #28
Source File: AddTargetHandler.java    From JReFrameworker with MIT License 4 votes vote down vote up
@SuppressWarnings("restriction")
public Object execute(ExecutionEvent event) throws ExecutionException {
	try {
		// get the package explorer selection
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ISelection selection = window.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");
		
		if(selection == null){
			Log.warning("Selection must be a library file.");
			return null;
		}
		
		TreePath[] paths = ((TreeSelection) selection).getPaths();
		if(paths.length > 0){
			TreePath p = paths[0];
			Object last = p.getLastSegment();
			
			// locate the project handle for the selection
			IProject project = null;
			if(last instanceof IJavaProject){
				project = ((IJavaProject) last).getProject();
			} else if (last instanceof IResource) {
				project = ((IResource) last).getProject();
			} 
			
			if(last instanceof org.eclipse.core.internal.resources.File){
				File library = ((org.eclipse.core.internal.resources.File)last).getLocation().toFile();
				JReFrameworkerProject jrefProject = new JReFrameworkerProject(project);
				jrefProject.addTarget(library);
			} else {
				Log.warning("Selection must be a library file.");
			}
		} else {
			Log.warning("Selection must be a library file.");
		}
	} catch (Exception e) {
		Log.error("Unable to add target", e);
	}
	
	return null;
}
 
Example #29
Source File: ResetClasspathHandler.java    From JReFrameworker with MIT License 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	try {
		// get the package explorer selection
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ISelection selection = window.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");
		
		if(selection == null){
			Log.warning("Selection must be a project.");
			return null;
		}
		
		TreePath[] paths = ((TreeSelection) selection).getPaths();
		if(paths.length > 0){
			TreePath p = paths[0];
			Object last = p.getLastSegment();
			
			// locate the project handle for the selection
			IProject project = null;
			if(last instanceof IJavaProject){
				project = ((IJavaProject) last).getProject();
			} else if (last instanceof IResource) {
				project = ((IResource) last).getProject();
			} 
			
			if(project == null){
				Log.warning("Selection must be a project.");
				return null;
			}
			
			JReFrameworkerProject jrefProject = new JReFrameworkerProject(project);
			jrefProject.restoreOriginalClasspathEntries();
			jrefProject.refresh();
		} else {
			Log.warning("Selection must be a project.");
		}
	} catch (Exception e) {
		Log.error("Unable to reset project classpath", e);
	}
	
	return null;
}
 
Example #30
Source File: MSyncWizardFolderPage.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create contents of the wizard.
 * @param parent
 */
public void createControl(Composite parent) {
	mc = MendeleyClient.getInstance();
	
	Composite container = new Composite(parent, SWT.NULL);

	setControl(container);
	container.setLayout(new GridLayout(1, false));
	TreeViewer treeViewer = new TreeViewer(container, SWT.BORDER);
	Tree tree = treeViewer.getTree();
	
	tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	treeViewer.setContentProvider(new TreeContentProvider());
	treeViewer.setLabelProvider(new MendeleyTreeLabelProvider());
	
       try {
       	// TreeViewer takes Array of MendeleyFolders
		treeViewer.setInput(mc.getMendeleyFolders());
	} catch (TokenMgrException e) {
		e.printStackTrace();
	}  
       
       // add a Listener that makes sure that only Folders can be selected
       // if a Folder is selected, the page will be set to complete
       treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
		
		@Override
		public void selectionChanged(SelectionChangedEvent event) {
			TreeSelection selection = ((TreeSelection)event.getSelection());
			if(selection.getFirstElement() instanceof MendeleyDocument){
				
				TreeItem[] item = treeViewer.getTree().getSelection();
				tree.select(item[0].getParentItem());
				folder_selected = (MendeleyFolder)item[0].getParentItem().getData();
				setPageComplete(true);
			}
			if(selection.getFirstElement() instanceof MendeleyFolder){
				folder_selected = (MendeleyFolder)selection.getFirstElement();
				setPageComplete(true);
			}
			isSelectionValidated = false;
		}
	});	
       
}