Skip to main content
summaryrefslogtreecommitdiffstats
blob: 155b4f04e7602d16c128f04291d193bce3a992a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2004, 2006 IBM Corporation and others.
 * 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:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060524   141194 joan@ca.ibm.com - Joan Haggarty
 *******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.ui.widgets.object;

import java.util.Vector;

import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jst.ws.internal.consumption.ui.ConsumptionUIMessages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

public class EJBTableViewer extends TableViewer
{
  private Vector beanNames;
  private Vector projectNames;

  public EJBTableViewer(Composite parent)
  {
    super(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    
    String columnProperties[] = {ConsumptionUIMessages.TABLE_TITLE_EJB_BEAN_NAMES, ConsumptionUIMessages.TABLE_TITLE_EJB_PROJECT_NAME};
    int columnsWidth[] = {60, 20};
    int columnMins[] = {175, 125};
    
    Table table = getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableLayout layout = new TableLayout();
    for (int i = 0; i < columnProperties.length; i++)
    {
      TableColumn column = new TableColumn(table, SWT.NONE, i);
      column.setText(columnProperties[i]);
      column.pack();
      layout.addColumnData(new ColumnWeightData(columnsWidth[i], columnMins[i], true));      
    }
    table.setLayout(layout);
    setColumnProperties(columnProperties);
    setContentProvider(new EJBContentProvider());
    setLabelProvider(new EJBLabelProvider());
  }
  
  public void setData(Vector beanNames, Vector projectNames)
  {
    this.beanNames = beanNames;
    this.projectNames = projectNames;
  }
  private class EJBLabelProvider extends LabelProvider implements ITableLabelProvider
  {
    public String getColumnText(Object object, int columnIndex)
    {
      String result = null;
      if (object instanceof Integer)
      {
        int index = ((Integer) object).intValue();
        if (columnIndex == 0)
        {
          return (String) (beanNames.elementAt(index));
        }
        else if (columnIndex == 1)
        {
          return (String) (projectNames.elementAt(index));
        }
      }
      return result;
    }

    public Image getColumnImage(Object object, int columnIndex)
    {
      return null;
    }
  }
  public class EJBContentProvider implements IStructuredContentProvider
  {
    public Object[] getElements(Object element)
    {
      if (beanNames != null)
      {
        int size = beanNames.size();
        Object[] result = new Object[size];
        for (int index = 0; index < size; index++)
        {
          result[index] = new Integer(index);
        }
        return result;
      }
      return null;
    }

    public void dispose()
    {
    }

    public void inputChanged(Viewer viewer, Object old, Object newobj)
    {
    }

    public boolean isDeleted(Object object)
    {
      return false;
    }
  }
}

Back to the top