• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /barrelfish-2018-10-04/usr/eclipseclp/Visualisation/src/com/parctechnologies/eclipse/visualisation/viewers/
1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation.viewers;
24
25import com.parctechnologies.eclipse.visualisation.VisClientStateModel;
26import com.parctechnologies.eclipse.visualisation.ViewletFactory;
27import com.parctechnologies.eclipse.visualisation.ViewletType;
28import com.parctechnologies.eclipse.visualisation.ViewerFactory;
29import com.parctechnologies.eclipse.visualisation.ViewableType;
30import com.parctechnologies.eclipse.visualisation.ElementType;
31import com.parctechnologies.eclipse.visualisation.Viewer;
32import com.parctechnologies.eclipse.visualisation.Viewable;
33import com.parctechnologies.eclipse.visualisation.TableViewer;
34import com.parctechnologies.eclipse.visualisation.DebuggingSupport;
35
36/**
37 * Factory for building Lightweight TableViewers with specified viewlets
38 */
39public class TableViewerFactory implements ViewerFactory
40{
41  private VisClientStateModel stateModel;
42  private Class viewletTypeClass;
43  private Class elementTypeClass;
44
45  public TableViewerFactory(VisClientStateModel stateModel,
46                            Class viewletTypeClass,
47                            Class elementTypeClass)
48  {
49    this.stateModel = stateModel;
50    this.viewletTypeClass = viewletTypeClass;
51    this.elementTypeClass = elementTypeClass;
52  }
53
54  /**
55   * Note that only the dimensionrestriction affects the ability of a
56   * TextTableLight viewer to render a viewable
57   */
58  public boolean canBuildFrom(ViewableType viewableType)
59  {
60    if (!(viewableType instanceof ViewableType.ArrayType)) {
61      return false;
62    }
63    ViewableType.ArrayType arrayType = (ViewableType.ArrayType) viewableType;
64    if(arrayType.getNDimensions() >= 1 &&
65       arrayType.getNDimensions() < 3 )
66    {
67      if (elementTypeClass.isInstance(arrayType.getElementType())) {
68        // can the viewletType render this elementType
69        return(true);
70      }
71    }
72    return(false);
73  }
74
75  public Viewer build(Viewable viewable)
76  {
77    String changeable = null;
78    ViewableType viewableType = viewable.getType();
79    if (viewableType instanceof ViewableType.ArrayType) {
80      ElementType elementType =
81        ((ViewableType.ArrayType)viewableType).getElementType();
82      changeable = elementType.getChangeableSolver();
83    }
84    Class argClasses[] = {String.class};
85    Object argInstances[] = {changeable};
86    ViewletType viewletType;
87    try {
88      viewletType = (ViewletType)(viewletTypeClass.getConstructor(argClasses).newInstance(argInstances));
89    } catch(Exception e) {
90      if (DebuggingSupport.logMessages) {
91        e.printStackTrace(System.err);
92      }
93      throw new RuntimeException("Unable to construct viewlet type in TableViewerFactory:"+e);
94    }
95    Viewer newViewer =
96      new TableViewer(viewletType, stateModel, viewable);
97    newViewer.setDescription(viewletType.getDescription()+" table viewer");
98    return(newViewer);
99  }
100
101}
102