Skip to main content
summaryrefslogtreecommitdiffstats
blob: 64fc8f9a9aa5edebbecb68efdda53ff98e10a0e6 (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
/*******************************************************************************
 * 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.ote.ui.test.manager.pages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.osee.framework.jdk.core.type.IPropertyStore;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.ui.plugin.OseeUiActivator;
import org.eclipse.osee.framework.ui.plugin.widgets.IPropertyStoreBasedControl;
import org.eclipse.osee.framework.ui.plugin.widgets.PropertyStoreControlContributions;
import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment;
import org.eclipse.osee.ote.service.ConnectionEvent;
import org.eclipse.osee.ote.ui.test.manager.core.TestManagerEditor;
import org.eclipse.osee.ote.ui.test.manager.internal.TestManagerPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class AdvancedPage extends TestManagerPage {

   public static final OseeUiActivator plugin = TestManagerPlugin.getInstance();
   private static final String pageName = "Advanced";
   private final List<IPropertyStoreBasedControl> contributions;
   private volatile boolean contributionsInitialized;

   public AdvancedPage(Composite parent, int style, TestManagerEditor parentTestManager) {
      super(parent, style, parentTestManager);
      this.contributions = new ArrayList<IPropertyStoreBasedControl>();
      contributionsInitialized = false;
   }

   private synchronized List<IPropertyStoreBasedControl> getContributions() {
      if (!contributionsInitialized) {
         contributionsInitialized = true;
         contributions.addAll(PropertyStoreControlContributions.getContributions(TestManagerPlugin.PLUGIN_ID));
      }
      return contributions;
   }

   @Override
   public void createPage() {
      super.createPage();
      Composite parent = (Composite) getContent();
      Composite extensionPanel = new Composite(parent, SWT.NONE);
      GridLayout gL = new GridLayout();
      gL.marginWidth = 0;
      gL.marginHeight = 0;
      extensionPanel.setLayout(gL);
      extensionPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

      Collections.sort(getContributions(), new Comparator<IPropertyStoreBasedControl>() {

         @Override
         public int compare(IPropertyStoreBasedControl o1, IPropertyStoreBasedControl o2) {
            return Integer.valueOf(o1.getPriority()).compareTo(Integer.valueOf(o2.getPriority()));
         }
      });
      for (IPropertyStoreBasedControl widget : getContributions()) {

         try {
            widget.createControl(extensionPanel);
         } catch (Throwable e) {
            TestManagerPlugin.log(Level.SEVERE, "problem creating advance page contribution", e);
         }
      }

      createBlankArea(parent, 0, true);
      computeScrollSize();
      TestManagerPlugin.getInstance().setHelp(this, "tm_advanced_page", "org.eclipse.osee.framework.help.ui");
   }

   @Override
   public String getPageName() {
      return pageName;
   }

   private Control createBlankArea(Composite parent, int height, boolean allVertical) {
      Composite blank = new Composite(parent, SWT.NONE);
      GridLayout gridLayout = new GridLayout();
      GridData gd = new GridData();
      gd.minimumHeight = height;
      gd.grabExcessHorizontalSpace = true;
      gd.grabExcessVerticalSpace = allVertical;
      blank.setLayout(gridLayout);
      blank.setLayoutData(gd);
      return parent;
   }

   protected void createAreaDefaultLayout(Composite parent, boolean allHorizontal, boolean allVertical) {
      GridLayout layout = new GridLayout();
      GridData data = new GridData(GridData.FILL_BOTH);
      data.grabExcessHorizontalSpace = allHorizontal;
      data.grabExcessVerticalSpace = allVertical;
      parent.setLayout(layout);
      parent.setLayoutData(data);
   }

   @Override
   public void saveData() {
      IPropertyStore propertyStore = getTestManager().getPropertyStore();
      for (IPropertyStoreBasedControl contribution : getContributions()) {
         contribution.save(propertyStore);
      }
   }

   @Override
   public void restoreData() {
      IPropertyStore propertyStore = getTestManager().getPropertyStore();
      for (IPropertyStoreBasedControl contribution : getContributions()) {
         contribution.load(propertyStore);
      }
   }

   @Override
   public boolean areSettingsValidForRun() {
      boolean result = true;
      for (IPropertyStoreBasedControl contribution : getContributions()) {
         result &= contribution.areSettingsValid();
      }
      return result;
   }

   @Override
   public String getErrorMessage() {
      StringBuilder builder = new StringBuilder();
      for (IPropertyStoreBasedControl contribution : getContributions()) {
         String message = contribution.getErrorMessage();
         if (Strings.isValid(message)) {
            if (builder.length() > 0) {
               builder.append("\n");
            }
            builder.append(message);
         }
      }
      return builder.toString();
   }

   @Override
   public boolean onConnection(ConnectionEvent event) {
      return false;
   }

   @Override
   public boolean onDisconnect(ConnectionEvent event) {
      return false;
   }

   @Override
   public boolean onConnectionLost(IHostTestEnvironment testHost) {
      return false;
   }
}

Back to the top