Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 333c101a81bb27d350ff763bdd10f7053732528d (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
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * 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:
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/
package org.eclipse.scout.rt.client.test;

import javax.swing.JLabel;

import org.eclipse.scout.commons.runtime.BundleBrowser;
import org.eclipse.scout.rt.client.services.common.test.AbstractClientTest;
import org.eclipse.scout.rt.client.services.common.test.ClientTestUtility;
import org.eclipse.scout.rt.client.ui.form.IForm;
import org.eclipse.scout.rt.client.ui.form.fields.IFormField;
import org.eclipse.scout.rt.client.ui.form.fields.button.AbstractButton;
import org.eclipse.scout.rt.client.ui.form.fields.datefield.AbstractDateField;
import org.eclipse.scout.rt.client.ui.form.fields.doublefield.AbstractDoubleField;
import org.eclipse.scout.rt.client.ui.form.fields.smartfield.AbstractSmartField;
import org.eclipse.scout.rt.client.ui.form.fields.stringfield.AbstractStringField;
import org.osgi.framework.Bundle;

public class VisibleFieldLabelUnitTest extends AbstractClientTest {

  @Override
  public void run() throws Exception {
    Bundle clientBundle = ClientTestUtility.getClientBundle();
    BundleBrowser b = new BundleBrowser(clientBundle.getSymbolicName(), ClientTestUtility.getFormsPackage());
    for (String className : b.getClasses(false, false)) {
      Class<?> c = clientBundle.loadClass(className);
      try {
        IForm form = (IForm) c.newInstance();
        for (IFormField childField : form.getAllFields()) {
          if (childField.getLabel() != null) {
            // test
            setSubTitle(form.getTitle() + " > " + childField.getLabel() + " [" + form.getClass().getSimpleName() + "." + childField.getClass().getSimpleName() + "]");
            JLabel l = new JLabel();
            int pix = l.getFontMetrics(l.getFont()).stringWidth(childField.getLabel());
            if (pix > 130 && (AbstractDateField.class.isAssignableFrom(childField.getClass()) || AbstractDoubleField.class.isAssignableFrom(childField.getClass()) || AbstractSmartField.class.isAssignableFrom(childField.getClass()) || AbstractStringField.class.isAssignableFrom(childField.getClass()))) {
              addWarningStatus(childField.getLabel() + " (" + pix + "px) > 130px");
            }
            else if (pix > (185 * childField.getGridData().w) && AbstractButton.class.isAssignableFrom(childField.getClass()) || AbstractButton.class.isAssignableFrom(childField.getClass())) {
              addWarningStatus(childField.getLabel() + " (" + pix + "px) > " + (185 * childField.getGridData().w) + "px");
            }
            else {
              addOkStatus();
            }
          }
        }
      }
      catch (Exception e) {
      }
    }
  }

  @Override
  protected String getConfiguredTitle() {
    return "dialog fields: field wide enough for label";
  }
}

Back to the top