Java Code Examples for org.eclipse.jface.viewers.TreeViewer#getControl()

The following examples show how to use org.eclipse.jface.viewers.TreeViewer#getControl() . 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: BibOutlinePage.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the outline with new content.
 * 
 * @param content The new content of the outline
 */    
//public void update(Hashtable<String, BibStringTriMap<ReferenceEntry>> sortIndex) {
public void update(BibOutlineContainer content) {
    this.content = content;

    TreeViewer viewer = getTreeViewer();
    //this.sortIndex = sortIndex;
    
    if (viewer != null) {
        Control control = viewer.getControl();
        if (control != null && !control.isDisposed()) {
            control.setRedraw(false);
            viewer.setInput(this.content);
            //viewer.setInput(sortIndex);
            control.setRedraw(true);
        }
    }
}
 
Example 2
Source File: ModulaOutlinePage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The editor is saved, so we should refresh representation
 * 
 * @param tableNamePositions
 */
public void update()
{
	//set the input so that the outlines parse can be called
	//update the tree viewer state
	TreeViewer viewer = getTreeViewer();

	if (viewer != null)
	{
		Control control = viewer.getControl();
		if (control != null && !control.isDisposed())
		{
			try{
				control.setRedraw(false);
				viewer.setInput(input);
			}
			finally{
				control.setRedraw(true);
			}
		}
	}
}
 
Example 3
Source File: TexOutlinePage.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the outline with new content. Called by TexDocumentModel
 * through the editor. Saves the visible state of the outline,
 * sets the new content and restores the state.
 *
 * @param input the new outline input
 */
public void update(TexOutlineInput input) {
    this.input = input;
    
    TreeViewer viewer= getTreeViewer();
    if (viewer != null) {
        
        Control control= viewer.getControl();
        if (control != null && !control.isDisposed()) {
            control.setRedraw(false);
                            
            //First try smart update
            boolean succUpdate = ((TexContentProvider) viewer.getContentProvider()).updateElements(viewer, input.getRootNodes());
            if (!succUpdate) {
                viewer.getTree().deselectAll();
                // save viewer state
            	Object[] expandedElements = viewer.getExpandedElements();
                // set new input
            	viewer.setInput(input.getRootNodes());
                /*viewer.getContentProvider().inputChanged(viewer, null, input.getRootNodes());
                viewer.refresh(true);*/
                // restore viewer state
            	viewer.setExpandedElements(expandedElements);
            }
            control.setRedraw(true);
            
            // disable the refresh button, enable context stuff
            outlineActions.get(ACTION_UPDATE).setEnabled(false);
            outlineActions.get(ACTION_COPY).setEnabled(true);
            outlineActions.get(ACTION_CUT).setEnabled(true);
            outlineActions.get(ACTION_PASTE).setEnabled(true);
            outlineActions.get(ACTION_DELETE).setEnabled(true);
        }
    }
}
 
Example 4
Source File: JsonContentOutlinePage.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
protected void update() {
    final IDocument document = documentProvider.getDocument(currentInput);

    if (document instanceof JsonDocument) {
        final Model model = ((JsonDocument) document).getModel();
        if (model == null) {
            return;
        }

        final TreeViewer viewer = getTreeViewer();

        if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
            // we keep all elements that have been previously expanded
            // so the tree stay in the same state between updates.
            final Object[] expandedElements = viewer.getExpandedElements();
            final List<Object> elements = expandedElements != null ? Arrays.asList(expandedElements) : null;

            viewer.setInput(model);

            if (elements != null && !elements.isEmpty()) {
                List<AbstractNode> newElements = new ArrayList<>();
                model.allNodes().forEach(node -> {
                    if (elements.contains(node))
                        newElements.add(node);
                });
                viewer.setExpandedElements(newElements.toArray());
            }
        }
    }
}
 
Example 5
Source File: DialogPackageExplorer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Control createControl(Composite parent) {
    fPackageViewer= new TreeViewer(parent, SWT.MULTI);
    fPackageViewer.setComparer(WorkingSetModel.COMPARER);
    fPackageViewer.addFilter(new PackageFilter());
    fPackageViewer.setComparator(new ExtendedJavaElementSorter());
    fPackageViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            Object element= ((IStructuredSelection)event.getSelection()).getFirstElement();
            if (fPackageViewer.isExpandable(element)) {
                fPackageViewer.setExpandedState(element, !fPackageViewer.getExpandedState(element));
            } else {
            	if (element instanceof CPListElementAttribute) {
		CPListElementAttribute attribute= (CPListElementAttribute)element;
            		if (attribute.getKey().equals(CPListElement.OUTPUT)) {
            			fActionGroup.getEditOutputFolderAction().run();
            		}
            	}
            }
        }
    });

    MenuManager menuMgr= new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(this);
    fContextMenu= menuMgr.createContextMenu(fPackageViewer.getTree());
    fPackageViewer.getTree().setMenu(fContextMenu);
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            fContextMenu.dispose();
        }
    });

    return fPackageViewer.getControl();
}
 
Example 6
Source File: N4IDEXpectView.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
	fillLayout.marginHeight = 5;
	fillLayout.marginWidth = 5;
	parent.setLayout(fillLayout);

	// main container
	container = new Composite(parent, SWT.BORDER);
	container.setLayout(new FillLayout());

	// create container for stack trace data
	Composite stacktraceDataContainer = new Composite(parent, SWT.BORDER);

	FormLayout formLayout = new FormLayout();
	formLayout.marginHeight = 5;
	formLayout.marginWidth = 5;
	formLayout.spacing = 5;
	stacktraceDataContainer.setLayout(formLayout);

	Composite stackLabelContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE);
	stackLabelContainer.setLayout(new GridLayout());

	FormData stackLabelFormData = new FormData();
	stackLabelFormData.top = new FormAttachment(0);
	stackLabelFormData.left = new FormAttachment(0);
	stackLabelFormData.right = new FormAttachment(100);
	stackLabelFormData.bottom = new FormAttachment(20);
	stackLabelContainer.setLayoutData(stackLabelFormData);

	Composite stackTraceContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE);
	stackTraceContainer.setLayout(new FillLayout());

	FormData stackTraceFormData = new FormData();
	stackTraceFormData.top = new FormAttachment(stackLabelContainer);
	stackTraceFormData.left = new FormAttachment(0);
	stackTraceFormData.right = new FormAttachment(100);
	stackTraceFormData.bottom = new FormAttachment(100);
	stackTraceContainer.setLayoutData(stackTraceFormData);

	// Create viewer for test tree in main container
	testTreeViewer = new TreeViewer(container);
	testTreeViewer.setContentProvider(new XpectContentProvider());
	testTreeViewer.setLabelProvider(new XpectLabelProvider(this.testsExecutionStatus));
	testTreeViewer.setInput(null);

	// create stack trace label
	stacktraceLabel = new Label(stackLabelContainer, SWT.SHADOW_OUT);
	FontData fontData = stacktraceLabel.getFont().getFontData()[0];
	Display display = Display.getCurrent();
	// may be null if outside the UI thread
	if (display == null)
		display = Display.getDefault();
	Font font = new Font(display, new FontData(fontData.getName(), fontData
			.getHeight(), SWT.BOLD));
	// Make stack trace label bold
	stacktraceLabel.setFont(font);

	stacktraceLabel.setText(NO_TRACE_MSG);

	// create stack trace console
	MessageConsole messageConsole = new MessageConsole("trace", null);
	stacktraceConsole = new TraceConsole(messageConsole);
	stacktraceConsoleViewer = new TextConsoleViewer(stackTraceContainer, messageConsole);

	// context menu
	getSite().setSelectionProvider(testTreeViewer);
	MenuManager contextMenu = new MenuManager();
	contextMenu.setRemoveAllWhenShown(true);
	getSite().registerContextMenu(contextMenu, testTreeViewer);
	Control control = testTreeViewer.getControl();
	Menu menu = contextMenu.createContextMenu(control);
	control.setMenu(menu);
	activateContext();

	createSelectionActions();

}