1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.jfreechart.chart.properties;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
17 import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
\r
18 import org.eclipse.swt.widgets.Control;
\r
19 import org.simantics.browsing.ui.swt.widgets.impl.Widget;
\r
20 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.management.ISessionContext;
\r
23 import org.simantics.db.procedure.Listener;
\r
24 import org.simantics.ui.SimanticsUI;
\r
25 import org.simantics.ui.utils.AdaptionUtils;
\r
26 import org.simantics.utils.datastructures.Pair;
\r
29 * Provides all variables a model contains
\r
31 * @author Teemu Lempinen
\r
34 public class VariableProposalProvider extends IdLabelProposalProvider implements Widget {
\r
37 * Provides all variables a model contains. Given resource needs to be
\r
38 * part of a model (i.e. using PartOf leads eventually to a SysdynModel).
\r
40 * @param control Control that is using this provider
\r
41 * @param resource A resource that is part of a model
\r
43 public VariableProposalProvider(final Control control, WidgetSupport support) {
\r
44 super(new ArrayList<ChartVariable>());// super(String [] {});
\r
45 support.register(this);
\r
46 this.control = control;
\r
49 private Resource resource;
\r
50 private Control control;
\r
53 public void setInput(ISessionContext context, Object input) {
\r
55 final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class);
\r
56 if(resource == null)
\r
58 this.resource = resource;
\r
60 SimanticsUI.getSession().asyncRequest(
\r
61 new AllVariablesOfModel(resource)
\r
62 , new Listener<Collection<ChartVariable>>() {
\r
65 public void execute(Collection<ChartVariable> result) {
\r
66 setProposals(result);
\r
70 public void exception(Throwable t) {
\r
71 t.printStackTrace();
\r
75 public boolean isDisposed() {
\r
76 return control == null ||
\r
77 control.isDisposed() ||
\r
78 !resource.equals(VariableProposalProvider.this.resource);
\r