コード例 #1
0
  /** 编辑转换配置XML文件 ; */
  public void editConfigXml() {
    ISelection selection = tableViewer.getSelection();
    if (!selection.isEmpty() && selection != null && selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      @SuppressWarnings("unchecked")
      Iterator<String[]> iter = structuredSelection.iterator();
      String convertXml = iter.next()[1];

      AddOrEditXmlConvertConfigDialog dialog =
          new AddOrEditXmlConvertConfigDialog(getShell(), false);
      dialog.create();
      String convertXmlLoaction =
          root.getLocation()
              .append(ADConstants.AD_xmlConverterConfigFolder)
              .append(convertXml)
              .toOSString();
      if (dialog.setInitEditData(convertXmlLoaction)) {
        int result = dialog.open();
        // 如果点击的是确定按钮,那么更新列表
        if (result == IDialogConstants.OK_ID) {
          String curentConvertXMl = dialog.getCurentConverXML();
          refreshTable();
          setTableSelection(curentConvertXMl);
        }
      }
    } else {
      MessageDialog.openInformation(
          getShell(),
          Messages.getString("dialogs.XmlConverterConfigurationDialog.msgTitle"),
          Messages.getString("dialogs.XmlConverterConfigurationDialog.msg2"));
    }
  }
コード例 #2
0
 @Override
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   newShell.setText(Messages.getString("dialogs.XmlConverterConfigurationDialog.title"));
 }
コード例 #3
0
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridDataFactory.fillDefaults()
        .grab(true, true)
        .hint(400, 450)
        .minSize(400, 450)
        .applyTo(tparent);

    tableViewer =
        new TableViewer(
            tparent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());

    String[] columnNames =
        new String[] {
          Messages.getString("dialogs.XmlConverterConfigurationDialog.columnNames1"),
          Messages.getString("dialogs.XmlConverterConfigurationDialog.columnNames2")
        };
    int[] columnAlignments = new int[] {SWT.LEFT, SWT.LEFT};
    for (int i = 0; i < columnNames.length; i++) {
      TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
      tableColumn.setText(columnNames[i]);
      tableColumn.setWidth(50);

      // 处理排序的问题
      switch (i) {
        case 0:
          tableColumn.addSelectionListener(
              new SelectionAdapter() {
                boolean asc = true; // 升序

                @Override
                public void widgetSelected(SelectionEvent e) {
                  tableViewer.setSorter(
                      asc ? XmlConvertOrder.index_ASC : XmlConvertOrder.index_DESC);
                  asc = !asc;
                }
              });
          break;
        case 1:
          tableColumn.addSelectionListener(
              new SelectionAdapter() {
                boolean asc = true; // 升序

                @Override
                public void widgetSelected(SelectionEvent e) {
                  tableViewer.setSorter(
                      asc ? XmlConvertOrder.xmlName_ASC : XmlConvertOrder.xmlName_DESC);
                  asc = !asc;
                }
              });
          break;
        default:
          break;
      }
    }
    tableViewer.setInput(getXmlConfigFilesInfo());

    // 让列表列宽动态变化
    table.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event
                .widget
                .getDisplay()
                .syncExec(
                    new Runnable() {
                      public void run() {
                        double[] columnWidths = new double[] {0.1, 0.85};
                        for (int i = 0; i < columns.length; i++)
                          columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                      }
                    });
          }
        });

    tableViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            editConfigXml();
          }
        });

    return tparent;
  }
コード例 #4
0
  @Override
  protected Control createButtonBar(Composite parent) {
    Composite buttonCmp = new Composite(parent, SWT.NONE);

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = false;
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    buttonCmp.setLayout(layout);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    buttonCmp.setLayoutData(data);
    buttonCmp.setFont(parent.getFont());

    Composite leftCmp = new Composite(buttonCmp, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(leftCmp);
    GridLayoutFactory.fillDefaults()
        .extendedMargins(0, 0, 0, 0)
        .numColumns(3)
        .equalWidth(false)
        .applyTo(leftCmp);

    addBtn =
        createButton(
            leftCmp,
            IDialogConstants.CLIENT_ID,
            Messages.getString("dialogs.XmlConverterConfigurationDialog.addBtn"),
            false);
    editBtn =
        createButton(
            leftCmp,
            IDialogConstants.CLIENT_ID,
            Messages.getString("dialogs.XmlConverterConfigurationDialog.editBtn"),
            false);
    deleteBtn =
        createButton(
            leftCmp,
            IDialogConstants.CLIENT_ID,
            Messages.getString("dialogs.XmlConverterConfigurationDialog.deleteBtn"),
            false);

    Composite rightCmp = new Composite(buttonCmp, SWT.NONE);
    GridLayoutFactory.fillDefaults()
        .extendedMargins(0, 0, 0, 0)
        .numColumns(1)
        .equalWidth(false)
        .applyTo(rightCmp);

    analysisBtn =
        createButton(
            rightCmp,
            IDialogConstants.CLIENT_ID,
            Messages.getString("dialogs.XmlConverterConfigurationDialog.analysisBtn"),
            false);

    Label separatorLbl = new Label(buttonCmp, SWT.HORIZONTAL | SWT.SEPARATOR);
    GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(separatorLbl);

    createHelpToolItem(buttonCmp);

    Composite bottomCmp = new Composite(buttonCmp, SWT.NONE);
    GridDataFactory.fillDefaults()
        .grab(false, false)
        .align(SWT.RIGHT, SWT.CENTER)
        .applyTo(bottomCmp);
    GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 0).numColumns(1).applyTo(bottomCmp);

    createButton(
            bottomCmp,
            IDialogConstants.CANCEL_ID,
            Messages.getString("dialogs.XmlConverterConfigurationDialog.cancel"),
            true)
        .setFocus();

    initListener();

    return buttonCmp;
  }