Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1df8c04bd73fb7c2b2fea5f3fd9a96bb16236e84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2006, 2015 Wind River Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.examples.dsf.filebrowser;

import java.util.concurrent.RejectedExecutionException;

import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.IRootVMNode;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
import org.eclipse.cdt.dsf.ui.viewmodel.RootVMNode;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;

/**
 * 
 */
@SuppressWarnings("restriction")
public class FileBrowserVMProvider extends AbstractVMProvider 
{
    /**
     * The object to be set to the viewer that shows contents supplied by this provider.
     * @see org.eclipse.jface.viewers.TreeViewer#setInput(Object)  
     */
    private final IAdaptable fViewerInputObject = 
        new IAdaptable() {
            /**
             * The input object provides the viewer access to the viewer model adapter.
             */
            @Override
	    @SuppressWarnings("unchecked")
            public Object getAdapter(Class adapter) {
                if ( adapter.isInstance(getVMAdapter()) ) {
                    return getVMAdapter();
                }
                return null;
            }
            
            @Override
            public String toString() {
                return "File Browser Viewer Input"; //$NON-NLS-1$
            }
        };

    /**
     * Constructor creates and configures the layout nodes to display file 
     * system contents.  
     * @param adapter The viewer model adapter that this provider is registered with.
     * @param presentationContext The presentation context that this provider is 
     * generating contents for.
     */
    public FileBrowserVMProvider(AbstractVMAdapter adapter, IPresentationContext presentationContext) {
        super(adapter, presentationContext);

        IRootVMNode root = new RootVMNode(this); 
        IVMNode fileSystemRoots = new FilesystemRootsVMNode(this);
        addChildNodes(root, new IVMNode[] { fileSystemRoots });
        IVMNode files = new FileVMNode(this);
        addChildNodes(fileSystemRoots, new IVMNode[] { files });
        addChildNodes(files, new IVMNode[] { files });
        setRootNode(root);
    }
    
    /**
     * Returns the input object to be set to the viewer that shows contents
     * supplied by this provider.  
     */
    public Object getViewerInputObject() {
        return fViewerInputObject;
    }    

    /**
     * Event handler for file selection text changes in the dialog.
     * @param text New text entered in file selection text box.
     */
    void selectionTextChanged(final String text) {
        if (isDisposed()) return;
        
        // We're in the UI thread.  Re-dispach to VM Adapter executor thread 
        // and then call root layout node.
        try {
            getExecutor().execute(new Runnable() {
                @Override
		public void run() {
                    if (isDisposed()) return;
                    handleEvent(text);
                }});
        } catch (RejectedExecutionException e) {
            // Ignore.  This exception could be thrown if the provider is being 
            // shut down.  
        }
    }
}

Back to the top