@Override
 protected String getLabel(TreePath elementPath, IPresentationContext context, String columnId)
     throws CoreException {
   if (columnId == null) {
     // when no columns, handle special escaping ourselves
     IDebugModelPresentation presentation = getCeylonJDIModelPresentation();
     if (presentation != null) {
       return presentation.getText(elementPath.getLastSegment());
     }
   }
   return super.getLabel(elementPath, context, columnId);
 }
  /**
   * Show a selection dialog that allows the user to choose one of the connections to use to build
   * the Image.
   *
   * @param connections Array of connections.
   * @return The chosen connection, or <code>null</code> if the user cancelled the dialog.
   */
  protected IDockerConnection chooseConnection(final IDockerConnection[] connections) {
    IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
    ElementListSelectionDialog dialog =
        new ElementListSelectionDialog(
            getActiveWorkbenchShell(), new ConnectionSelectionLabelProvider() {});

    dialog.setElements(connections);
    dialog.setTitle(LaunchMessages.getString(LaunchShortcut_Connection_Selection));
    dialog.setMessage(LaunchMessages.getString(LaunchShortcut_Choose_Connection));
    dialog.setMultipleSelection(false);
    int result = dialog.open();
    labelProvider.dispose();
    if (result == IStatus.OK) {
      return (IDockerConnection) dialog.getFirstResult();
    }
    return null;
  }
Example #3
0
  protected void displayResult(final IScriptEvaluationResult result) {
    // Errors
    if (result.hasErrors()) {
      final Display display = DLTKDebugUIPlugin.getStandardDisplay();
      display.asyncExec(
          new Runnable() {
            public void run() {
              if (display.isDisposed()) {
                return;
              }

              reportErrors(result);
              evaluationCleanup();
            }
          });
      return;
    }

    final String snippet = result.getSnippet();
    IScriptValue resultValue = result.getValue();

    final String typeName = resultValue.getType().getName();

    IDebugModelPresentation presentation =
        getDebugModelPresentation(result.getThread().getModelIdentifier());
    presentation.computeDetail(
        resultValue,
        new IValueDetailListener() {
          public void detailComputed(IValue value, String result) {
            displayStringResult(
                snippet,
                MessageFormat.format(
                    Messages.ScriptDisplayAction_displayResult,
                    new Object[] {typeName, trimDisplayResult(result)}));
          }
        });

    presentation.dispose();
    // displayStringResult(snippet, getExceptionMessage(x));
  }
  private ILaunchConfiguration getLaunchConfiguration(IContainer basedir, String mode) {
    if (goalName != null) {
      return createLaunchConfiguration(basedir, goalName);
    }

    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType launchConfigurationType =
        launchManager.getLaunchConfigurationType(MavenLaunchConstants.LAUNCH_CONFIGURATION_TYPE_ID);

    // scan existing launch configurations
    IPath basedirLocation = basedir.getLocation();
    if (!showDialog) {
      try {
        //        ILaunch[] launches = launchManager.getLaunches();
        //        ILaunchConfiguration[] launchConfigurations = null;
        //        if(launches.length > 0) {
        //          for(int i = 0; i < launches.length; i++ ) {
        //            ILaunchConfiguration config = launches[i].getLaunchConfiguration();
        //            if(config != null && launchConfigurationType.equals(config.getType())) {
        //              launchConfigurations = new ILaunchConfiguration[] {config};
        //            }
        //          }
        //        }
        //        if(launchConfigurations == null) {
        //          launchConfigurations =
        // launchManager.getLaunchConfigurations(launchConfigurationType);
        //        }

        ILaunchConfiguration[] launchConfigurations =
            launchManager.getLaunchConfigurations(launchConfigurationType);
        ArrayList<ILaunchConfiguration> matchingConfigs = new ArrayList<ILaunchConfiguration>();
        for (ILaunchConfiguration configuration : launchConfigurations) {
          // substitute variables
          String workDir =
              LaunchingUtils.substituteVar(
                  configuration.getAttribute(MavenLaunchConstants.ATTR_POM_DIR, (String) null));
          if (workDir == null) {
            continue;
          }
          IPath workPath = new Path(workDir);
          if (basedirLocation.equals(workPath)) {
            matchingConfigs.add(configuration);
          }
        }

        if (matchingConfigs.size() == 1) {
          log.info("Using existing launch configuration");
          return matchingConfigs.get(0);
        } else if (matchingConfigs.size() > 1) {
          final IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
          ElementListSelectionDialog dialog =
              new ElementListSelectionDialog(
                  getShell(), //
                  new ILabelProvider() {
                    public Image getImage(Object element) {
                      return labelProvider.getImage(element);
                    }

                    public String getText(Object element) {
                      if (element instanceof ILaunchConfiguration) {
                        ILaunchConfiguration configuration = (ILaunchConfiguration) element;
                        try {
                          return labelProvider.getText(element)
                              + " : "
                              + configuration.getAttribute(MavenLaunchConstants.ATTR_GOALS, "");
                        } catch (CoreException ex) {
                          // ignore
                        }
                      }
                      return labelProvider.getText(element);
                    }

                    public boolean isLabelProperty(Object element, String property) {
                      return labelProvider.isLabelProperty(element, property);
                    }

                    public void addListener(ILabelProviderListener listener) {
                      labelProvider.addListener(listener);
                    }

                    public void removeListener(ILabelProviderListener listener) {
                      labelProvider.removeListener(listener);
                    }

                    public void dispose() {
                      labelProvider.dispose();
                    }
                  });
          dialog.setElements(
              matchingConfigs.toArray(new ILaunchConfiguration[matchingConfigs.size()]));
          dialog.setTitle(Messages.ExecutePomAction_dialog_title);
          if (mode.equals(ILaunchManager.DEBUG_MODE)) {
            dialog.setMessage(Messages.ExecutePomAction_dialog_debug_message);
          } else {
            dialog.setMessage(Messages.ExecutePomAction_dialog_run_message);
          }
          dialog.setMultipleSelection(false);
          int result = dialog.open();
          labelProvider.dispose();
          return result == Window.OK ? (ILaunchConfiguration) dialog.getFirstResult() : null;
        }

      } catch (CoreException ex) {
        log.error(ex.getMessage(), ex);
      }
    }

    log.info("Creating new launch configuration");

    String newName =
        launchManager.generateUniqueLaunchConfigurationNameFrom(basedirLocation.lastSegment());
    try {
      ILaunchConfigurationWorkingCopy workingCopy =
          launchConfigurationType.newInstance(null, newName);
      workingCopy.setAttribute(MavenLaunchConstants.ATTR_POM_DIR, basedirLocation.toString());

      setProjectConfiguration(workingCopy, basedir);

      // set other defaults if needed
      // MavenLaunchMainTab maintab = new MavenLaunchMainTab();
      // maintab.setDefaults(workingCopy);
      // maintab.dispose();

      return workingCopy.doSave();
    } catch (Exception ex) {
      log.error("Error creating new launch configuration", ex);
    }
    return null;
  }