Package ch.ethz.prose.eclipse.internal.run

Source Code of ch.ethz.prose.eclipse.internal.run.ProseRunContentProvider

//
//  This file is part of the Prose Development Tools for Eclipse package.
//
//  The contents of this file are subject to the Mozilla Public License
//  Version 1.1 (the "License"); you may not use this file except in
//  compliance with the License. You may obtain a copy of the License at
//  http://www.mozilla.org/MPL/
//
//  Software distributed under the License is distributed on an "AS IS" basis,
//  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
//  for the specific language governing rights and limitations under the
//  License.
//
//  The Original Code is Prose Development Tools for Eclipse.
//
//  The Initial Developer of the Original Code is Angela Nicoara. Portions
//  created by Angela Nicoara are Copyright (C) 2006 Angela Nicoara.
//  All Rights Reserved.
//
//  Contributor(s):
//  $Id: ProseRunContentProvider.java,v 1.1 2008/11/18 12:23:02 anicoara Exp $
//  ==============================================================================
//

package ch.ethz.prose.eclipse.internal.run;

import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Control;

import ch.ethz.prose.eclipse.IProseRunListener;
import ch.ethz.prose.eclipse.internal.core.ProsePlugin;

/**
* Content provider for Prose run tree views.
*
* @author Angela Nicoara
* @author Johann Gyger
* @version $Id: ProseRunContentProvider.java,v 1.1 2008/11/18 12:23:02 anicoara Exp $
*/
public class ProseRunContentProvider implements ITreeContentProvider, IProseRunListener {

    protected TreeViewer viewer;

    /**
     * Create new Prose run content provider.
     */
    public ProseRunContentProvider() {
        ProsePlugin.getDefault().addRunListener(this);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
     */
    public Object[] getElements(Object inputElement) {
        return ProsePlugin.getDefault().getRuns();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    public Object[] getChildren(Object parentElement) {
        return ((IRunNode) parentElement).getChildren();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    public Object getParent(Object element) {
        return ((IRunNode) element).getParent();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    public boolean hasChildren(Object element) {
        return ((IRunNode) element).hasChildren();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
     */
    public void dispose() {
        ProsePlugin.getDefault().removeRunListener(this);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public void inputChanged(Viewer treeViewer, Object oldInput, Object newInput) {
        viewer = (TreeViewer) treeViewer;
    }

    /* (non-Javadoc)
     * @see ch.ethz.prose.eclipse.IProseRunListener#runAdded(ch.ethz.prose.eclipse.internal.core.ProseRunNode)
     */
    public void runAdded(final ProseRunNode node) {
        Control ctrl = viewer.getControl();
        if (ctrl == null || ctrl.isDisposed())
            return;
        ctrl.getDisplay().syncExec(new Runnable() {
            public void run() {
                if (!viewer.getControl().isDisposed()) {
                    viewer.add(viewer.getInput(), node);
                    viewer.expandToLevel(2);
                }
            }
        });
    }

    /* (non-Javadoc)
     * @see ch.ethz.prose.eclipse.IProseRunListener#runUnreachable(ch.ethz.prose.eclipse.internal.run.ProseRunNode)
     */
    public void runUnreachable(final ProseRunNode node) {
        Control ctrl = viewer.getControl();
        if (ctrl == null || ctrl.isDisposed())
            return;
        ctrl.getDisplay().asyncExec(new Runnable() {
            public void run() {
                if (!viewer.getControl().isDisposed()) {
                    viewer.refresh(node);
                }
            }
        });       
    }

    /* (non-Javadoc)
     * @see ch.ethz.prose.eclipse.IProseRunListener#runRemoved(ch.ethz.prose.eclipse.internal.run.ProseRunNode)
     */
    public void runRemoved(final ProseRunNode node) {
        Control ctrl = viewer.getControl();
        if (ctrl == null || ctrl.isDisposed())
            return;
        ctrl.getDisplay().syncExec(new Runnable() {
            public void run() {
                if (!viewer.getControl().isDisposed()) {
                    viewer.remove(node);
                }
            }
        });
    }

    /* (non-Javadoc)
     * @see ch.ethz.prose.eclipse.IProseRunListener#aspectInserted(ch.ethz.prose.eclipse.internal.core.AspectManagerNode)
     */
    public void aspectInserted(final AspectManagerNode node) {
        Control ctrl = viewer.getControl();
        if (ctrl == null || ctrl.isDisposed())
            return;
        ctrl.getDisplay().syncExec(new Runnable() {
            public void run() {
                if (!viewer.getControl().isDisposed()) {
                    viewer.collapseToLevel(node, AbstractTreeViewer.ALL_LEVELS);
                    viewer.refresh(node);
                }
            }
        });
    }

    /* (non-Javadoc)
     * @see ch.ethz.prose.eclipse.IProseRunListener#aspectInserted(ch.ethz.prose.eclipse.internal.run.AspectNode)
     */
    public void aspectWithdrawn(final AspectNode node) {
        Control ctrl = viewer.getControl();
        if (ctrl == null || ctrl.isDisposed())
            return;
        ctrl.getDisplay().syncExec(new Runnable() {
            public void run() {
                if (!viewer.getControl().isDisposed()) {
                    viewer.refresh(node.getParent());
                }
            }
        });
    }

}
TOP

Related Classes of ch.ethz.prose.eclipse.internal.run.ProseRunContentProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.