/** * Copyright (c) 2012-2016 Marsha Chechik, Alessio Di Sandro, Michalis Famelis, * Rick Salay. * 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: * Alessio Di Sandro - Implementation. */ package edu.toronto.cs.se.mmint.mid.ui; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; import edu.toronto.cs.se.mmint.mid.MID; import edu.toronto.cs.se.mmint.mid.Model; import edu.toronto.cs.se.mmint.mid.relationship.ModelRel; public class NewWorkflowModelDialogContentProvider implements ITreeContentProvider { private MID mid; public NewWorkflowModelDialogContentProvider(MID mid) { this.mid = mid; } /** * {@inheritDoc} * This implementation does nothing. */ @Override public void dispose() { // do nothing } /** * {@inheritDoc} * This implementation does nothing. */ @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing } /** * {@inheritDoc} */ @Override public Object[] getElements(Object inputElement) { return getChildren(inputElement); } /** * {@inheritDoc} */ @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof MID) { List<Model> modelTypes = new ArrayList<>(); for (Model modelType : ((MID) parentElement).getModels()) { if (modelType instanceof ModelRel || modelType.isAbstract()) { continue; } modelTypes.add(modelType); } return modelTypes.toArray(); } return new Object[] {}; } /** * {@inheritDoc} */ @Override public Object getParent(Object element) { if (element instanceof Model) { return mid; } return null; } /** * {@inheritDoc} */ @Override public boolean hasChildren(Object element) { if (element instanceof MID) { return !((MID) element).getModels().isEmpty(); } return false; } }