Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7f267f000f6e7b232619a1dbda57017a07e1487b (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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*******************************************************************************
 * 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.ats.view.web.components;

import org.eclipse.osee.ats.api.components.AtsSearchHeaderComponentInterface;
import org.eclipse.osee.ats.api.search.AtsSearchPresenter;
import org.eclipse.osee.ats.view.web.AtsNavigator;
import org.eclipse.osee.ats.view.web.AtsUiApplication;
import org.eclipse.osee.ats.view.web.search.AtsSearchHomeView;
import org.eclipse.osee.display.api.data.WebId;
import org.eclipse.osee.display.view.web.CssConstants;
import org.eclipse.osee.display.view.web.components.OseeLogoLink;
import org.eclipse.osee.display.view.web.search.OseeSearchHeaderComponent;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

/**
 * @author Shawn F. Cook
 */
@SuppressWarnings("serial")
public class AtsSearchHeaderComponent extends OseeSearchHeaderComponent implements AtsSearchHeaderComponentInterface, Handler {

   private boolean populated = false;
   private final ComboBox programCombo;
   private final ComboBox buildCombo;
   private final CheckBox nameOnlyCheckBox;
   private final TextField searchTextField;
   private AtsSearchPresenter searchPresenter;
   private AtsNavigator navigator;
   private boolean lockProgramCombo = false;

   @Override
   public void attach() {
      if (!populated) {
         try {
            AtsUiApplication app = (AtsUiApplication) this.getApplication();
            searchPresenter = app.getAtsWebSearchPresenter();
            navigator = app.getAtsNavigator();
         } catch (Exception e) {
            System.out.println("OseeArtifactNameLinkComponent.attach - CRITICAL ERROR: (AtsUiApplication) this.getApplication() threw an exception.");
         }
      }
      createLayout();
      populated = true;
   }

   private void selectSearch() {
      WebId program = (WebId) programCombo.getValue();
      searchPresenter.selectProgram(program, this);
   }

   public AtsSearchHeaderComponent(boolean showOseeTitleAbove) {
      this.showOseeTitleAbove = showOseeTitleAbove;

      programCombo = new ComboBox("Program:");
      buildCombo = new ComboBox("Build:");
      nameOnlyCheckBox = new CheckBox("Name Only", false);
      searchTextField = new TextField();

      if (programCombo != null) {
         programCombo.setNullSelectionAllowed(false);
         programCombo.addListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
               if (!lockProgramCombo) {
                  selectSearch();
               }
            }
         });
         programCombo.setImmediate(true);
      }
      if (buildCombo != null) {
         buildCombo.setNullSelectionAllowed(false);
      }

      searchTextField.setImmediate(true);
   }

   public AtsSearchHeaderComponent() {
      this(true);
   }

   @Override
   public void createLayout() {
      this.removeAllComponents();
      setHeight(null);
      setWidth(100, UNITS_PERCENTAGE);
      setStyleName(CssConstants.OSEE_SEARCH_HEADER_COMPONENT);

      HorizontalLayout hLayoutRow0 = new HorizontalLayout();
      HorizontalLayout hLayoutRow1 = new HorizontalLayout();
      HorizontalLayout hLayoutRow2 = new HorizontalLayout();

      //      Embedded oseeTitleLabel = new Embedded("", new ThemeResource("../osee/osee_large.png"));
      //      oseeTitleLabel.setType(Embedded.TYPE_IMAGE);

      Label spacer1 = new Label("");
      spacer1.setHeight(null);
      spacer1.setWidth(30, UNITS_PIXELS);
      Label spacer2 = new Label("");
      spacer2.setHeight(null);
      spacer2.setWidth(30, UNITS_PIXELS);
      hLayoutRow1.addComponent(programCombo);
      hLayoutRow1.addComponent(spacer1);
      hLayoutRow1.addComponent(buildCombo);
      hLayoutRow1.addComponent(spacer2);
      hLayoutRow1.addComponent(nameOnlyCheckBox);
      hLayoutRow1.setComponentAlignment(programCombo, Alignment.MIDDLE_LEFT);
      hLayoutRow1.setComponentAlignment(buildCombo, Alignment.MIDDLE_CENTER);
      hLayoutRow1.setComponentAlignment(nameOnlyCheckBox, Alignment.BOTTOM_RIGHT);

      searchTextField.setStyleName(CssConstants.OSEE_SEARCH_TEXTFIELD);
      Label spacer3 = new Label("");
      spacer3.setHeight(null);
      spacer3.setWidth(30, UNITS_PIXELS);
      Button searchButton = new Button("Search", new Button.ClickListener() {
         @Override
         public void buttonClick(ClickEvent event) {
            WebId program = (WebId) programCombo.getValue();
            WebId build = (WebId) buildCombo.getValue();
            boolean nameOnly = nameOnlyCheckBox.toString().equalsIgnoreCase("true");
            String searchPhrase = (String) searchTextField.getValue();
            if (searchPresenter != null) {
               searchPresenter.selectSearch(program, build, nameOnly, searchPhrase, navigator);
            }
         }
      });
      hLayoutRow2.addComponent(searchTextField);
      hLayoutRow2.addComponent(spacer3);
      hLayoutRow2.addComponent(searchButton);
      hLayoutRow2.setComponentAlignment(searchTextField, Alignment.MIDDLE_LEFT);
      hLayoutRow2.setComponentAlignment(searchButton, Alignment.MIDDLE_RIGHT);

      if (showOseeTitleAbove) {
         OseeLogoLink oseeTitleLabel =
            new OseeLogoLink(navigator, CssConstants.OSEE_TITLE_LARGE_TEXT, AtsSearchHomeView.class);
         hLayoutRow0.addComponent(oseeTitleLabel);
         hLayoutRow0.setComponentAlignment(oseeTitleLabel, Alignment.MIDDLE_CENTER);
         oseeTitleLabel.setStyleName(CssConstants.OSEE_TITLE_LARGE_TEXT);
         hLayoutRow0.setHeight(oseeTitleLabel.getHeight(), UNITS_PIXELS);

         addComponent(hLayoutRow0);
         addComponent(hLayoutRow1);
         addComponent(hLayoutRow2);

         hLayoutRow1.setMargin(true);

         setComponentAlignment(hLayoutRow0, Alignment.MIDDLE_CENTER);
         setComponentAlignment(hLayoutRow1, Alignment.MIDDLE_CENTER);
         setComponentAlignment(hLayoutRow2, Alignment.MIDDLE_CENTER);
      } else {
         OseeLogoLink oseeTitleLabel =
            new OseeLogoLink(navigator, CssConstants.OSEE_TITLE_MEDIUM_TEXT, AtsSearchHomeView.class);
         Label spacer4 = new Label("");
         spacer4.setWidth(15, UNITS_PIXELS);
         oseeTitleLabel.setHeight(70, UNITS_PIXELS);
         oseeTitleLabel.setWidth(70, UNITS_PIXELS);

         VerticalLayout rightSideVLayout = new VerticalLayout();
         rightSideVLayout.addComponent(hLayoutRow1);
         rightSideVLayout.addComponent(hLayoutRow2);
         rightSideVLayout.setSizeUndefined();

         //TODO: Make the title logo a hyper link to the search home

         hLayoutRow0.addComponent(oseeTitleLabel);
         hLayoutRow0.addComponent(spacer4);
         hLayoutRow0.addComponent(rightSideVLayout);
         hLayoutRow0.setComponentAlignment(oseeTitleLabel, Alignment.TOP_CENTER);
         hLayoutRow0.setComponentAlignment(rightSideVLayout, Alignment.TOP_CENTER);

         Label spacer5 = new Label("");
         spacer5.setHeight(15, UNITS_PIXELS);
         spacer5.setStyleName(CssConstants.OSEE_HORIZONTAL_LINE);

         addComponent(hLayoutRow0);
         addComponent(spacer5);
      }
   }

   @Override
   public void addProgram(WebId program) {
      if (programCombo != null) {
         lockProgramCombo = true;
         programCombo.addItem(program);
         lockProgramCombo = false;
      }
   }

   @Override
   public void clearBuilds() {
      if (buildCombo != null) {
         buildCombo.removeAllItems();
      }
   }

   @Override
   public void addBuild(WebId build) {
      if (buildCombo != null) {
         buildCombo.addItem(build);
      }
   }

   @Override
   public void setSearchCriteria(WebId program, WebId build, boolean nameOnly, String searchPhrase) {
      if (programCombo != null) {
         lockProgramCombo = true;
         programCombo.setValue(program);
         lockProgramCombo = false;
      }
      if (buildCombo != null) {
         buildCombo.setValue(build);
      }
      if (nameOnlyCheckBox != null) {
         nameOnlyCheckBox.setValue(nameOnly);
      }
      if (searchTextField != null) {
         searchTextField.setValue(searchPhrase);
      }
   }

   @Override
   public void clearAll() {
      if (programCombo != null) {
         //         programCombo.removeAllItems();
         programCombo.setValue(null);
      }
      if (buildCombo != null) {
         //         buildCombo.removeAllItems();
         buildCombo.setValue(null);
      }
      if (nameOnlyCheckBox != null) {
         nameOnlyCheckBox.setValue(false);
      }
      if (searchTextField != null) {
         searchTextField.setValue("");
      }
   }

   @Override
   public void setProgram(WebId program) {
      if (programCombo != null) {
         programCombo.setValue(program);
      }
   }

   @Override
   public void setBuild(WebId build) {
      if (buildCombo != null) {
         buildCombo.setValue(build);
      }
   }

   @Override
   public void setErrorMessage(String message) {
      //TODO:
   }

   //TODO: None of this works because Vaadin only supports key actions for Windows and Panel Objects. (this is
   // a Component)
   private final Action action_enter = new ShortcutAction("Enter key", ShortcutAction.KeyCode.ENTER, null);
   private final Action[] actions = new Action[] {action_enter};

   @Override
   public Action[] getActions(Object target, Object sender) {
      if (sender == searchTextField) {
         return actions;
      }
      return null;
   }

   @Override
   public void handleAction(Action action, Object sender, Object target) {
      if (sender == searchTextField && action == action_enter) {
         selectSearch();
      }
   }

}

Back to the top