Skip to main content
summaryrefslogtreecommitdiffstats
blob: d60a87e1f5309b19ba3fcc00e7f663b922f10055 (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
/*******************************************************************************
 * 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.SearchHeaderComponent;
import org.eclipse.osee.display.api.components.SearchResultComponent;
import org.eclipse.osee.display.api.data.DisplayOptions;
import org.eclipse.osee.display.api.data.SearchResultMatch;
import org.eclipse.osee.display.api.data.StyledText;
import org.eclipse.osee.display.api.data.ViewArtifact;
import org.eclipse.osee.display.api.data.ViewSearchParameters;
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.ui.Alignment;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

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

   private ViewArtifact artifact;
   private final OseeArtifactNameLinkComponent artifactName = new OseeArtifactNameLinkComponent();
   private final OseeBreadcrumbComponent breadcrumbComp = new OseeBreadcrumbComponent();
   private final VerticalLayout vLayout_Matches = new VerticalLayout();
   private final Label artifactType = new Label("", Label.CONTENT_XHTML);
   private final int TOPBOTTOM_VERT_SPACE = 8;
   private boolean isLayoutComplete = false;
   private SearchPresenter<SearchHeaderComponent, ViewSearchParameters> searchPresenter;
   private SearchNavigator navigator;

   @Override
   public void attach() {
      if (!isLayoutComplete) {
         createLayout();
         isLayoutComplete = true;
      }
   }

   private void createLayout() {
      setSizeUndefined();

      HorizontalLayout row0 = new HorizontalLayout();

      Label spacer1 = new Label("");
      spacer1.setHeight(null);
      spacer1.setWidth(15, UNITS_PIXELS);
      artifactType.setStyleName(CssConstants.OSEE_SEARCHRESULT_ARTTYPE);

      Label bottomSpacer = new Label("");
      bottomSpacer.setHeight(TOPBOTTOM_VERT_SPACE, UNITS_PIXELS);

      Label topSpacer = new Label("");
      topSpacer.setHeight(TOPBOTTOM_VERT_SPACE, UNITS_PIXELS);

      row0.addComponent(artifactName);
      row0.addComponent(spacer1);
      row0.addComponent(artifactType);

      addComponent(topSpacer);
      addComponent(row0);

      addComponent(breadcrumbComp);

      addComponent(vLayout_Matches);
      addComponent(bottomSpacer);

      row0.setComponentAlignment(artifactName, Alignment.BOTTOM_LEFT);
      row0.setComponentAlignment(artifactType, Alignment.MIDDLE_LEFT);
   }

   private static int i = 0;

   @Override
   public void setArtifact(ViewArtifact artifact) {
      this.artifact = artifact;
      artifactName.setArtifact(this.artifact);
      breadcrumbComp.setArtifact(this.artifact);
      artifactType.setCaption(String.format("[%s]", artifact.getArtifactType()));

   }

   @Override
   public void addSearchResultMatch(SearchResultMatch match) {
      OseeSearchResultMatchComponent matchComp = new OseeSearchResultMatchComponent(match);
      vLayout_Matches.addComponent(matchComp);
   }

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

   @Override
   public void setDisplayOptions(DisplayOptions options) {
      if (options != null) {
         boolean showVerbose = options.getVerboseResults();
         vLayout_Matches.setVisible(showVerbose);
         breadcrumbComp.setVisible(showVerbose);
      }
   }

   private class OseeSearchResultMatchComponent extends HorizontalLayout {
      public OseeSearchResultMatchComponent(SearchResultMatch match) {
         Label matchLabel = new Label(String.format("%s: ", match.getAttributeType()), Label.CONTENT_XHTML);
         matchLabel.setStyleName(CssConstants.OSEE_ATTRNAME);
         Label spacer4 = new Label();
         spacer4.setWidth(15, UNITS_PIXELS);

         StringBuilder builder = new StringBuilder();
         for (StyledText text : match.getData()) {
            if (text.isHighLighted()) {
               builder.append("<SPAN style=\"BACKGROUND-COLOR: #ffff00\">");
            }
            builder.append(text.getData());
            if (text.isHighLighted()) {
               builder.append("</SPAN>");
            }
         }
         Label matchLabelHint = new Label(builder.toString(), Label.CONTENT_XHTML);
         Label spacer3 = new Label();
         spacer3.setWidth(15, UNITS_PIXELS);

         Label matchManyLabel = new Label(String.format("(%d matches)", match.getManyMatches()), Label.CONTENT_XHTML);
         matchManyLabel.setStyleName(CssConstants.OSEE_SEARCHRESULT_MATCH_MANY);

         addComponent(matchLabel);
         addComponent(spacer4);
         addComponent(matchLabelHint);
         addComponent(spacer3);
         addComponent(matchManyLabel);
      }
   }

}

Back to the top