Skip to main content
summaryrefslogtreecommitdiffstats
blob: 28f9b0b1063bc134a132f8232799021ea639cfb7 (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
/*******************************************************************************
 * Copyright (c) 2011 Boeing.
 * All rightsimport com.vaadin.Application;
import com.vaadin.service.ApplicationContext.TransactionListener;
he 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 java.util.ArrayList;
import java.util.Collection;
import org.eclipse.osee.display.api.components.AttributeComponent;
import org.eclipse.osee.display.view.web.CssConstants;
import com.vaadin.Application;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.Notification;

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

   private Collection<labelValuePair> attributes = new ArrayList<labelValuePair>();

   private class labelValuePair {
      private final String label;
      private final String value;

      public labelValuePair(String label, String value) {
         super();
         this.label = label;
         this.value = value;
      }

      @SuppressWarnings("unused")
      public String getLabel() {
         return label;
      }

      @SuppressWarnings("unused")
      public String getValue() {
         return value;
      }
   }

   private void createLayout() {
      removeAllComponents();

      final HorizontalLayout attributesLayout = new HorizontalLayout();

      //      final OseeShowHideButton showHideButton = new OseeShowHideButton("Attributes");
      //      showHideButton.addListener(new OseeShowHideButton.ClickListener() {
      //         @Override
      //         public void buttonClick(OseeShowHideButton.ClickEvent event) {
      //            attributesLayout.setVisible(showHideButton.isStateShow());
      //         }
      //      });
      //      attributesLayout.setVisible(showHideButton.isStateShow());

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

      VerticalLayout attrLabelsLayout = new VerticalLayout();
      VerticalLayout attrValuesLayout = new VerticalLayout();

      for (labelValuePair pair : attributes) {
         Label attrLabel = new Label(String.format("%s:", pair.getLabel()));
         Label attrValue = new Label(pair.getValue());
         attrLabel.setStyleName(CssConstants.OSEE_ATTRIBUTELABEL);
         attrValue.setStyleName(CssConstants.OSEE_ATTRIBUTEVALUE);

         attrLabelsLayout.addComponent(attrLabel);
         attrValuesLayout.addComponent(attrValue);
      }

      Label spacer = new Label("");
      spacer.setWidth(15, UNITS_PIXELS);
      Label spacer2 = new Label("");
      spacer2.setWidth(15, UNITS_PIXELS);
      attributesLayout.addComponent(spacer);
      attributesLayout.addComponent(attrLabelsLayout);
      attributesLayout.addComponent(spacer2);
      attributesLayout.addComponent(attrValuesLayout);

      addComponent(titleLabel);
      //      addComponent(showHideButton);
      addComponent(attributesLayout);
      setExpandRatio(attributesLayout, 1.0f);

      attrLabelsLayout.setWidth(200, UNITS_PIXELS);
      attrValuesLayout.setWidth(200, UNITS_PIXELS);
   }

   @Override
   public void clearAll() {
      attributes.clear();
      createLayout();
   }

   @Override
   public void setErrorMessage(String message) {
      Application app = this.getApplication();
      if (app != null) {
         Window mainWindow = app.getMainWindow();
         if (mainWindow != null) {
            mainWindow.showNotification(message, Notification.TYPE_ERROR_MESSAGE);
         } else {
            System.out.println("OseeAttributeComponent.setErrorMessage - ERROR: Application.getMainWindow() returns null value.");
         }
      } else {
         System.out.println("OseeAttributeComponent.setErrorMessage - ERROR: getApplication() returns null value.");
      }
   }

   @Override
   public void addAttribute(String type, String value) {
      if (type != null && !type.isEmpty() && value != null && !value.isEmpty()) {
         attributes.add(new labelValuePair(type, value));
      }
      createLayout();
   }

}

Back to the top