Пример #1
0
  private static void createCombo(final Group group) {
    group.setLayout(new GridLayout(2, false));
    group.setText("Combo widget");

    final Label lbl0 = new Label(group, SWT.NONE);
    lbl0.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl0.setText("No prompt :");

    final Combo combo0 = new Combo(group, SWT.BORDER);
    combo0.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

    final Label lbl1 = new Label(group, SWT.NONE);
    lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl1.setText("Simple text prompt :");

    final Combo combo1 = new Combo(group, SWT.BORDER);
    combo1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", combo1);

    final Label lbl2 = new Label(group, SWT.NONE);
    lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl2.setText("Other style (bold) :");

    final Combo combo2 = new Combo(group, SWT.BORDER);
    combo2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want in bold", combo2);
    PromptSupport.setFontStyle(SWT.BOLD, combo2);

    final Label lbl3 = new Label(group, SWT.NONE);
    lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl3.setText("Behaviour highlight :");

    final Combo combo3 = new Combo(group, SWT.BORDER);
    combo3.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", combo3);
    PromptSupport.setFocusBehavior(FocusBehavior.HIGHLIGHT_PROMPT, combo3);

    final Label lbl4 = new Label(group, SWT.NONE);
    lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl4.setText("Change colors :");

    final Combo combo4 = new Combo(group, SWT.BORDER);
    combo4.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", combo4);
    PromptSupport.setForeground(combo4.getDisplay().getSystemColor(SWT.COLOR_YELLOW), combo4);
    PromptSupport.setBackground(combo4.getDisplay().getSystemColor(SWT.COLOR_BLACK), combo4);

    final Label lbl5 = new Label(group, SWT.NONE);
    lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl5.setText("Change when widget is initialized :");

    final Combo combo5 = new Combo(group, SWT.BORDER);
    combo5.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    combo5.setText("Remove what is typed...");
    combo5.setBackground(combo4.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    combo5.setForeground(combo4.getDisplay().getSystemColor(SWT.COLOR_YELLOW));

    PromptSupport.setPrompt("Type anything you want", combo5);
    PromptSupport.setForeground(combo4.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE), combo5);
    PromptSupport.setBackground(combo4.getDisplay().getSystemColor(SWT.COLOR_WHITE), combo5);
  }
  public Map<String, Serializable> getParams() {
    Map<String, Serializable> dsParams = new HashMap<String, Serializable>();
    boolean error = false;
    try {
      URL u = new URL(urlCombo.getText());
      dsParams.put(WFSDataStoreFactory.URL.key, u);
    } catch (Exception e) {
      if (red == null) red = new Color(null, 255, 0, 0);
      urlCombo.setForeground(red);
      error = true;
    }
    //        if(user.getText()!=null && !user.getText().equals("")){ //$NON-NLS-1$
    //            String username = user.getText();
    //            String password = pass.getText();
    //            if(password == null || "".equals(password)){ //$NON-NLS-1$
    //                if(red == null)
    //                    red = new Color(null,255,0,0);
    //                user.setForeground(red);
    //                pass.setForeground(red);
    //                error = true;
    //            }
    //            r.put(WFSDataStoreFactory.USERNAME.key,username);
    //            r.put(WFSDataStoreFactory.PASSWORD.key,password);
    //        }

    if (postDefault.getSelection()) {
      dsParams.put(WFSDataStoreFactory.PROTOCOL.key, Boolean.TRUE);
    } else {
      if (getDefault.getSelection()) {
        dsParams.put(WFSDataStoreFactory.PROTOCOL.key, Boolean.FALSE);
      } else {
        dsParams.put(WFSDataStoreFactory.PROTOCOL.key, null);
      }
    }

    String timeout = timeoutText.getText();
    if (!WFSRegistryWizardPage.timeoutDefault.equals(timeout)) {
      // parse the string
      Integer sec = null;
      try {
        sec = new Integer(timeout);
      } catch (NumberFormatException e) {
        if (red == null) red = new Color(null, 255, 0, 0);
        timeoutText.setForeground(red);
        error = true;
      }
      dsParams.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(sec.intValue() * 1000));
    }

    String buffer = bufferText.getText();
    if (!WFSRegistryWizardPage.bufferDefault.equals(buffer)) {
      // parse the string
      Integer sec = null;
      try {
        sec = new Integer(buffer);
      } catch (NumberFormatException e) {
        if (red == null) red = new Color(null, 255, 0, 0);
        bufferText.setForeground(red);
        error = true;
      }
      dsParams.put(WFSDataStoreFactory.BUFFER_SIZE.key, sec);
    }

    //        String maxFeatures = maxFeaturesText.getText();
    //        if(!WFSRegistryWizardPage.maxFeaturesDefault.equals(timeout)){
    //            // parse the string
    //            Integer max = null;
    //            try{
    //                max = Integer.valueOf(maxFeatures);
    //            }catch(NumberFormatException e){
    //                if(red == null)
    //                    red = new Color(null,255,0,0);
    //                maxFeaturesText.setForeground(red);
    //                error = true;
    //            }
    //            dsParams.put(WFSDataStoreFactory.MAXFEATURES.key, max);
    //        }
    /*
          boolean usePull = usePullParser.getSelection();
    dsParams.put("USE_PULL_PARSER", String.valueOf(usePull)); //$NON-NLS-1$
    */
    return error ? null : dsParams;
  }
Пример #3
0
 @Test
 public void testPreserveValues() {
   Combo combo = new Combo(shell, SWT.READ_ONLY);
   Fixture.markInitialized(display);
   // Test preserving a combo with no items and (naturally) no selection
   Fixture.preserveWidgets();
   WidgetAdapter adapter = WidgetUtil.getAdapter(combo);
   String[] items = ((String[]) adapter.getPreserved(PROP_ITEMS));
   assertEquals(0, items.length);
   assertEquals(new Integer(-1), adapter.getPreserved(PROP_SELECTION_INDEX));
   assertNull(adapter.getPreserved(ComboLCA.PROP_TEXT_LIMIT));
   Object visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT);
   assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount);
   assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   assertEquals(new Point(0, 0), adapter.getPreserved(ComboLCA.PROP_SELECTION));
   // Test preserving combo with items were one is selected
   Fixture.clearPreserved();
   combo.add("item 1");
   combo.add("item 2");
   combo.select(1);
   combo.setListVisible(true);
   SelectionListener selectionListener = new SelectionAdapter() {};
   combo.addSelectionListener(selectionListener);
   combo.addModifyListener(
       new ModifyListener() {
         public void modifyText(ModifyEvent event) {}
       });
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   items = ((String[]) adapter.getPreserved(PROP_ITEMS));
   assertEquals(2, items.length);
   assertEquals("item 1", items[0]);
   assertEquals("item 2", items[1]);
   assertEquals(new Integer(1), adapter.getPreserved(PROP_SELECTION_INDEX));
   visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT);
   assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount);
   assertEquals("item 2", adapter.getPreserved(Props.TEXT));
   assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   Fixture.clearPreserved();
   // foreground background font
   Color background = new Color(display, 122, 33, 203);
   combo.setBackground(background);
   Color foreground = new Color(display, 211, 178, 211);
   combo.setForeground(foreground);
   Font font = new Font(display, "font", 12, SWT.BOLD);
   combo.setFont(font);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals(background, adapter.getPreserved(Props.BACKGROUND));
   assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND));
   assertEquals(font, adapter.getPreserved(Props.FONT));
   Fixture.clearPreserved();
   // tooltiptext
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals(null, combo.getToolTipText());
   Fixture.clearPreserved();
   combo.setToolTipText("some text");
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals("some text", combo.getToolTipText());
   Fixture.clearPreserved();
 }