private void jbInit() throws Exception {
   border1 = BorderFactory.createEmptyBorder(20, 20, 20, 20);
   contentPane.setBorder(border1);
   contentPane.setLayout(borderLayout1);
   controlsPane.setLayout(gridLayout1);
   gridLayout1.setColumns(1);
   gridLayout1.setHgap(10);
   gridLayout1.setRows(0);
   gridLayout1.setVgap(10);
   okButton.setVerifyInputWhenFocusTarget(true);
   okButton.setMnemonic('O');
   okButton.setText("OK");
   buttonsPane.setLayout(flowLayout1);
   flowLayout1.setAlignment(FlowLayout.CENTER);
   messagePane.setEditable(false);
   messagePane.setText("");
   borderLayout1.setHgap(10);
   borderLayout1.setVgap(10);
   this.setTitle("Subscription Authorization");
   this.getContentPane().add(contentPane, BorderLayout.CENTER);
   contentPane.add(controlsPane, BorderLayout.SOUTH);
   controlsPane.add(responsesComboBox, null);
   controlsPane.add(buttonsPane, null);
   buttonsPane.add(okButton, null);
   contentPane.add(messageScrollPane, BorderLayout.CENTER);
   messageScrollPane.getViewport().add(messagePane, null);
 }
  public void createControl(Composite parent) {

    Composite pageContent = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    pageContent.setLayout(layout);
    pageContent.setLayoutData(new GridData(GridData.FILL_BOTH));

    // variable never used ... is pageContent.getLayoutData() needed?
    // GridData outerFrameGridData = (GridData)
    pageContent.getLayoutData();

    //		outerFrameGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_FILL;
    //		outerFrameGridData.verticalAlignment = GridData.VERTICAL_ALIGN_FILL;

    //    WorkbenchHelp.setHelp(
    //        pageContent,
    //        B2BGUIContextIds.BTBG_SELECT_MULTI_FILE_PAGE);

    createLabels(pageContent);
    createSourceViewer(pageContent);
    createButtonPanel(pageContent);
    createSelectedListBox(pageContent);
    createImportButton(pageContent);

    setControl(pageContent);
    if (isFileMandatory) setPageComplete(false);
  }
Exemplo n.º 3
0
  void addBooleanComponent(String name, boolean currentValue) {
    configGridLayout.setRows(configGridLayout.getRows() + 1);
    addConfigLabel(name);

    JCheckBox checkBox = new JCheckBox();
    checkBox.setSelected(currentValue);

    componentByName.put(name, checkBox);
    configPanel.add(checkBox);
  }
Exemplo n.º 4
0
  void addTextBox(String name, String currentValue) {
    configGridLayout.setRows(configGridLayout.getRows() + 1);
    addConfigLabel(name);

    JTextField textField = new JTextField();
    textField.setText(currentValue);

    componentByName.put(name, textField);
    configPanel.add(textField);
  }
Exemplo n.º 5
0
  void buildConfigPanel() {
    try {
      Config config = playerObjects.getConfig();
      for (Field field : config.getClass().getDeclaredFields()) {
        Annotation excludeAnnotation = field.getAnnotation(ReflectionHelper.Exclude.class);
        if (excludeAnnotation == null) { // so, this field is not excluded
          Class<?> fieldType = field.getType();
          Method getMethod = getGetMethod(config.getClass(), field.getType(), field.getName());
          if (getMethod != null) {
            Object value = getMethod.invoke(config);
            if (fieldType == String.class) {
              addTextBox(field.getName(), (String) value);
            }
            if (fieldType == boolean.class || fieldType == Boolean.class) {
              addBooleanComponent(field.getName(), (Boolean) value);
            }
            if (fieldType == float.class || fieldType == Float.class) {
              addTextBox(field.getName(), "" + value);
            }
            if (fieldType == int.class || fieldType == Integer.class) {
              addTextBox(field.getName(), "" + value);
            }
          } else {
            playerObjects
                .getLogFile()
                .WriteLine("No get accessor method for config field " + field.getName());
          }
        }
      }
    } catch (Exception e) {
      playerObjects.getLogFile().WriteLine(Formatting.exceptionToStackTrace(e));
    }

    configGridLayout.setRows(configGridLayout.getRows() + 2);

    configRevertButton = new JButton("Revert");
    configReloadButton = new JButton("Reload");
    configApplyButton = new JButton("Apply");
    configSaveButton = new JButton("Save");

    configRevertButton.addActionListener(new ConfigRevert());
    configReloadButton.addActionListener(new ConfigReload());
    configApplyButton.addActionListener(new ConfigApply());
    configSaveButton.addActionListener(new ConfigSave());

    configPanel.add(configRevertButton);
    configPanel.add(configReloadButton);
    configPanel.add(configApplyButton);
    configPanel.add(configSaveButton);
  }
  private void createButtonPanel(Composite pageContent) {
    Composite buttonPanel = new Composite(pageContent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    buttonPanel.setLayout(layout);

    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = false;
    gridData.grabExcessVerticalSpace = true;
    gridData.verticalAlignment = GridData.CENTER;
    gridData.horizontalAlignment = GridData.CENTER;
    buttonPanel.setLayoutData(gridData);

    addButton = new Button(buttonPanel, SWT.PUSH);
    addButton.setText(Messages._UI_ADD_BUTTON);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.CENTER;
    addButton.setLayoutData(gridData);
    addButton.addSelectionListener(new ButtonSelectListener());
    addButton.setToolTipText(Messages._UI_ADD_BUTTON_TOOL_TIP);
    addButton.setEnabled(false);

    removeButton = new Button(buttonPanel, SWT.PUSH);
    removeButton.setText(Messages._UI_REMOVE_BUTTON);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.CENTER;
    removeButton.setLayoutData(gridData);
    removeButton.addSelectionListener(new ButtonSelectListener());
    removeButton.setToolTipText(Messages._UI_REMOVE_BUTTON_TOOL_TIP);
    removeButton.setEnabled(false);

    removeAllButton = new Button(buttonPanel, SWT.PUSH);
    removeAllButton.setText(Messages._UI_REMOVE_ALL_BUTTON);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.CENTER;
    removeAllButton.setLayoutData(gridData);
    removeAllButton.addSelectionListener(new ButtonSelectListener());
    removeAllButton.setToolTipText(Messages._UI_REMOVE_ALL_BUTTON_TOOL_TIP);
    removeAllButton.setEnabled(false);
  }
  private void createComp(Composite group) {

    GridLayout layout = new GridLayout(1, false);
    layout.verticalSpacing = 10;
    group.setLayout(layout);

    // TableViewer是通过Table来布局的
    // 制作表格   MULTI可多选  H_SCROLL有水平 滚动条、V_SCROLL有垂直滚动条、BORDER有边框、FULL_SELECTION整行选择
    table = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); // 注意此处的设置
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);

    // 指定Table单元格的宽度和高度
    table.addListener(
        SWT.MeasureItem,
        new Listener() { // 向表格增加一个SWT.MeasureItem监听器,每当需要单元内容的大小的时候就会被调用。
          public void handleEvent(Event event) {
            event.width = table.getGridLineWidth(); // 设置宽度
            event.height =
                (int) Math.floor(event.gc.getFontMetrics().getHeight() * 1.5); // 设置高度为字体高度的1.5倍
          }
        });

    // 表格的视图
    tableViewer = new TableViewer(table);
    // 标题和网格线可见
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    // 设置填充
    // GridData data = new GridData(SWT.LEFT,SWT.CENTER, true, false);//SWT.FILL, SWT.FILL, true,
    // false  xbm
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 350;
    data.heightHint = 295;
    data.grabExcessHorizontalSpace = true;
    tableViewer.getTable().setLayoutData(data); // 表格的布局

    // 创建表格列的标题
    int width = 1;
    for (int i = 0; i < stationData.getColumnCount(); i++) {
      width = stationData.getColumnWidth(i);
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setWidth((int) (width * 8));
      column.setText(stationData.getColumnHeads()[i]); // 设置表头
      column.setAlignment(SWT.LEFT); // 对齐方式SWT.LEFT
      if (i == 0) // 站名
      {
        // 列的选择事件  实现排序
        column.addSelectionListener(
            new SelectionAdapter() {
              boolean sortType = true; // sortType记录上一次的排序方式,默认为升序

              public void widgetSelected(SelectionEvent e) {
                sortType = !sortType; // 取反。下一次排序方式要和这一次的相反
                tableViewer.setSorter(new StationSorter(sortType, stationData.columnHeads[0]));
              }
            });
      }
    }

    /*tableLayout.addColumnData(new ColumnWeightData(8, 8, false));//设置列宽为8像素
     TableColumn column_one = new TableColumn(table, SWT.NONE);//SWT.LEFT
     column_one.setText(stationData.COLUMN_HEADINGS[0]);//设置表头
     column_one.setAlignment(SWT.LEFT);//对齐方式SWT.LEFT
     column.setWidth(10);//宽度
    */

    // 设置标题的提供者
    tableViewer.setLabelProvider(new TableLabelProvider());

    // 设置表格视图的内容提供者
    tableViewer.setContentProvider(new TableContentProvider());

    // 设置列的属性.
    tableViewer.setColumnProperties(stationData.columnHeads);

    // 定义每一列的别名
    tableViewer.setColumnProperties(new String[] {"name", "down", "up", "map"});

    // 设置每一列的单元格编辑组件CellEditor
    CellEditor[] celleditors = new CellEditor[5];
    // 文本编辑框
    celleditors[0] = null;
    celleditors[1] = new TextCellEditor(table);
    celleditors[2] = new TextCellEditor(table);
    // CheckboxCellEditor(table) 复选框
    celleditors[3] = new ComboBoxCellEditor(table, StationData.MAPS, SWT.READ_ONLY); // 下拉框

    Text text = (Text) celleditors[1].getControl(); // 设置第down列只能输入数值
    text.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent e) {
            // 输入控制键,输入中文,输入字符,输入数字 正整数验证
            Pattern pattern = Pattern.compile("[0-9]\\d*"); // 正则表达式
            Matcher matcher = pattern.matcher(e.text);
            if (matcher.matches()) // 处理数字
            {
              /*if(Integer.parseInt(e.text) != 0)//确保输入的数字不是0
              			e.doit = true;
              		else
              			e.doit = false;
              */
              e.doit = true;
            } else if (e.text.length() > 0) // 字符: 包含中文、空格
            e.doit = false;
            else // 控制键
            e.doit = true;
          }
        });

    Text text1 = (Text) celleditors[2].getControl(); // 设置第up列只能输入数值
    text1.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent e) {
            String inStr = e.text;
            if (inStr.length() > 0) {
              e.doit = NumberUtils.isDigits(inStr);
            }
          }
        });

    table.addMouseMoveListener(
        new MouseMoveListener() {
          public void mouseMove(MouseEvent e) {
            if (StationData.reloadFlag) {
              getStationInfo();
              openCurrentTable(row);
              StationData.reloadFlag = false;
              // System.out.println("entry");
            }
          }
        });
    /*table.addFocusListener(new FocusListener(){
    public void focusGained(FocusEvent e) {
    	getStationInfo();
    	openCurrentTable(row);
    }
    @Override
    public void focusLost(FocusEvent e) {
    }
      });
         */
    tableViewer.setCellEditors(celleditors);

    // 设置单元的更改器
    tableViewer.setCellModifier(new TableCellModifier());

    tableViewer.addFilter(new TableViewerFilter()); // 过滤器

    // 构造工具条
    Composite buttonComposite = new Composite(group, SWT.NONE);
    buttonComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); // 使工具条居中
    Action actionModify =
        new Action("更新") {
          public void run() {
            // 取得用户所选择的第一行, 若没有选择则为null
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            // 获取选中的第一行数据
            Station station = (Station) selection.getFirstElement();
            if (station != null) {
              if (updateStationInfo(
                  station.getStation_downnumber(),
                  station.getStation_upnumber(),
                  station.getStation_graph(),
                  station.getStation_name())) {
                showMsg("成功更新!");
                // 表格的刷新方法,界面会重新读取数据并显示

                pushCommand();

                tableViewer.refresh(); // false
              } else {
                showMsg("更新失败!");
                // tableViewer.refresh();//false
              }
            } else {
              showMsg("请选取进行更新的行!");
            }
          }
        };

    Action actionDelete =
        new Action("删除") {
          public void run() {
            // 取得用户所选择的第一行, 若没有选择则为null
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            // 获取选中的第一个数据
            Station station = (Station) selection.getFirstElement();
            if (station != null) {
              // 先预先移动到下一行
              Table table = tableViewer.getTable();

              // int i = table.getSelectionIndex(); //取得当前所选行的序号,如没有则返回-1
              // table.setSelection(i + 1); //当前选择行移下一行
              // 确认删除
              MessageBox messageBox =
                  new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_INFORMATION);
              messageBox.setText("提示信息");
              messageBox.setMessage("确定要删除此记录吗?");
              // SWT.YES 是  // SWT.NO 否 // SWT.CANCEL 取消 // SWT.RETRY 重试// SWT.ABORT 放弃// SWT.IGNORE
              // 忽略
              if (messageBox.open() == SWT.YES) {
                if (deleteStationInfo(station.getStation_name())) // 从数据库中删除记录
                {
                  // showMsg("成功删除!");
                  ((List) tableViewer.getInput()).remove(station); // 数据模型的List容器中删除
                  stationData.remove(station.getStation_name());
                  openCurrentTable(row);
                  tableViewer.remove(station); // 从表格界面上删除

                  pushCommand();
                } else showMsg("删除失败!");
              }
            } else {
              showMsg("请选取要删除的纪录!");
            }
          }
        };

    Action actionClear = new Action("清空") { // 清除所显示内容,点击保存后更新库
          public void run() {
            if (clearStationInfo()) {
              showMsg("清空操作成功!");
              stationData.removeAll();
              openCurrentTable(row);

              pushCommand();
            } else showMsg("清空操作失败!");
          }
        };
    Action actionHelp =
        new Action("帮助") {
          public void run() {
            String str = "更新:\n\r" + "先对某行内容进行修改,然后点击更新进行保存\n\r" + "清空:\n\r" + "从库中物理删除所有记录";
            showMsg(str);
          }
        };

    Action nextPage =
        new Action("下一页") {
          public void run() {
            row++;
            if (row > stationData.getTotalPageNum()) {
              row--;
              return;
            }
            openCurrentTable(row);
          }
        };
    Action prevPage =
        new Action("上一页") {
          public void run() {
            row--;
            if (row < 1) {
              row++;
              return;
            }
            openCurrentTable(row);
          }
        };

    Action refresh =
        new Action("刷新") {
          public void run() {
            getStationInfo();
            openCurrentTable(row);
          }
        };

    // 工具条
    ToolBar toolBar = new ToolBar(buttonComposite, SWT.FLAT | SWT.RIGHT); // |SWT.BORDER

    // 工具条管理器
    ToolBarManager manager = new ToolBarManager(toolBar);

    // manager.add(refresh);
    // manager.add(new Separator());

    manager.add(nextPage);
    manager.add(prevPage);

    manager.add(new Separator());

    manager.add(actionModify);
    manager.add(actionDelete);
    manager.add(actionClear);
    manager.add(new Separator());
    manager.add(actionHelp);
    manager.update(true);

    // 选中某行时,改变行的颜色
    table.addListener(
        SWT.EraseItem,
        new Listener() {
          public void handleEvent(Event event) {
            event.detail &= ~SWT.HOT;
            if ((event.detail & SWT.SELECTED) == 0) return;
            int clientWidth = table.getClientArea().width;
            GC gc = event.gc;
            Color oldForeground = gc.getForeground();
            Color oldBackground = gc.getBackground();
            gc.setForeground(red);
            // gc.setBackground(yellow);
            gc.fillGradientRectangle(0, event.y, clientWidth, event.height, false);
            gc.setForeground(oldForeground);
            gc.setBackground(oldBackground);
            event.detail &= ~SWT.SELECTED;
          }
        });

    // 在tableviewer内部为数据记录和tableItem之间的映射创建一个hash表,这样可以加快tableItem的和记录间的查找速度
    // 必须保证存在要显示的数据,否则程序出错。所以这里不能用下面的语句
    // tableViewer.setUseHashlookup(true);//必须在setInput之前加入才有效
    // 从服务器获取数据
    getStationInfo();
    // 通过setInput为table添加了一个list后,只要对这个list里的元素进行添加和删除,
    // table中的数据就会自动添加和删除,当然每次操作后需要调用refresh方法对tableviewer进行刷新。
    // 打开界面所显示的内容
    tableViewer.setInput(stationData.getData()); // 自动输入数据   即将数据显示在表格中
    tableViewer.setItemCount(stationData.PAGE_SIZE); // 设置显示的Item数
  } //// createComp
  /** @see PreferencePage#createContents(Composite) */
  protected Control createContents(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);

    // layout the top table & its buttons
    Label label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_topTableLabel);
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fIdMapsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fIdMapsTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fIdMapsTable.getItemHeight() * 4;
    fIdMapsTable.setLayoutData(data);
    fIdMapsTable.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            selectionChanged();
          }
        });

    String column2Text = XMLCompareMessages.XMLComparePreference_topTableColumn2;
    String column3Text = XMLCompareMessages.XMLComparePreference_topTableColumn3;
    ColumnLayoutData columnLayouts[] = {
      new ColumnWeightData(1),
      new ColumnPixelData(convertWidthInCharsToPixels(column2Text.length() + 2), true),
      new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 5), true)
    };
    TableLayout tablelayout = new TableLayout();
    fIdMapsTable.setLayout(tablelayout);
    for (int i = 0; i < 3; i++) tablelayout.addColumnData(columnLayouts[i]);
    TableColumn column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_topTableColumn1);
    column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(column2Text);
    column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(column3Text);

    fillIdMapsTable();

    Composite buttons = new Composite(parent, SWT.NULL);
    buttons.setLayout(new GridLayout());
    data = new GridData();
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    buttons.setLayoutData(data);

    fAddIdMapButton = new Button(buttons, SWT.PUSH);
    fAddIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topAdd);
    fAddIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            addIdMap(fAddIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fAddIdMapButton.setLayoutData(data);

    fRenameIdMapButton = new Button(buttons, SWT.PUSH);
    fRenameIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRename);
    fRenameIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            renameIdMap(fRenameIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fRenameIdMapButton.setLayoutData(data);

    fRemoveIdMapButton = new Button(buttons, SWT.PUSH);
    fRemoveIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRemove);
    fRemoveIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            removeIdMap(fRemoveIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fRemoveIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fRemoveIdMapButton.setLayoutData(data);

    createSpacer(buttons);

    fEditIdMapButton = new Button(buttons, SWT.PUSH);
    fEditIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topEdit);
    fEditIdMapButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            editIdMap(fEditIdMapButton.getShell());
          }
        });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint =
        Math.max(widthHint, fEditIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fEditIdMapButton.setLayoutData(data);

    // Spacer
    label = new Label(parent, SWT.LEFT);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    // layout the middle table & its buttons
    label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_middleTableLabel);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fMappingsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fMappingsTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fMappingsTable.getItemHeight() * 4;
    data.widthHint = convertWidthInCharsToPixels(70);
    fMappingsTable.setLayoutData(data);

    column3Text = XMLCompareMessages.XMLComparePreference_middleTableColumn3;
    String column4Text = XMLCompareMessages.XMLComparePreference_middleTableColumn4;
    columnLayouts =
        new ColumnLayoutData[] {
          new ColumnWeightData(10),
          new ColumnWeightData(18),
          new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 1), true),
          new ColumnPixelData(convertWidthInCharsToPixels(column4Text.length() + 3), true)
        };
    tablelayout = new TableLayout();
    fMappingsTable.setLayout(tablelayout);
    for (int i = 0; i < 4; i++) tablelayout.addColumnData(columnLayouts[i]);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn1);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn2);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(column3Text);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(column4Text);

    buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fNewMappingsButton = new Button(buttons, SWT.PUSH);
    fNewMappingsButton.setLayoutData(getButtonGridData(fNewMappingsButton));
    fNewMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleNew);
    fNewMappingsButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            addMapping(fAddIdMapButton.getShell());
          }
        });

    fEditMappingsButton = new Button(buttons, SWT.PUSH);
    fEditMappingsButton.setLayoutData(getButtonGridData(fEditMappingsButton));
    fEditMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleEdit);
    fEditMappingsButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            editMapping(fEditMappingsButton.getShell());
          }
        });

    fRemoveMappingsButton = new Button(buttons, SWT.PUSH);
    fRemoveMappingsButton.setLayoutData(getButtonGridData(fRemoveMappingsButton));
    fRemoveMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleRemove);
    fRemoveMappingsButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            removeMapping(fRemoveMappingsButton.getShell());
          }
        });

    createSpacer(buttons);

    // layout the botton table & its buttons
    label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_bottomTableLabel);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fOrderedTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fOrderedTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fOrderedTable.getItemHeight() * 2;
    data.widthHint = convertWidthInCharsToPixels(70);
    fOrderedTable.setLayoutData(data);

    columnLayouts = new ColumnLayoutData[] {new ColumnWeightData(1), new ColumnWeightData(1)};
    tablelayout = new TableLayout();
    fOrderedTable.setLayout(tablelayout);
    for (int i = 0; i < 2; i++) tablelayout.addColumnData(columnLayouts[i]);
    column = new TableColumn(fOrderedTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn1);
    column = new TableColumn(fOrderedTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn2);

    buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fNewOrderedButton = new Button(buttons, SWT.PUSH);
    fNewOrderedButton.setLayoutData(getButtonGridData(fNewOrderedButton));
    fNewOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomNew);
    fNewOrderedButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            addOrdered(fNewOrderedButton.getShell());
          }
        });

    fEditOrderedButton = new Button(buttons, SWT.PUSH);
    fEditOrderedButton.setLayoutData(getButtonGridData(fEditOrderedButton));
    fEditOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomEdit);
    fEditOrderedButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            editOrdered(fEditOrderedButton.getShell());
          }
        });

    fRemoveOrderedButton = new Button(buttons, SWT.PUSH);
    fRemoveOrderedButton.setLayoutData(getButtonGridData(fRemoveOrderedButton));
    fRemoveOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomRemove);
    fRemoveOrderedButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            removeOrdered(fRemoveOrderedButton.getShell());
          }
        });

    createSpacer(buttons);

    fIdMapsTable.setSelection(0);
    fIdMapsTable.setFocus();
    selectionChanged();

    return parent;
  }
Exemplo n.º 9
0
  private void jbInit() throws Exception {

    saveButton.setText("Save");
    saveButton.addActionListener(new PrintfTemplateEditor_saveButton_actionAdapter(this));
    cancelButton.setText("Cancel");
    cancelButton.addActionListener(new PrintfTemplateEditor_cancelButton_actionAdapter(this));
    this.setTitle(this.getTitle() + " Template Editor");
    printfPanel.setLayout(gridBagLayout1);
    formatLabel.setFont(new java.awt.Font("DialogInput", 0, 12));
    formatLabel.setText("Format String:");
    buttonPanel.setLayout(flowLayout1);
    printfPanel.setBorder(BorderFactory.createEtchedBorder());
    printfPanel.setMinimumSize(new Dimension(100, 160));
    printfPanel.setPreferredSize(new Dimension(380, 160));
    parameterPanel.setLayout(gridBagLayout2);
    parameterLabel.setText("Parameters:");
    parameterLabel.setFont(new java.awt.Font("DialogInput", 0, 12));
    parameterTextArea.setMinimumSize(new Dimension(100, 25));
    parameterTextArea.setPreferredSize(new Dimension(200, 25));
    parameterTextArea.setEditable(true);
    parameterTextArea.setText("");
    insertButton.setMaximumSize(new Dimension(136, 20));
    insertButton.setMinimumSize(new Dimension(136, 20));
    insertButton.setPreferredSize(new Dimension(136, 20));
    insertButton.setToolTipText(
        "insert the format in the format string and add parameter to list.");
    insertButton.setText("Insert Parameter");
    insertButton.addActionListener(new PrintfTemplateEditor_insertButton_actionAdapter(this));
    formatTextArea.setMinimumSize(new Dimension(100, 25));
    formatTextArea.setPreferredSize(new Dimension(200, 15));
    formatTextArea.setText("");
    parameterPanel.setBorder(null);
    parameterPanel.setMinimumSize(new Dimension(60, 40));
    parameterPanel.setPreferredSize(new Dimension(300, 40));
    insertMatchButton.addActionListener(
        new PrintfTemplateEditor_insertMatchButton_actionAdapter(this));
    insertMatchButton.setText("Insert Match");
    insertMatchButton.setToolTipText(
        "insert the match in the format string and add parameter to list.");
    insertMatchButton.setPreferredSize(new Dimension(136, 20));
    insertMatchButton.setMinimumSize(new Dimension(136, 20));
    insertMatchButton.setMaximumSize(new Dimension(136, 20));
    matchPanel.setPreferredSize(new Dimension(300, 40));
    matchPanel.setBorder(null);
    matchPanel.setMinimumSize(new Dimension(60, 60));
    matchPanel.setLayout(gridBagLayout3);
    InsertPanel.setLayout(gridLayout1);
    gridLayout1.setColumns(1);
    gridLayout1.setRows(2);
    gridLayout1.setVgap(0);
    InsertPanel.setBorder(BorderFactory.createEtchedBorder());
    InsertPanel.setMinimumSize(new Dimension(100, 100));
    InsertPanel.setPreferredSize(new Dimension(380, 120));
    editorPane.setText("");
    editorPane.addKeyListener(new PrintfEditor_editorPane_keyAdapter(this));
    printfTabPane.addChangeListener(new PrintfEditor_printfTabPane_changeAdapter(this));
    parameterPanel.add(
        insertButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(8, 6, 13, 8),
            0,
            10));
    parameterPanel.add(
        paramComboBox,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(8, 8, 13, 0),
            258,
            11));
    paramComboBox.setRenderer(new MyCellRenderer());
    InsertPanel.add(matchPanel, null);
    InsertPanel.add(parameterPanel, null);
    buttonPanel.add(cancelButton, null);
    buttonPanel.add(saveButton, null);
    this.getContentPane().add(printfTabPane, BorderLayout.NORTH);
    this.getContentPane().add(InsertPanel, BorderLayout.CENTER);
    matchPanel.add(
        insertMatchButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(8, 6, 13, 8),
            0,
            10));
    matchPanel.add(
        matchComboBox,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(8, 8, 13, 0),
            258,
            11));
    printfPanel.add(
        parameterLabel,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(7, 5, 0, 5),
            309,
            0));
    printfPanel.add(
        formatLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(4, 5, 0, 5),
            288,
            0));
    printfPanel.add(
        formatTextArea,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(6, 5, 0, 5),
            300,
            34));
    printfPanel.add(
        parameterTextArea,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(6, 5, 6, 5),
            300,
            34));
    printfTabPane.addTab("Editor View", null, editorPanel, "View in Editor");
    printfTabPane.addTab("Printf View", null, printfPanel, "Vies as Printf");
    editorPane.setCharacterAttributes(PLAIN_ATTR, true);
    editorPane.addStyle("PLAIN", editorPane.getLogicalStyle());
    editorPanel.getViewport().add(editorPane, null);
    this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    buttonGroup.add(cancelButton);
  }
    protected authDialog(
        AESemaphore _sem,
        Display display,
        String realm,
        boolean is_tracker,
        String target,
        String details) {
      sem = _sem;

      if (display.isDisposed()) {

        sem.releaseForever();

        return;
      }

      final String ignore_key = "IgnoreAuth:" + realm + ":" + target + ":" + details;

      if (RememberedDecisionsManager.getRememberedDecision(ignore_key) == 1) {

        Debug.out(
            "Authentication for "
                + realm
                + "/"
                + target
                + "/"
                + details
                + " ignored as told not to ask again");

        sem.releaseForever();

        return;
      }

      shell = ShellFactory.createMainShell(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

      Utils.setShellIcon(shell);
      Messages.setLanguageText(shell, "authenticator.title");

      GridLayout layout = new GridLayout();
      layout.numColumns = 3;

      shell.setLayout(layout);

      GridData gridData;

      // realm

      Label realm_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(realm_label, "authenticator.realm");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      realm_label.setLayoutData(gridData);

      Label realm_value = new Label(shell, SWT.NULL);
      realm_value.setText(realm.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      realm_value.setLayoutData(gridData);

      // target

      Label target_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(
          target_label, is_tracker ? "authenticator.tracker" : "authenticator.location");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      target_label.setLayoutData(gridData);

      Label target_value = new Label(shell, SWT.NULL);
      target_value.setText(target.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      target_value.setLayoutData(gridData);

      if (details != null) {

        Label details_label = new Label(shell, SWT.NULL);
        Messages.setLanguageText(
            details_label, is_tracker ? "authenticator.torrent" : "authenticator.details");
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 1;
        details_label.setLayoutData(gridData);

        Label details_value = new Label(shell, SWT.NULL);
        details_value.setText(details.replaceAll("&", "&&"));
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 2;
        details_value.setLayoutData(gridData);
      }
      // user

      Label user_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(user_label, "authenticator.user");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      user_label.setLayoutData(gridData);

      final Text user_value = new Text(shell, SWT.BORDER);
      user_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      user_value.setLayoutData(gridData);

      user_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              username = user_value.getText();
            }
          });

      // password

      Label password_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(password_label, "authenticator.password");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      password_label.setLayoutData(gridData);

      final Text password_value = new Text(shell, SWT.BORDER);
      password_value.setEchoChar('*');
      password_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      password_value.setLayoutData(gridData);

      password_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              password = password_value.getText();
            }
          });

      // persist

      Label blank_label = new Label(shell, SWT.NULL);
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      blank_label.setLayoutData(gridData);

      final Button checkBox = new Button(shell, SWT.CHECK);
      checkBox.setText(MessageText.getString("authenticator.savepassword"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      checkBox.setLayoutData(gridData);
      checkBox.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              persist = checkBox.getSelection();
            }
          });

      final Button dontAsk = new Button(shell, SWT.CHECK);
      dontAsk.setText(MessageText.getString("general.dont.ask.again"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      dontAsk.setLayoutData(gridData);
      dontAsk.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              RememberedDecisionsManager.setRemembered(ignore_key, dontAsk.getSelection() ? 1 : 0);
            }
          });

      // line

      Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      gridData.horizontalSpan = 3;
      labelSeparator.setLayoutData(gridData);

      // buttons

      new Label(shell, SWT.NULL);

      Button bOk = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bOk, "Button.ok");
      gridData =
          new GridData(
              GridData.FILL_HORIZONTAL
                  | GridData.HORIZONTAL_ALIGN_END
                  | GridData.HORIZONTAL_ALIGN_FILL);
      gridData.grabExcessHorizontalSpace = true;
      gridData.widthHint = 70;
      bOk.setLayoutData(gridData);
      bOk.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(true);
            }
          });

      Button bCancel = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bCancel, "Button.cancel");
      gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
      gridData.grabExcessHorizontalSpace = false;
      gridData.widthHint = 70;
      bCancel.setLayoutData(gridData);
      bCancel.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(false);
            }
          });

      shell.setDefaultButton(bOk);

      shell.addListener(
          SWT.Traverse,
          new Listener() {
            public void handleEvent(Event e) {
              if (e.character == SWT.ESC) {
                close(false);
              }
            }
          });

      shell.pack();

      Utils.centreWindow(shell);

      shell.open();
    }
  /**
   * Creates the dialog's contents
   *
   * @param shell the dialog window
   */
  private void createContents(final Shell shell) {

    final Config config = controller.getConfig();

    // Create the ScrolledComposite to scroll horizontally and vertically
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);

    // Create the parent Composite container for the three child containers
    Composite container = new Composite(sc, SWT.NONE);
    GridLayout containerLayout = new GridLayout(1, false);
    container.setLayout(containerLayout);
    shell.setLayout(new FillLayout());

    GridData data;
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 50;
    data.widthHint = 400;

    // START TOP COMPONENT

    Composite topComp = new Composite(container, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    topComp.setLayout(layout);
    topComp.setLayoutData(data);

    Label blank = new Label(topComp, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 10;
    blank.setLayoutData(data);
    blank.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    // Show the message
    Label label = new Label(topComp, SWT.NONE);
    label.setText(message);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 30;
    data.widthHint = 370;

    Font f = label.getFont();
    FontData[] farr = f.getFontData();
    FontData fd = farr[0];
    fd.setStyle(SWT.BOLD);
    label.setFont(new Font(Display.getCurrent(), fd));

    label.setLayoutData(data);
    label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    Label labelSeparator = new Label(topComp, SWT.SEPARATOR | SWT.HORIZONTAL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    labelSeparator.setLayoutData(data);

    // END TOP COMPONENT

    // START MIDDLE COMPONENT

    Composite restComp = new Composite(container, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    restComp.setLayoutData(data);
    layout = new GridLayout(2, false);
    layout.verticalSpacing = 10;
    restComp.setLayout(layout);

    // Hide welecome screen
    Label labelHideWelcomeScreen = new Label(restComp, SWT.RIGHT);
    labelHideWelcomeScreen.setText(
        Labels.getString("AdvancedSettingsDialog.hideWelcomeScreen")); // $NON-NLS-1$
    labelHideWelcomeScreen.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    buttonHideWelcomeScreen = new Button(restComp, SWT.CHECK);
    buttonHideWelcomeScreen.setSelection(config.getBoolean(Config.HIDE_WELCOME_SCREEN));

    // batch size
    Label labelBatch = new Label(restComp, SWT.RIGHT);
    labelBatch.setText(Labels.getString("AdvancedSettingsDialog.batchSize")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelBatch.setLayoutData(data);

    textBatch = new Text(restComp, SWT.BORDER);
    textBatch.setText(config.getString(Config.LOAD_BATCH_SIZE));
    textBatch.setTextLimit(8);
    textBatch.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            event.doit =
                Character.isISOControl(event.character) || Character.isDigit(event.character);
          }
        });
    data = new GridData();
    data.widthHint = 50;
    textBatch.setLayoutData(data);

    // insert Nulls
    Label labelNulls = new Label(restComp, SWT.RIGHT);
    labelNulls.setText(Labels.getString("AdvancedSettingsDialog.insertNulls")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelNulls.setLayoutData(data);
    buttonNulls = new Button(restComp, SWT.CHECK);
    buttonNulls.setSelection(config.getBoolean(Config.INSERT_NULLS));

    // assignment rules
    Label labelRule = new Label(restComp, SWT.RIGHT);
    labelRule.setText(Labels.getString("AdvancedSettingsDialog.assignmentRule")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelRule.setLayoutData(data);

    textRule = new Text(restComp, SWT.BORDER);
    textRule.setTextLimit(18);
    data = new GridData();
    data.widthHint = 115;
    textRule.setLayoutData(data);
    textRule.setText(config.getString(Config.ASSIGNMENT_RULE));

    // endpoint
    Label labelEndpoint = new Label(restComp, SWT.RIGHT);
    labelEndpoint.setText(Labels.getString("AdvancedSettingsDialog.serverURL")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelEndpoint.setLayoutData(data);

    textEndpoint = new Text(restComp, SWT.BORDER);
    data = new GridData();
    data.widthHint = 250;
    textEndpoint.setLayoutData(data);
    String endpoint = config.getString(Config.ENDPOINT);
    if ("".equals(endpoint)) { // $NON-NLS-1$
      endpoint = defaultServer;
    }

    textEndpoint.setText(endpoint);

    // reset url on login
    Label labelResetUrl = new Label(restComp, SWT.RIGHT);
    labelResetUrl.setText(
        Labels.getString("AdvancedSettingsDialog.resetUrlOnLogin")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelResetUrl.setLayoutData(data);
    buttonResetUrl = new Button(restComp, SWT.CHECK);
    buttonResetUrl.setSelection(config.getBoolean(Config.RESET_URL_ON_LOGIN));

    // insert compression
    Label labelCompression = new Label(restComp, SWT.RIGHT);
    labelCompression.setText(Labels.getString("AdvancedSettingsDialog.compression")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelCompression.setLayoutData(data);
    buttonCompression = new Button(restComp, SWT.CHECK);
    buttonCompression.setSelection(config.getBoolean(Config.NO_COMPRESSION));

    // timeout size
    Label labelTimeout = new Label(restComp, SWT.RIGHT);
    labelTimeout.setText(Labels.getString("AdvancedSettingsDialog.timeout")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelTimeout.setLayoutData(data);

    textTimeout = new Text(restComp, SWT.BORDER);
    textTimeout.setTextLimit(4);
    textTimeout.setText(config.getString(Config.TIMEOUT_SECS));
    textTimeout.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            event.doit =
                Character.isISOControl(event.character) || Character.isDigit(event.character);
          }
        });
    data = new GridData();
    data.widthHint = 30;
    textTimeout.setLayoutData(data);

    // extraction batch size
    Label labelQueryBatch = new Label(restComp, SWT.RIGHT);
    labelQueryBatch.setText(Labels.getString("ExtractionInputDialog.querySize")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelQueryBatch.setLayoutData(data);

    textQueryBatch = new Text(restComp, SWT.BORDER);
    textQueryBatch.setText(config.getString(Config.EXTRACT_REQUEST_SIZE));
    textQueryBatch.setTextLimit(4);
    textQueryBatch.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            event.doit =
                Character.isISOControl(event.character) || Character.isDigit(event.character);
          }
        });
    data = new GridData();
    data.widthHint = 30;
    textQueryBatch.setLayoutData(data);

    // enable/disable output of success file for extracts
    Label labelOutputExtractStatus = new Label(restComp, SWT.RIGHT);
    labelOutputExtractStatus.setText(
        Labels.getString("AdvancedSettingsDialog.outputExtractStatus")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelOutputExtractStatus.setLayoutData(data);

    buttonOutputExtractStatus = new Button(restComp, SWT.CHECK);
    buttonOutputExtractStatus.setSelection(config.getBoolean(Config.ENABLE_EXTRACT_STATUS_OUTPUT));

    // utf-8 for loading
    Label labelReadUTF8 = new Label(restComp, SWT.RIGHT);
    labelReadUTF8.setText(Labels.getString("AdvancedSettingsDialog.readUTF8")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelReadUTF8.setLayoutData(data);

    buttonReadUtf8 = new Button(restComp, SWT.CHECK);
    buttonReadUtf8.setSelection(config.getBoolean(Config.READ_UTF8));

    // utf-8 for extraction
    Label labelWriteUTF8 = new Label(restComp, SWT.RIGHT);
    labelWriteUTF8.setText(Labels.getString("AdvancedSettingsDialog.writeUTF8")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelWriteUTF8.setLayoutData(data);

    buttonWriteUtf8 = new Button(restComp, SWT.CHECK);
    buttonWriteUtf8.setSelection(config.getBoolean(Config.WRITE_UTF8));

    // European Dates
    Label labelEuropeanDates = new Label(restComp, SWT.RIGHT);
    labelEuropeanDates.setText(
        Labels.getString("AdvancedSettingsDialog.useEuropeanDateFormat")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelEuropeanDates.setLayoutData(data);

    buttonEuroDates = new Button(restComp, SWT.CHECK);
    buttonEuroDates.setSelection(config.getBoolean(Config.EURO_DATES));

    // Field truncation
    Label labelTruncateFields = new Label(restComp, SWT.RIGHT);
    labelTruncateFields.setText(Labels.getString("AdvancedSettingsDialog.allowFieldTruncation"));
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelTruncateFields.setLayoutData(data);

    buttonTruncateFields = new Button(restComp, SWT.CHECK);
    buttonTruncateFields.setSelection(config.getBoolean(Config.TRUNCATE_FIELDS));

    Label labelCsvCommand = new Label(restComp, SWT.RIGHT);
    labelCsvCommand.setText(Labels.getString("AdvancedSettingsDialog.useCommaAsCsvDelimiter"));
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelCsvCommand.setLayoutData(data);
    buttonCsvComma = new Button(restComp, SWT.CHECK);
    buttonCsvComma.setSelection(config.getBoolean(Config.CSV_DELIMETER_COMMA));

    Label labelTabCommand = new Label(restComp, SWT.RIGHT);
    labelTabCommand.setText(Labels.getString("AdvancedSettingsDialog.useTabAsCsvDelimiter"));
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelTabCommand.setLayoutData(data);
    buttonCsvTab = new Button(restComp, SWT.CHECK);
    buttonCsvTab.setSelection(config.getBoolean(Config.CSV_DELIMETER_TAB));

    Label labelOtherCommand = new Label(restComp, SWT.RIGHT);
    labelOtherCommand.setText(Labels.getString("AdvancedSettingsDialog.useOtherAsCsvDelimiter"));
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelOtherCommand.setLayoutData(data);
    buttonCsvOther = new Button(restComp, SWT.CHECK);
    buttonCsvOther.setSelection(config.getBoolean(Config.CSV_DELIMETER_OTHER));

    Label labelOtherDelimiterValue = new Label(restComp, SWT.RIGHT);
    labelOtherDelimiterValue.setText(
        Labels.getString("AdvancedSettingsDialog.csvOtherDelimiterValue"));
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelOtherDelimiterValue.setLayoutData(data);
    textSplitterValue = new Text(restComp, SWT.BORDER);
    textSplitterValue.setText(config.getString(Config.CSV_DELIMETER_OTHER_VALUE));
    data = new GridData();
    data.widthHint = 25;
    textSplitterValue.setLayoutData(data);

    // Enable Bulk API Setting
    Label labelUseBulkApi = new Label(restComp, SWT.RIGHT);
    labelUseBulkApi.setText(Labels.getString("AdvancedSettingsDialog.useBulkApi")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelUseBulkApi.setLayoutData(data);

    boolean useBulkAPI = config.getBoolean(Config.BULK_API_ENABLED);
    buttonUseBulkApi = new Button(restComp, SWT.CHECK);
    buttonUseBulkApi.setSelection(useBulkAPI);
    buttonUseBulkApi.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            boolean enabled = buttonUseBulkApi.getSelection();
            // update batch size when this setting changes
            int newDefaultBatchSize = controller.getConfig().getDefaultBatchSize(enabled);
            logger.info("Setting batch size to " + newDefaultBatchSize);
            textBatch.setText(String.valueOf(newDefaultBatchSize));
            // make sure the appropriate check boxes are enabled or disabled
            initBulkApiSetting(enabled);
          }
        });

    // Bulk API serial concurrency mode setting
    Label labelBulkApiSerialMode = new Label(restComp, SWT.RIGHT);
    labelBulkApiSerialMode.setText(
        Labels.getString("AdvancedSettingsDialog.bulkApiSerialMode")); // $NON-NLS-1$
    labelBulkApiSerialMode.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    buttonBulkApiSerialMode = new Button(restComp, SWT.CHECK);
    buttonBulkApiSerialMode.setSelection(config.getBoolean(Config.BULK_API_SERIAL_MODE));
    buttonBulkApiSerialMode.setEnabled(useBulkAPI);

    // Bulk API serial concurrency mode setting
    Label labelBulkApiZipContent = new Label(restComp, SWT.RIGHT);
    labelBulkApiZipContent.setText(
        Labels.getString("AdvancedSettingsDialog.bulkApiZipContent")); // $NON-NLS-1$
    labelBulkApiZipContent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    buttonBulkApiZipContent = new Button(restComp, SWT.CHECK);
    buttonBulkApiZipContent.setSelection(config.getBoolean(Config.BULK_API_SERIAL_MODE));
    buttonBulkApiZipContent.setEnabled(useBulkAPI);
    // timezone
    textTimezone =
        createTextInput(
            restComp,
            "AdvancedSettingsDialog.timezone",
            Config.TIMEZONE,
            TimeZone.getDefault().getID(),
            200);

    // proxy Host
    Label labelProxyHost = new Label(restComp, SWT.RIGHT);
    labelProxyHost.setText(Labels.getString("AdvancedSettingsDialog.proxyHost")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelProxyHost.setLayoutData(data);

    textProxyHost = new Text(restComp, SWT.BORDER);
    textProxyHost.setText(config.getString(Config.PROXY_HOST));
    data = new GridData();
    data.widthHint = 250;
    textProxyHost.setLayoutData(data);

    // Proxy Port
    Label labelProxyPort = new Label(restComp, SWT.RIGHT);
    labelProxyPort.setText(Labels.getString("AdvancedSettingsDialog.proxyPort")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelProxyPort.setLayoutData(data);

    textProxyPort = new Text(restComp, SWT.BORDER);
    textProxyPort.setText(config.getString(Config.PROXY_PORT));
    textProxyPort.setTextLimit(4);
    textProxyPort.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            event.doit =
                Character.isISOControl(event.character) || Character.isDigit(event.character);
          }
        });
    data = new GridData();
    data.widthHint = 25;
    textProxyPort.setLayoutData(data);

    // Proxy Username
    Label labelProxyUsername = new Label(restComp, SWT.RIGHT);
    labelProxyUsername.setText(Labels.getString("AdvancedSettingsDialog.proxyUser")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelProxyUsername.setLayoutData(data);

    textProxyUsername = new Text(restComp, SWT.BORDER);
    textProxyUsername.setText(config.getString(Config.PROXY_USERNAME));
    data = new GridData();
    data.widthHint = 120;
    textProxyUsername.setLayoutData(data);

    // Proxy Password
    Label labelProxyPassword = new Label(restComp, SWT.RIGHT);
    labelProxyPassword.setText(
        Labels.getString("AdvancedSettingsDialog.proxyPassword")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelProxyPassword.setLayoutData(data);

    textProxyPassword = new Text(restComp, SWT.BORDER | SWT.PASSWORD);
    textProxyPassword.setText(config.getString(Config.PROXY_PASSWORD));
    data = new GridData();
    data.widthHint = 120;
    textProxyPassword.setLayoutData(data);

    // proxy NTLM domain
    Label labelProxyNtlmDomain = new Label(restComp, SWT.RIGHT);
    labelProxyNtlmDomain.setText(
        Labels.getString("AdvancedSettingsDialog.proxyNtlmDomain")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelProxyNtlmDomain.setLayoutData(data);

    textProxyNtlmDomain = new Text(restComp, SWT.BORDER);
    textProxyNtlmDomain.setText(config.getString(Config.PROXY_NTLM_DOMAIN));
    data = new GridData();
    data.widthHint = 250;
    textProxyNtlmDomain.setLayoutData(data);

    //////////////////////////////////////////////////
    // Row to start At

    Label blankAgain = new Label(restComp, SWT.NONE);
    data = new GridData();
    data.horizontalSpan = 2;
    blankAgain.setLayoutData(data);

    // Row to start AT
    Label labelLastRow = new Label(restComp, SWT.NONE);

    String lastBatch = controller.getConfig().getString(LastRun.LAST_LOAD_BATCH_ROW);
    if (lastBatch.equals("")) { // $NON-NLS-1$
      lastBatch = "0"; // $NON-NLS-1$
    }

    labelLastRow.setText(
        Labels.getFormattedString("AdvancedSettingsDialog.lastBatch", lastBatch)); // $NON-NLS-1$
    data = new GridData();
    data.horizontalSpan = 2;
    labelLastRow.setLayoutData(data);

    Label labelRowToStart = new Label(restComp, SWT.RIGHT);
    labelRowToStart.setText(Labels.getString("AdvancedSettingsDialog.startRow")); // $NON-NLS-1$
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    labelRowToStart.setLayoutData(data);

    textRowToStart = new Text(restComp, SWT.BORDER);
    textRowToStart.setText(config.getString(Config.LOAD_ROW_TO_START_AT));
    data = new GridData();
    data.widthHint = 75;
    textRowToStart.setLayoutData(data);
    textRowToStart.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            event.doit =
                Character.isISOControl(event.character) || Character.isDigit(event.character);
          }
        });

    // now that we've created all the buttons, make sure that buttons dependent on the bulk api
    // setting are enabled or disabled appropriately
    initBulkApiSetting(useBulkAPI);

    // the bottow separator
    Label labelSeparatorBottom = new Label(restComp, SWT.SEPARATOR | SWT.HORIZONTAL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    labelSeparatorBottom.setLayoutData(data);

    // ok cancel buttons
    new Label(restComp, SWT.NONE);

    // END MIDDLE COMPONENT

    // START BOTTOM COMPONENT

    Composite buttonComp = new Composite(restComp, SWT.NONE);
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    buttonComp.setLayoutData(data);
    buttonComp.setLayout(new GridLayout(2, false));

    // Create the OK button and add a handler
    // so that pressing it will set input
    // to the entered value
    Button ok = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
    ok.setText(Labels.getString("UI.ok")); // $NON-NLS-1$
    ok.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent event) {
            Config config = controller.getConfig();

            // set the configValues
            config.setValue(Config.HIDE_WELCOME_SCREEN, buttonHideWelcomeScreen.getSelection());
            config.setValue(Config.INSERT_NULLS, buttonNulls.getSelection());
            config.setValue(Config.LOAD_BATCH_SIZE, textBatch.getText());
            if (!buttonCsvComma.getSelection()
                && !buttonCsvTab.getSelection()
                && (!buttonCsvOther.getSelection()
                    || textSplitterValue.getText() == null
                    || textSplitterValue.getText().length() == 0)) {
              return;
            }
            config.setValue(Config.CSV_DELIMETER_OTHER_VALUE, textSplitterValue.getText());
            config.setValue(Config.CSV_DELIMETER_COMMA, buttonCsvComma.getSelection());
            config.setValue(Config.CSV_DELIMETER_TAB, buttonCsvTab.getSelection());
            config.setValue(Config.CSV_DELIMETER_OTHER, buttonCsvOther.getSelection());

            config.setValue(Config.EXTRACT_REQUEST_SIZE, textQueryBatch.getText());
            config.setValue(Config.ENDPOINT, textEndpoint.getText());
            config.setValue(Config.ASSIGNMENT_RULE, textRule.getText());
            config.setValue(Config.LOAD_ROW_TO_START_AT, textRowToStart.getText());
            config.setValue(Config.RESET_URL_ON_LOGIN, buttonResetUrl.getSelection());
            config.setValue(Config.NO_COMPRESSION, buttonCompression.getSelection());
            config.setValue(Config.TRUNCATE_FIELDS, buttonTruncateFields.getSelection());
            config.setValue(Config.TIMEOUT_SECS, textTimeout.getText());
            config.setValue(
                Config.ENABLE_EXTRACT_STATUS_OUTPUT, buttonOutputExtractStatus.getSelection());
            config.setValue(Config.READ_UTF8, buttonReadUtf8.getSelection());
            config.setValue(Config.WRITE_UTF8, buttonWriteUtf8.getSelection());
            config.setValue(Config.EURO_DATES, buttonEuroDates.getSelection());
            config.setValue(Config.TIMEZONE, textTimezone.getText());
            config.setValue(Config.PROXY_HOST, textProxyHost.getText());
            config.setValue(Config.PROXY_PASSWORD, textProxyPassword.getText());
            config.setValue(Config.PROXY_PORT, textProxyPort.getText());
            config.setValue(Config.PROXY_USERNAME, textProxyUsername.getText());
            config.setValue(Config.PROXY_NTLM_DOMAIN, textProxyNtlmDomain.getText());
            config.setValue(Config.BULK_API_ENABLED, buttonUseBulkApi.getSelection());
            config.setValue(Config.BULK_API_SERIAL_MODE, buttonBulkApiSerialMode.getSelection());
            config.setValue(Config.BULK_API_ZIP_CONTENT, buttonBulkApiZipContent.getSelection());

            controller.saveConfig();
            controller.logout();

            input = Labels.getString("UI.ok"); // $NON-NLS-1$
            shell.close();
          }
        });
    data = new GridData();
    data.widthHint = 75;
    ok.setLayoutData(data);

    // Create the cancel button and add a handler
    // so that pressing it will set input to null
    Button cancel = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
    cancel.setText(Labels.getString("UI.cancel")); // $NON-NLS-1$
    cancel.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent event) {
            input = null;
            shell.close();
          }
        });

    // END BOTTOM COMPONENT

    data = new GridData();
    data.widthHint = 75;
    cancel.setLayoutData(data);

    // Set the OK button as the default, so
    // user can type input and press Enter
    // to dismiss
    shell.setDefaultButton(ok);

    // Set the child as the scrolled content of the ScrolledComposite
    sc.setContent(container);

    // Set the minimum size
    sc.setMinSize(768, 1024);

    // Expand both horizontally and vertically
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
  }
Exemplo n.º 12
0
  /** Initializes the GUI. */
  private void initGUI() {
    try {
      getShell()
          .addDisposeListener(
              new DisposeListener() {
                public void widgetDisposed(DisposeEvent evt) {
                  shellWidgetDisposed(evt);
                }
              });

      getShell()
          .addControlListener(
              new ControlAdapter() {
                public void controlResized(ControlEvent evt) {
                  shellControlResized(evt);
                }
              });

      getShell()
          .addControlListener(
              new ControlAdapter() {
                public void controlMoved(ControlEvent evt) {
                  shellControlMoved(evt);
                }
              });

      GridLayout thisLayout = new GridLayout();
      this.setLayout(thisLayout);
      {
        GridData toolBarLData = new GridData();
        toolBarLData.grabExcessHorizontalSpace = true;
        toolBarLData.horizontalAlignment = GridData.FILL;
        toolBar = new ToolBar(this, SWT.FLAT);
        toolBar.setLayoutData(toolBarLData);
        toolBar.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
        {
          newToolItem = new ToolItem(toolBar, SWT.NONE);
          newToolItem.setImage(SWTResourceManager.getImage("images/new.gif"));
          newToolItem.setToolTipText("New");
        }
        {
          openToolItem = new ToolItem(toolBar, SWT.NONE);
          openToolItem.setToolTipText("Open");
          openToolItem.setImage(SWTResourceManager.getImage("images/open.gif"));
          openToolItem.addSelectionListener(
              new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                  openToolItemWidgetSelected(evt);
                }
              });
        }
        {
          saveToolItem = new ToolItem(toolBar, SWT.NONE);
          saveToolItem.setToolTipText("Save");
          saveToolItem.setImage(SWTResourceManager.getImage("images/save.gif"));
        }
      }
      {
        clientArea = new Composite(this, SWT.NONE);
        GridData clientAreaLData = new GridData();
        clientAreaLData.grabExcessHorizontalSpace = true;
        clientAreaLData.grabExcessVerticalSpace = true;
        clientAreaLData.horizontalAlignment = GridData.FILL;
        clientAreaLData.verticalAlignment = GridData.FILL;
        clientArea.setLayoutData(clientAreaLData);
        clientArea.setLayout(null);
      }
      {
        statusArea = new Composite(this, SWT.NONE);
        GridLayout statusAreaLayout = new GridLayout();
        statusAreaLayout.makeColumnsEqualWidth = true;
        statusAreaLayout.horizontalSpacing = 0;
        statusAreaLayout.marginHeight = 0;
        statusAreaLayout.marginWidth = 0;
        statusAreaLayout.verticalSpacing = 0;
        statusAreaLayout.marginLeft = 3;
        statusAreaLayout.marginRight = 3;
        statusAreaLayout.marginTop = 3;
        statusAreaLayout.marginBottom = 3;
        statusArea.setLayout(statusAreaLayout);
        GridData statusAreaLData = new GridData();
        statusAreaLData.horizontalAlignment = GridData.FILL;
        statusAreaLData.grabExcessHorizontalSpace = true;
        statusArea.setLayoutData(statusAreaLData);
        statusArea.setBackground(SWTResourceManager.getColor(239, 237, 224));
        {
          statusText = new Label(statusArea, SWT.BORDER);
          statusText.setText(" Ready");
          GridData txtStatusLData = new GridData();
          txtStatusLData.horizontalAlignment = GridData.FILL;
          txtStatusLData.grabExcessHorizontalSpace = true;
          txtStatusLData.verticalIndent = 3;
          statusText.setLayoutData(txtStatusLData);
        }
      }
      thisLayout.verticalSpacing = 0;
      thisLayout.marginWidth = 0;
      thisLayout.marginHeight = 0;
      thisLayout.horizontalSpacing = 0;
      thisLayout.marginTop = 3;
      this.setSize(474, 312);
      {
        menu1 = new Menu(getShell(), SWT.BAR);
        getShell().setMenuBar(menu1);
        {
          fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
          fileMenuItem.setText("&File");
          {
            fileMenu = new Menu(fileMenuItem);
            {
              newFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              newFileMenuItem.setText("&New");
              newFileMenuItem.setImage(SWTResourceManager.getImage("images/new.gif"));
            }
            {
              openFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              openFileMenuItem.setText("&Open");
              openFileMenuItem.setImage(SWTResourceManager.getImage("images/open.gif"));
              openFileMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      openFileMenuItemWidgetSelected(evt);
                    }
                  });
            }
            {
              closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
              closeFileMenuItem.setText("Close");
            }
            {
              fileMenuSep1 = new MenuItem(fileMenu, SWT.SEPARATOR);
            }
            {
              saveFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              saveFileMenuItem.setText("&Save");
              saveFileMenuItem.setImage(SWTResourceManager.getImage("images/save.gif"));
              saveFileMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      saveFileMenuItemWidgetSelected(evt);
                    }
                  });
            }
            {
              fileMenuSep2 = new MenuItem(fileMenu, SWT.SEPARATOR);
            }
            {
              exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
              exitMenuItem.setText("E&xit");
              exitMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      exitMenuItemWidgetSelected(evt);
                    }
                  });
            }
            fileMenuItem.setMenu(fileMenu);
          }
        }
        {
          helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
          helpMenuItem.setText("&Help");
          {
            helpMenu = new Menu(helpMenuItem);
            {
              aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
              aboutMenuItem.setText("&About");
              aboutMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      aboutMenuItemWidgetSelected(evt);
                    }
                  });
            }
            helpMenuItem.setMenu(helpMenu);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 13
0
    protected authDialog(
        AESemaphore _sem, Display display, String realm, String tracker, String torrent_name) {
      sem = _sem;

      if (display.isDisposed()) {

        sem.release();

        return;
      }

      shell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

      Utils.setShellIcon(shell);
      Messages.setLanguageText(shell, "authenticator.title");

      GridLayout layout = new GridLayout();
      layout.numColumns = 3;

      shell.setLayout(layout);

      GridData gridData;

      // realm

      Label realm_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(realm_label, "authenticator.realm");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      realm_label.setLayoutData(gridData);

      Label realm_value = new Label(shell, SWT.NULL);
      realm_value.setText(realm.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      realm_value.setLayoutData(gridData);

      // tracker

      Label tracker_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(tracker_label, "authenticator.tracker");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      tracker_label.setLayoutData(gridData);

      Label tracker_value = new Label(shell, SWT.NULL);
      tracker_value.setText(tracker.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      tracker_value.setLayoutData(gridData);

      if (torrent_name != null) {

        Label torrent_label = new Label(shell, SWT.NULL);
        Messages.setLanguageText(torrent_label, "authenticator.torrent");
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 1;
        torrent_label.setLayoutData(gridData);

        Label torrent_value = new Label(shell, SWT.NULL);
        torrent_value.setText(torrent_name.replaceAll("&", "&&"));
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 2;
        torrent_value.setLayoutData(gridData);
      }
      // user

      Label user_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(user_label, "authenticator.user");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      user_label.setLayoutData(gridData);

      final Text user_value = new Text(shell, SWT.BORDER);
      user_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      user_value.setLayoutData(gridData);

      user_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              username = user_value.getText();
            }
          });

      // password

      Label password_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(password_label, "authenticator.password");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      password_label.setLayoutData(gridData);

      final Text password_value = new Text(shell, SWT.BORDER);
      password_value.setEchoChar('*');
      password_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      password_value.setLayoutData(gridData);

      password_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              password = password_value.getText();
            }
          });

      // persist

      Label blank_label = new Label(shell, SWT.NULL);
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      blank_label.setLayoutData(gridData);

      final Button checkBox = new Button(shell, SWT.CHECK);
      checkBox.setText(MessageText.getString("authenticator.savepassword"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      checkBox.setLayoutData(gridData);
      checkBox.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              persist = checkBox.getSelection();
            }
          });

      // line

      Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      gridData.horizontalSpan = 3;
      labelSeparator.setLayoutData(gridData);

      // buttons

      new Label(shell, SWT.NULL);

      Button bOk = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bOk, "Button.ok");
      gridData =
          new GridData(
              GridData.FILL_HORIZONTAL
                  | GridData.HORIZONTAL_ALIGN_END
                  | GridData.HORIZONTAL_ALIGN_FILL);
      gridData.grabExcessHorizontalSpace = true;
      gridData.widthHint = 70;
      bOk.setLayoutData(gridData);
      bOk.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(true);
            }
          });

      Button bCancel = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bCancel, "Button.cancel");
      gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
      gridData.grabExcessHorizontalSpace = false;
      gridData.widthHint = 70;
      bCancel.setLayoutData(gridData);
      bCancel.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(false);
            }
          });

      shell.setDefaultButton(bOk);

      shell.addListener(
          SWT.Traverse,
          new Listener() {
            public void handleEvent(Event e) {
              if (e.character == SWT.ESC) {
                close(false);
              }
            }
          });

      shell.pack();

      Utils.centreWindow(shell);

      shell.open();

      shell.forceActive();
    }