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.sysdyn.ui.trend.chart.properties;
\r
14 import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
\r
15 import org.eclipse.swt.widgets.Control;
\r
16 import org.simantics.browsing.ui.swt.widgets.impl.Widget;
\r
17 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.db.management.ISessionContext;
\r
20 import org.simantics.db.procedure.Listener;
\r
21 import org.simantics.ui.SimanticsUI;
\r
22 import org.simantics.ui.utils.AdaptionUtils;
\r
25 * Provides all variables a model contains
\r
27 * @author Teemu Lempinen
\r
30 public class VariableProposalProvider extends SimpleContentProposalProvider implements Widget {
\r
33 * Provides all variables a model contains. Given resource needs to be
\r
34 * part of a model (i.e. using PartOf leads eventually to a SysdynModel).
\r
36 * @param control Control that is using this provider
\r
37 * @param resource A resource that is part of a model
\r
39 public VariableProposalProvider(final Control control, WidgetSupport support) {
\r
40 super(new String [] {});
\r
41 support.register(this);
\r
42 this.control = control;
\r
45 private Resource resource;
\r
46 private Control control;
\r
49 public void setInput(ISessionContext context, Object input) {
\r
51 final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class);
\r
52 if(resource == null)
\r
54 this.resource = resource;
\r
56 SimanticsUI.getSession().asyncRequest(
\r
57 new AllVariablesOfModel(resource)
\r
58 , new Listener<String[]>() {
\r
61 public void execute(String[] result) {
\r
62 setProposals(result);
\r
66 public void exception(Throwable t) {
\r
67 t.printStackTrace();
\r
71 public boolean isDisposed() {
\r
72 return control == null ||
\r
73 control.isDisposed() ||
\r
74 !resource.equals(VariableProposalProvider.this.resource);
\r