| /******************************************************************************* |
| * Copyright (c) 2004-2008 Istvan Rath and Daniel Varro |
| * 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: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.frameworkgui.content;
|
|
|
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.jface.viewers.ITreeContentProvider; |
| import org.eclipse.jface.viewers.Viewer; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.PartInitException; |
| import org.eclipse.viatra2.framework.FrameworkManager; |
| import org.eclipse.viatra2.framework.IFramework; |
| import org.eclipse.viatra2.framework.IFrameworkListChangedListener; |
| import org.eclipse.viatra2.frameworkgui.views.FrameworkTreeView; |
| import org.eclipse.viatra2.frameworkgui.views.code.CodeBufferView; |
|
|
| public class FrameworkViewContentProvider
|
| implements ITreeContentProvider, IFrameworkListChangedListener
|
| {
|
|
|
| private FrameworkTreeView iFT;
|
|
|
| private Map<IFramework,FrameworkContainer> frameworkContainers;
|
|
|
| public FrameworkViewContentProvider(FrameworkTreeView part)
|
| {
|
| iFT = part;
|
| frameworkContainers = new HashMap<IFramework,FrameworkContainer>();
|
| refreshFrameworks();
|
| FrameworkManager.getInstance().addFrameworkListChangedListener(this);
|
| }
|
|
|
| public void inputChanged(Viewer v, Object oldInput, Object newInput) {}
|
|
|
| public void dispose()
|
| {
|
| FrameworkManager.getInstance().removeFrameworkListChangedListener(this);
|
| }
|
|
|
| public Object[] getElements(Object parent)
|
| {
|
| return getChildren(parent);
|
| }
|
|
|
| public Object[] getChildren(Object parent)
|
| {
|
| if (parent.equals(iFT.getViewSite()))
|
| {
|
| return frameworkContainers.values().toArray();
|
| }
|
| else if (parent instanceof ITreeParent)
|
| {
|
| return ((ITreeParent)parent).getChildren().toArray();
|
| }
|
| else return new Object[0];
|
| }
|
|
|
|
|
| public Object getParent(Object child)
|
| {
|
| if (child instanceof ITreeObject)
|
| {
|
| return ((ITreeObject)child).getParent();
|
| }
|
| // else if (child instanceof I)
|
| return null;
|
| }
|
|
|
| public boolean hasChildren(Object parent)
|
| {
|
| if (parent instanceof ITreeParent)
|
| {
|
| return ((ITreeParent)parent).hasChildren();
|
| }
|
| return false;
|
| }
|
|
|
| public void frameworkAdded(final IFramework f)
|
| {
|
| Display.getDefault().asyncExec(new Runnable(){
|
|
|
| public void run() {
|
| FrameworkContainer c = new FrameworkContainer(f,iFT);
|
| frameworkContainers.put(f,c);
|
| iFT.refreshViewer(null);
|
|
|
| // activate code output view
|
| try {
|
| iFT.getViewSite().getPage().showView(CodeBufferView.ID);
|
| }
|
| catch (PartInitException e)
|
| {
|
| f.getLogger().fatal(e.getMessage());
|
| }
|
| }
|
| });
|
|
|
| }
|
|
|
| public void frameworkRemoved(final IFramework f)
|
| {
|
| Display.getDefault().asyncExec(new Runnable(){
|
|
|
| public void run() {
|
| FrameworkContainer c = frameworkContainers.get(f); |
| if (c != null)
|
| c.dispose();
|
| frameworkContainers.remove(f);
|
| iFT.refreshViewer(null);
|
| }
|
| });
|
|
|
| }
|
|
|
| private void refreshFrameworks()
|
| {
|
| String[] fws = iFT.getFrameWorkManager().getAllFrameWorks();
|
| for (int i=0; i<fws.length; i++)
|
| {
|
| IFramework fw = iFT.getFrameWorkManager().getFramework(fws[i]);
|
| FrameworkContainer c = new FrameworkContainer(fw,iFT);
|
| frameworkContainers.put(fw,c);
|
| }
|
| }
|
|
|
| /* private void refreshframeworks()
|
| {
|
| invisibleRoot = new TreeParent("", null);
|
| String[] fws = iFT.getFrameWorkManager().getAllFrameWorks();
|
| for (int i=0; i<fws.length; i++)
|
| {
|
| IFramework fw = iFT.getFrameWorkManager().getFramework(fws[i]);
|
| String pf = new File(fw.getCurrentFilename()).getName();
|
| TreeParent p = new TreeParent(fws[i]+" ("+pf+")", fw);
|
| TreeParent cf = new TreeParent("Full filename", null);
|
| TreeObject o = new TreeObject(fw.getCurrentFilename(), null);
|
| cf.addChild(o);
|
| p.addChild(cf);
|
|
|
| TreeParent pmp = new TreeParent("Program models", null);
|
| for (Object machine : fw.getMachines())
|
| {
|
| TreeObject to = new TreeObject(machine.toString(), machine);
|
| pmp.addChild(to);
|
| }
|
| p.addChild(pmp);
|
|
|
| TreeParent pp = new TreeParent("Property providers", null);
|
| for (String pid : fw.getProperties().getAllProviderIDs())
|
| {
|
| TreeObject to = new TreeObject(pid, null);
|
| pp.addChild(to);
|
| }
|
| p.addChild(pp);
|
| TreeParent ni = new TreeParent("Native importers", null);
|
| for (String iid : fw.getNativeImporters().keySet())
|
| {
|
| TreeObject to = new TreeObject(iid, null);
|
| ni.addChild(to);
|
| }
|
| p.addChild(ni);
|
| invisibleRoot.addChild(p);
|
| }
|
| }
|
| */
|
|
|
| }
|