Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4d4b8dbfb13e6a3ba39a1fe042d12a2bbd4c70be (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*******************************************************************************
 * Copyright (c) 2011 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.display.view.web.components;

import org.eclipse.osee.display.api.components.RelationComponent;
import org.eclipse.osee.display.api.data.ViewArtifact;
import org.eclipse.osee.display.api.data.ViewId;
import org.eclipse.osee.display.api.search.SearchNavigator;
import org.eclipse.osee.display.api.search.SearchPresenter;
import org.eclipse.osee.display.view.web.CssConstants;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.VerticalLayout;

/**
 * @author Shawn F. Cook
 */
@SuppressWarnings("serial")
public class OseeRelationsComponent extends VerticalLayout implements RelationComponent {

   private final ListSelect relTypesSelect = new ListSelect();
   private final ListSelect leftSelect = new ListSelect();
   private final ListSelect rightSelect = new ListSelect();
   private boolean lockRelTypesListener = false;
   private boolean lockRelsListener = false;
   private ViewArtifact artifact = null;
   private final int LISTBOX_MINWIDTH = 100;
   private final Label leftTitle = new Label("");
   private final Label relTypesTitle = new Label("Relation Type");
   private final Label rightTitle = new Label("");

   @Override
   public void attach() {
      createLayout();
   }

   private void createLayout() {
      setSizeUndefined();
      removeAllComponents();

      final HorizontalLayout listBoxesLayout = new HorizontalLayout();

      Label titleLabel = new Label("Relations");
      titleLabel.setStyleName(CssConstants.OSEE_ATTRIBUTESTITLELABEL);

      leftTitle.setStyleName(CssConstants.OSEE_ATTRIBUTELABEL);
      relTypesTitle.setStyleName(CssConstants.OSEE_ATTRIBUTELABEL);
      rightTitle.setStyleName(CssConstants.OSEE_ATTRIBUTELABEL);

      //Fixed width lists make for a prettier layout
      relTypesSelect.setWidth(LISTBOX_MINWIDTH, UNITS_PIXELS);
      leftSelect.setWidth(LISTBOX_MINWIDTH, UNITS_PIXELS);
      rightSelect.setWidth(LISTBOX_MINWIDTH, UNITS_PIXELS);

      relTypesSelect.setNullSelectionAllowed(false);
      relTypesSelect.setImmediate(true);

      leftSelect.setNullSelectionAllowed(false);
      leftSelect.setImmediate(true);

      rightSelect.setNullSelectionAllowed(false);
      rightSelect.setImmediate(true);

      relTypesSelect.addListener(new Property.ValueChangeListener() {
         @Override
         public void valueChange(ValueChangeEvent event) {
            if (!lockRelTypesListener) {
               try {
                  ViewId relationType = (ViewId) relTypesSelect.getValue();
                  if (relationType != null) {
                     SearchPresenter<?, ?> presenter = ComponentUtility.getPresenter(OseeRelationsComponent.this);
                     presenter.selectRelationType(artifact, relationType, OseeRelationsComponent.this);
                  }
               } catch (Exception e) {
                  ComponentUtility.logError(
                     "OseeRelationsComponent.createLayout - CRITICAL ERROR: (WebArtifact) relationsListSelect.getValue() threw an exception:" + e.getMessage() + e.getStackTrace(),
                     OseeRelationsComponent.this);
               }
            }
         }
      });

      leftSelect.addListener(new Property.ValueChangeListener() {
         @Override
         public void valueChange(ValueChangeEvent event) {
            if (!lockRelsListener) {
               try {
                  ViewArtifact artifact = (ViewArtifact) leftSelect.getValue();
                  handleValue(artifact);
               } catch (Exception e) {
                  ComponentUtility.logError(
                     "OseeRelationsComponent.createLayout - CRITICAL ERROR: (WebArtifact) relationsListSelect.getValue() threw an exception.",
                     OseeRelationsComponent.this);
               }
            }
         }
      });

      rightSelect.addListener(new Property.ValueChangeListener() {
         @Override
         public void valueChange(ValueChangeEvent event) {
            if (!lockRelsListener) {
               try {
                  ViewArtifact artifact = (ViewArtifact) rightSelect.getValue();
                  handleValue(artifact);
               } catch (Exception e) {
                  ComponentUtility.logError(
                     "OseeRelationsComponent.createLayout - CRITICAL ERROR: (WebArtifact) relationsListSelect.getValue() threw an exception.",
                     OseeRelationsComponent.this);
               }
            }
         }
      });

      VerticalLayout vLayout_LeftSelect = new VerticalLayout();
      VerticalLayout vLayout_RelTypesSelect = new VerticalLayout();
      VerticalLayout vLayout_RightSelect = new VerticalLayout();

      vLayout_LeftSelect.addComponent(leftTitle);
      vLayout_LeftSelect.addComponent(leftSelect);

      vLayout_RelTypesSelect.addComponent(relTypesTitle);
      vLayout_RelTypesSelect.addComponent(relTypesSelect);

      vLayout_RightSelect.addComponent(rightTitle);
      vLayout_RightSelect.addComponent(rightSelect);

      Label spacer = new Label();
      spacer.setWidth(15, UNITS_PIXELS);

      Label leftArrow = new Label();
      leftArrow.setStyleName(CssConstants.OSEE_LEFTARROW);

      Label rightArrow = new Label();
      rightArrow.setStyleName(CssConstants.OSEE_RIGHTARROW);

      listBoxesLayout.addComponent(spacer);
      listBoxesLayout.addComponent(vLayout_LeftSelect);
      listBoxesLayout.addComponent(leftArrow);
      listBoxesLayout.addComponent(vLayout_RelTypesSelect);
      listBoxesLayout.addComponent(rightArrow);
      listBoxesLayout.addComponent(vLayout_RightSelect);

      addComponent(titleLabel);
      addComponent(listBoxesLayout);

      vLayout_LeftSelect.setComponentAlignment(leftTitle, Alignment.BOTTOM_CENTER);
      vLayout_LeftSelect.setComponentAlignment(leftSelect, Alignment.BOTTOM_CENTER);
      vLayout_RelTypesSelect.setComponentAlignment(relTypesSelect, Alignment.BOTTOM_CENTER);
      vLayout_RelTypesSelect.setComponentAlignment(relTypesTitle, Alignment.MIDDLE_CENTER);
      vLayout_RightSelect.setComponentAlignment(rightTitle, Alignment.BOTTOM_CENTER);
      vLayout_RightSelect.setComponentAlignment(rightSelect, Alignment.BOTTOM_CENTER);
      listBoxesLayout.setComponentAlignment(vLayout_LeftSelect, Alignment.BOTTOM_CENTER);
      listBoxesLayout.setComponentAlignment(vLayout_RelTypesSelect, Alignment.BOTTOM_CENTER);
      listBoxesLayout.setComponentAlignment(vLayout_RightSelect, Alignment.BOTTOM_CENTER);
      listBoxesLayout.setComponentAlignment(rightArrow, Alignment.MIDDLE_CENTER);
      listBoxesLayout.setComponentAlignment(leftArrow, Alignment.MIDDLE_CENTER);
      setExpandRatio(listBoxesLayout, 1.0f);
   }

   private void handleValue(ViewArtifact artifact) {
      if (artifact != null) {
         String url = ComponentUtility.getUrl(OseeRelationsComponent.this);
         SearchPresenter<?, ?> presenter = ComponentUtility.getPresenter(OseeRelationsComponent.this);
         SearchNavigator navigator = ComponentUtility.getNavigator(OseeRelationsComponent.this);
         presenter.selectArtifact(url, artifact, navigator);
      } else {
         ComponentUtility.logWarn("OseeRelationsComponent.handleValue - WARNING: null value detected.", this);
      }
   }

   public OseeRelationsComponent() {
      createLayout();
   }

   @Override
   public void clearAll() {
      this.addRelationType(null);
      this.clearRelations();
   }

   @Override
   public void addRelationType(ViewId id) {
      if (id == null) {
         relTypesSelect.setEnabled(false);
         relTypesSelect.removeAllItems();
         relTypesSelect.setWidth(LISTBOX_MINWIDTH, UNITS_PIXELS);
      } else {
         relTypesSelect.setEnabled(true);
         if (relTypesSelect != null) {
            lockRelTypesListener = true;
            relTypesSelect.addItem(id);
            relTypesSelect.setWidth(null);
            lockRelTypesListener = false;
         }
      }
   }

   @Override
   public void clearRelations() {
      this.addLeftRelated(null);
      this.addRightRelated(null);
      this.setLeftName(null);
      this.setRightName(null);
   }

   @Override
   public void setErrorMessage(String shortMsg, String longMsg, MsgType msgType) {
      OseeExceptionDialogComponent dlg =
         new OseeExceptionDialogComponent(msgType, shortMsg, longMsg, getApplication().getMainWindow());
   }

   @Override
   public void setArtifact(ViewArtifact artifact) {
      this.artifact = artifact;
   }

   @Override
   public void addLeftRelated(ViewArtifact id) {
      if (id == null) {
         leftSelect.setEnabled(false);
         leftSelect.removeAllItems();
         leftSelect.setWidth(LISTBOX_MINWIDTH, UNITS_PIXELS);
      } else {
         leftSelect.setEnabled(true);
         if (leftSelect != null) {
            lockRelsListener = true;
            leftSelect.addItem(id);
            leftSelect.setWidth(null);
            lockRelsListener = false;
         }
      }
   }

   @Override
   public void addRightRelated(ViewArtifact id) {
      if (id == null) {
         rightSelect.setEnabled(false);
         rightSelect.removeAllItems();
         rightSelect.setWidth(LISTBOX_MINWIDTH, UNITS_PIXELS);
      } else {
         rightSelect.setEnabled(true);
         if (rightSelect != null) {
            lockRelsListener = true;
            rightSelect.addItem(id);
            rightSelect.setWidth(null);
            lockRelsListener = false;
         }
      }
   }

   @Override
   public void setLeftName(String name) {
      if (name == null) {
         leftSelect.setEnabled(false);
         leftTitle.setValue("");
      } else {
         leftSelect.setEnabled(true);
         leftTitle.setValue(name);
      }
   }

   @Override
   public void setRightName(String name) {
      if (name == null) {
         rightSelect.setEnabled(false);
         rightTitle.setValue("");
      } else {
         rightSelect.setEnabled(true);
         rightTitle.setValue(name);
      }
   }
}

Back to the top