示例#1
0
  @Override
  public String toString() {
    StringBuilder text = new StringBuilder();
    text.append('(');
    IConnectionPoint source = getSource();
    if (source == null) {
      text.append(Messages.SiteConnection_LBL_NoSource);
    } else {
      ConnectionPointType type = CoreIOPlugin.getConnectionPointManager().getType(source);
      if (type != null) {
        text.append(type.getName()).append(':');
      }
      text.append(source.getName());
    }

    text.append(" <-> "); // $NON-NLS-1$

    IConnectionPoint target = getDestination();
    if (target == null) {
      text.append(Messages.SiteConnection_LBL_NoDestination);
    } else {
      ConnectionPointType type = CoreIOPlugin.getConnectionPointManager().getType(target);
      if (type != null) {
        text.append(type.getName()).append(':');
      }
      text.append(target.getName());
    }
    text.append(')');

    return text.toString();
  }
  public void widgetSelected(SelectionEvent e) {
    Object source = e.getSource();

    if (source == newSiteButton) {
      final Shell shell = getShell();
      Dialog dlg =
          new FTPPropertyDialogProvider()
              .createPropertyDialog(
                  new IShellProvider() {

                    public Shell getShell() {
                      return shell;
                    }
                  });
      if (dlg instanceof IPropertyDialog) {
        ((IPropertyDialog) dlg)
            .setPropertySource(
                CoreIOPlugin.getConnectionPointManager().getType(IBaseFTPConnectionPoint.TYPE_FTP));
      }
      int ret = dlg.open();

      if (ret == Window.OK) {
        populateTable();

        if (dlg instanceof IPropertyDialog) {
          checkItem((IConnectionPoint) ((IPropertyDialog) dlg).getPropertySource());
        }
      }
    } else if (source == syncOnFinish) {
      setSynchronize(syncOnFinish.getSelection());
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.jface.dialogs.Dialog#okPressed()
  */
 @Override
 protected void okPressed() {
   if (!isValid()) {
     return;
   }
   if (savePropertiesTo(genericConnectionPoint)) {
     /* TODO: notify */
   }
   if (isNew) {
     CoreIOPlugin.getConnectionPointManager().addConnectionPoint(genericConnectionPoint);
   }
   super.okPressed();
 }
  private void populateTable() {
    connectionTable.removeAll();

    IConnectionPointManager manager = CoreIOPlugin.getConnectionPointManager();
    IConnectionPoint[] remoteSites =
        manager
            .getConnectionPointCategory(IBaseRemoteConnectionPoint.CATEGORY)
            .getConnectionPoints();
    for (IConnectionPoint site : remoteSites) {
      if (site instanceof IBaseRemoteConnectionPoint) {
        TableItem item = new TableItem(connectionTable, SWT.NONE);
        item.setText(
            MessageFormat.format(
                "{0}: {1}", manager.getType(site).getName(), site.getName())); // $NON-NLS-1$
        item.setData(site);
      }
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);

    if (genericConnectionPoint != null) {
      setTitle("Edit the Connection");
      getShell().setText("Edit Connection");
    } else {
      setTitle("Create a Connection");
      getShell().setText("New Connection");
    }

    Composite container = new Composite(dialogArea, SWT.NONE);
    container.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    container.setLayout(
        GridLayoutFactory.swtDefaults()
            .margins(
                convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN),
                convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN))
            .spacing(
                convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING),
                convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING))
            .numColumns(2)
            .create());

    /* row 1 */
    Label label = new Label(container, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                new PixelConverter(label)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());
    label.setText(StringUtils.makeFormLabel("Name"));

    nameText = new Text(container, SWT.SINGLE | SWT.BORDER);
    nameText.setLayoutData(
        GridDataFactory.fillDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT)
            .grab(true, false)
            .create());

    /* row 2 */
    label = new Label(container, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                new PixelConverter(label)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());
    label.setText(StringUtils.makeFormLabel("URI"));

    uriText = new Text(container, SWT.SINGLE | SWT.BORDER);
    uriText.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT)
            .grab(true, false)
            .create());

    /* -- */
    addListeners();

    if (genericConnectionPoint == null) {
      try {
        genericConnectionPoint =
            (GenericConnectionPoint)
                CoreIOPlugin.getConnectionPointManager()
                    .createConnectionPoint(getConnectionPointType());
        genericConnectionPoint.setName(DEFAULT_NAME);
        isNew = true;
      } catch (CoreException e) {
        IdeLog.logError(IOUIPlugin.getDefault(), "Create new connection failed", e);
        close();
      }
    }
    loadPropertiesFrom(genericConnectionPoint);

    return dialogArea;
  }