Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0224e6efcad54d4244fea6fcc156bdeb23a6db9a (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.admin.dbtabletab;

import java.util.ArrayList;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.ui.admin.Activator;
import org.eclipse.osee.framework.ui.admin.AdminView;
import org.eclipse.osee.framework.ui.skynet.widgets.XCombo;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class DbTableTab {
   protected Browser browser;
   public static final String VIEW_ID = "org.eclipse.osee.framework.ui.admin.AdminView";
   public static User person;
   public static DbTableViewer dbTableViewer;
   private static XCombo filterCombo;
   private final Label readOnlyLabel, addRecordLabel, publishLabel;
   private final ArrayList<DbItem> dbItems;
   private final Cursor handCursor;
   private boolean noListener = true;
   private final Composite parent;

   public DbTableTab(TabFolder tabFolder) {
      super();

      dbItems = new ArrayList<DbItem>();
      dbItems.add(new SiteGssflRpcr());
      dbItems.add(new OseeInfoDbItem());
      handCursor = new Cursor(null, SWT.CURSOR_HAND);

      TabItem dbTab = new TabItem(tabFolder, SWT.NULL);
      dbTab.setText("Database");

      // Filter Composite
      int numColumns = 5;
      Composite c = new Composite(tabFolder, SWT.NONE);
      c.setLayout(new GridLayout(numColumns, false));
      c.setLayoutData(new GridData());

      c.setLayoutData(new GridData(GridData.FILL_BOTH));
      this.parent = c;

      filterCombo = new XCombo("DB Table");
      filterCombo.setDataStrings(getDbTableNames());
      filterCombo.createWidgets(c, 2);
      filterCombo.addModifyListener(new ModifyListener() {

         @Override
         public void modifyText(ModifyEvent e) {
            try {
               handleTableSelect();
            } catch (OseeCoreException ex) {
               OseeLog.log(Activator.class, Level.SEVERE, ex);
            }
            AdminView.setSaveNeeded(false);
         }
      });

      readOnlyLabel = new Label(c, SWT.NONE);
      readOnlyLabel.setForeground(Displays.getSystemColor(SWT.COLOR_RED));

      addRecordLabel = new Label(c, SWT.NONE);
      addRecordLabel.setForeground(Displays.getSystemColor(SWT.COLOR_BLUE));
      addRecordLabel.addMouseTrackListener(new MouseTrackListener() {

         @Override
         public void mouseEnter(MouseEvent e) {
            if (getSelectedDbItem() != null && getSelectedDbItem().isWriteAccess()) {
               if (addRecordLabel != null) {
                  addRecordLabel.setCursor(handCursor);
               }
            }
         }

         @Override
         public void mouseExit(MouseEvent e) {
            if (addRecordLabel != null) {
               addRecordLabel.setCursor(null);
            }
         };

         @Override
         public void mouseHover(MouseEvent e) {
            // do nothing
         }
      });

      publishLabel = new Label(c, SWT.NONE);
      publishLabel.setForeground(Displays.getSystemColor(SWT.COLOR_BLUE));
      publishLabel.addMouseTrackListener(new MouseTrackListener() {

         @Override
         public void mouseEnter(MouseEvent e) {
            if (getSelectedDbItem() != null && getSelectedDbItem().isWriteAccess()) {
               if (publishLabel != null) {
                  publishLabel.setCursor(handCursor);
               }
            }
         }

         @Override
         public void mouseExit(MouseEvent e) {
            if (publishLabel != null) {
               publishLabel.setCursor(null);
            }
         };

         @Override
         public void mouseHover(MouseEvent e) {
            // do nothing
         }
      });

      updateReadOnly();
      dbTab.setControl(c);
   }

   Listener addRecordListener = new Listener() {
      @Override
      public void handleEvent(org.eclipse.swt.widgets.Event event) {
         System.out.println("I am adding a row...");
         handleAddRecord();
      };
   };

   public void handleAddRecord() {
      System.out.println("trying to add a record");
      dbTableViewer.addRecord();
   }

   public void updateReadOnly() {
      DbItem selItem = getSelectedDbItem();
      if (selItem == null) {
         readOnlyLabel.setText("");
         addRecordLabel.setText("                ");
      } else if (selItem.isWriteAccess()) {
         readOnlyLabel.setText("    WRITE ACCESS");
         addRecordLabel.setText("   Add Record   ");

         if (noListener) {
            addRecordLabel.addListener(SWT.MouseUp, addRecordListener);
         }
         noListener = false;
      } else {
         readOnlyLabel.setText("    READ ONLY ACCESS");
         addRecordLabel.setText("                ");
         addRecordLabel.removeListener(SWT.MouseUp, addRecordListener);
      }
   }

   public DbItem getSelectedDbItem() {
      for (DbItem d : dbItems) {
         if (filterCombo.get().equals(d.getTableName())) {
            return d;
         }
      }
      return null;
   }

   public void handleTableSelect() throws OseeCoreException {
      if (dbTableViewer != null) {
         dbTableViewer.dispose();
      }
      updateReadOnly();
      if (filterCombo.get().equals("")) {
         return;
      }

      dbTableViewer = new DbTableViewer(parent, 5, this, getSelectedDbItem());
      dbTableViewer.load();
      parent.layout();
   }

   public static void refresh() throws OseeCoreException {
      if (filterCombo.get().equals("")) {
         return;
      }
      if (dbTableViewer != null) {
         dbTableViewer.load();
         dbTableViewer.refresh();
      }
   }

   public XCombo getFilterCombo() {
      return filterCombo;
   }

   public String[] getDbTableNames() {
      String names[] = new String[dbItems.size()];
      for (int x = 0; x < dbItems.size(); x++) {
         names[x] = dbItems.get(x).getTableName();
      }
      return names;
   }

}

Back to the top