Пример #1
0
  protected void validate() {
    boolean fail = true;
    if (textPortName.getText().trim().equals("")) setErrorMessage("Connection name can't be empty");
    else if (client.getConnectionPool().hasConnection(textPortName.getText().trim()))
      setErrorMessage("Connection name has already been used by other port");
    else if (familyList.getSelection().isEmpty())
      setErrorMessage("Should select at least one family");
    else if (textServerAddress.getText().trim().equals(""))
      setErrorMessage("Server address can't be empty");
    else if (Util.getInt(textServerPort.getText().trim(), 0) == 0)
      setErrorMessage("The server port format is incorrect");
    else if (chkUdp.getSelection() && comboProxyType.getSelectionIndex() == 1)
      setErrorMessage("Can't use Http proxy with UDP mode");
    else if (comboProxyType.getSelectionIndex() != 0
        && textProxyAddress.getText().trim().equals(""))
      setErrorMessage("Proxy address can't be empty");
    else if (comboProxyType.getSelectionIndex() != 0
        && Util.getInt(textProxyPort.getText().trim(), 0) == 0)
      setErrorMessage("The proxy port format is incorrect");
    else {
      setErrorMessage(null);
      fail = false;
    }

    getButton(IDialogConstants.OK_ID).setEnabled(!fail);
  }
  public String getSelectedFileExt() {
    //		String[] selection = fileExtList.getSelection();
    //		if (selection.length > 0)
    //			return selection[0];
    //		else
    //			return null;

    if (fileExtListViewer.getSelection() instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection =
          (IStructuredSelection) fileExtListViewer.getSelection();
      if (structuredSelection.getFirstElement() instanceof String) {
        String selection = (String) structuredSelection.getFirstElement();
        System.out.println("selected entry: " + selection); // $NON-NLS-1$
        return selection;
      }
    }
    return null;
  }
  public void updateList() {

    //		String[] selection = fileExtList.getSelection();
    //		fileExtList.removeAll();
    //		SortedSet<String> keys = new TreeSet<String>();
    //		keys.addAll(delegateConfigs.keySet());
    //		for (String fileExt : keys) {
    //			fileExtList.add(fileExt);
    //		}
    //		fileExtList.setSelection(selection);

    // does only remember the first selection out of a (possible larger) set of selections
    /*		String selection = "";
    if (fileExtListViewer.getSelection() instanceof IStructuredSelection) {
    	IStructuredSelection structuredSelection = (IStructuredSelection) fileExtListViewer.getSelection();
    	if (structuredSelection.getFirstElement() instanceof String) {
    		selection = (String)structuredSelection.getFirstElement();
    	}
    }*/

    String[] selections = null; // = new String[];

    if (fileExtListViewer.getSelection() instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection =
          (IStructuredSelection) fileExtListViewer.getSelection();
      int amountOfChosenEntries = structuredSelection.toList().size();
      selections = new String[amountOfChosenEntries];
      for (int j = 0; j < amountOfChosenEntries; j++) {
        selections[j] = (String) structuredSelection.toList().get(j);
      }
    }

    fileExtListViewer.setInput(null);
    SortedSet<String> keys = new TreeSet<String>();
    keys.addAll(delegateConfigs.keySet());
    for (String fileExt : keys) {
      fileExtListViewer.add(fileExt);
    }

    if (selections != null) {
      fileExtListViewer.getList().setSelection(selections);
    }
  }
 protected void buttonPressed(int buttonId) {
   if (buttonId == IDialogConstants.OK_ID) {
     StructuredSelection sel = (StructuredSelection) listViewer.getSelection();
     Object[] objs = sel.toArray();
     selectedSkills = new int[objs.length];
     for (int i = 0; i < objs.length; i++) {
       selectedSkills[i] = ((SkillConfig) objs[i]).id;
     }
   }
   super.buttonPressed(buttonId);
 }
Пример #5
0
 public void widgetDefaultSelected(final SelectionEvent e) {
   if (e.widget == availableContexts) {
     IStructuredSelection selection =
         (IStructuredSelection) availableContextsViewer.getSelection();
     if (!selection.isEmpty()) {
       Context context = (Context) selection.getFirstElement();
       if (ConfigurationManager.instance.isPlugin(context)) {
         copyAction();
       } else {
         editAction();
       }
     }
   }
 }
Пример #6
0
  protected void copyAction() {
    CopyContextAction action = new CopyContextAction();
    IStructuredSelection selection = (IStructuredSelection) availableContextsViewer.getSelection();
    if (selection.isEmpty()) {
      return;
    }

    Object element = selection.getFirstElement();
    if (element instanceof Context) {
      Context sourceContext = (Context) element;
      try {

        InputDialog dialog =
            new InputDialog(
                getShell(),
                Messages.CustomizationDialog_enterConfigurationName,
                Messages.CustomizationDialog_enterConfigurationName,
                Messages.CustomizationDialog_copyOf + sourceContext.getName(),
                new IInputValidator() {

                  public String isValid(final String newText) {
                    if (newText.trim().equals("")) { // $NON-NLS-1$
                      return Messages.CustomizationDialog_configurationNameNotEmpty;
                    }
                    if (ConfigurationManager.instance.getContext(newText) != null) {
                      return Messages.CustomizationDialog_configurationWithSameNameExists;
                    }
                    return null;
                  }
                });
        dialog.setTitle(Messages.CustomizationDialog_configurationName);
        int result = dialog.open();
        if (result == Window.OK) {
          String targetName = dialog.getText();
          action.copy(sourceContext, targetName, false);
          availableContextsViewer.setInput(ConfigurationManager.instance.getContexts());
        }
      } catch (IOException ex) {
        Activator.log.error(ex);
      }
    }
  }
Пример #7
0
  protected void editAction() {
    EditContextAction action = new EditContextAction();
    IStructuredSelection selection = (IStructuredSelection) availableContextsViewer.getSelection();
    if (selection.isEmpty()) {
      return;
    }

    Object element = selection.getFirstElement();
    if (element instanceof Context) {
      Context sourceContext = (Context) element;
      try {
        action.openEditor(sourceContext);
        close();
      } catch (Exception ex) {
        Activator.log.error(
            "An error occured while initializing the customization editor", ex); // $NON-NLS-1$
        return;
      }
    }
  }
Пример #8
0
  protected void deleteAction() {
    RemoveContextAction action = new RemoveContextAction();
    IStructuredSelection selection = (IStructuredSelection) availableContextsViewer.getSelection();
    if (selection.isEmpty()) {
      return;
    }

    Object element = selection.getFirstElement();
    if (element instanceof Context) {
      Context sourceContext = (Context) element;
      if (ConfigurationManager.instance.isPlugin(sourceContext)) {
        Activator.log.warn(Messages.CustomizationDialog_cannotDeletePluginContext);
        // Plugin context cannot be deleted
        return;
      }

      MessageDialog dialog =
          new MessageDialog(
              getShell(),
              Messages.CustomizationDialog_deleteContext,
              null,
              Messages.CustomizationDialog_deleteContextConfirmation1
                  + sourceContext.getName()
                  + Messages.CustomizationDialog_deleteContextConfirmation2,
              MessageDialog.CONFIRM,
              new String[] {
                IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL
              },
              2);
      int result = dialog.open();
      if (result == 0) { // 0 is "Yes" (It is *not* the same 0 as Window.OK)
        action.removeContext(sourceContext);
        availableContextsViewer.setInput(ConfigurationManager.instance.getContexts());
      }
    }
  }
Пример #9
0
  @Override
  @SuppressWarnings("unchecked")
  protected void okPressed() {
    String portName = textPortName.getText().trim();
    int supportedFamily = 0;
    for (Iterator<Integer> i = ((IStructuredSelection) familyList.getSelection()).iterator();
        i.hasNext(); ) supportedFamily |= i.next();

    IConnection conn = null;

    IConnectionPolicy policy =
        client
            .getConnectionPolicyFactory()
            .createPolicy(
                client,
                portName,
                supportedFamily,
                (Integer) ((IStructuredSelection) familyList.getSelection()).getFirstElement(),
                null,
                null,
                null);
    try {
      if (chkUdp.getSelection()) {
        switch (comboProxyType.getSelectionIndex()) {
          case 0:
            conn =
                client
                    .getConnectionPool()
                    .newUDPConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 2:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newUDPSocks5Connection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
        }
      } else {
        switch (comboProxyType.getSelectionIndex()) {
          case 0:
            conn =
                client
                    .getConnectionPool()
                    .newTCPConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 1:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newTCPHttpConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 2:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newTCPSocks5Connection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
        }
      }
    } catch (UnresolvedAddressException e) {
      conn = null;
    }

    if (conn == null) MessageDialog.openError(getShell(), "Failed", "Create connection failed");
    else super.okPressed();
  }