Java Code Examples for org.eclipse.osgi.util.NLS#bind()

The following examples show how to use org.eclipse.osgi.util.NLS#bind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectDisconnectAction.java    From codewind-eclipse with Eclipse Public License 2.0 7 votes vote down vote up
public static void connectRemoteCodewind(RemoteConnection conn) {
	Job job = new Job(NLS.bind(Messages.ConnectJobLabel, conn.getBaseURI())) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				conn.connect(monitor);
				CodewindUIPlugin.getUpdateHandler().updateConnection(conn);
				return Status.OK_STATUS;
			} catch (Exception e) {
				Logger.logError("An error occurred connecting to: " + conn.getBaseURI(), e); //$NON-NLS-1$
				return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.ConnectJobError, conn.getBaseURI()), e);
			}
		}
	};
	job.schedule();
}
 
Example 2
Source File: BindProjectWizard.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void cleanup(String projectName, CodewindConnection connection) {
	Job job = new Job(NLS.bind(Messages.ProjectCleanupJobLabel, projectName)) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			SubMonitor mon = SubMonitor.convert(monitor, 30);
			mon.split(10);
			connection.refreshApps(null);
			CodewindApplication app = connection.getAppByName(projectName);
			if (app != null) {
				try {
					ProjectUtil.removeProject(app.name, app.projectID, mon.split(20));
				} catch (Exception e) {
					Logger.logError("An error occurred while trying to remove the project after bind project terminated for: " + projectName, e);
					return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.ProjectCleanupError, projectName), null);
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.schedule();
}
 
Example 3
Source File: CheckConfigurationWorkingCopy.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Changes the name of the check configuration.
 *
 * @param name
 *          the new name
 * @throws CheckstylePluginException
 *           if name is <code>null</code> or empty or a name collision with an existing check
 *           configuration exists
 */
public void setName(String name) throws CheckstylePluginException {

  if (name == null || name.trim().length() == 0) {
    throw new CheckstylePluginException(Messages.errorConfigNameEmpty);
  }

  String oldName = getName();
  if (!name.equals(oldName)) {

    mEditedName = name;

    // Check if the new name is in use
    if (mWorkingSet.isNameCollision(this)) {
      mEditedName = oldName;
      throw new CheckstylePluginException(NLS.bind(Messages.errorConfigNameInUse, name));
    }
  }
}
 
Example 4
Source File: CodewindEclipseApplication.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void deleteProject() {
	Job job = new Job(NLS.bind(Messages.DeleteProjectJobLabel, name)) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				IProject project = CoreUtil.getEclipseProject(CodewindEclipseApplication.this);
				if (project != null) {
					project.delete(true, true, monitor);
				} else if (fullLocalPath.toFile().exists()) {
					FileUtil.deleteDirectory(fullLocalPath.toOSString(), true);
				} else {
					Logger.log("No project contents were found to delete for application: " + name);
				}
			} catch (Exception e) {
				Logger.logError("Error deleting project contents: " + name, e); //$NON-NLS-1$
				return new Status(IStatus.ERROR, CodewindCorePlugin.PLUGIN_ID, NLS.bind(Messages.DeleteProjectError, name), e);
			}
			if (monitor.isCanceled()) {
				return Status.CANCEL_STATUS;
			}
			return Status.OK_STATUS;
		}
	};
	job.schedule();
}
 
Example 5
Source File: NewCodewindConnectionWizard.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean performFinish() {
	if(!canFinish()) {
		return false;
	}

	Job job = new Job(NLS.bind(Messages.NewConnectionWizard_CreateJobTitle, newConnectionPage.getConnectionName())) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			return newConnectionPage.createConnection(monitor);
		}
	};
	job.schedule();

	return true;
}
 
Example 6
Source File: MergeTask.java    From MergeProcessor with Apache License 2.0 6 votes vote down vote up
/**
 * Asks the user if an already finished merge unit should really be executed.
 * 
 * @return {@code true} if an already finished merge unit should really be
 *         executed
 */
private boolean askUserToMergeFinishedMergeUnit() {
	final MergeUnitStatus status = mergeUnit.getStatus();
	String dialogMessage = NLS.bind(Messages.View_MergeSelection_Ignored_Todo_Question, mergeUnit.getFileName(),
			status);
	MessageDialog dialog = new MessageDialog(shellProvider.getShell(),
			Messages.View_MergeSelection_Ignored_Todo_Title, null, dialogMessage, MessageDialog.INFORMATION,
			new String[] { Messages.View_MergeSelection_Ignored_Todo_Yes,
					Messages.View_MergeSelection_Ignored_Todo_No },
			0);

	int choice = dialog.open();

	if (choice != 0) {
		// user didn't say 'yes' so we skip it...
		LOGGER.fine(() -> String.format("User skipped mergeUnit=%s with status %s.", mergeUnit, status));
		return false;
	}
	return true;
}
 
Example 7
Source File: CodewindDebugConnector.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private static String getDebugLaunchName(String projectName, String host, String debugPort) {
	return NLS.bind(Messages.DebugLaunchConfigName,
			new Object[] {
					projectName,
					host,
					debugPort
			});
}
 
Example 8
Source File: ShowAllLogsAction.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
  public void run() {
      if (app == null) {
      	// should not be possible
      	Logger.logError("ShowAllLogsAction ran but no application was selected"); //$NON-NLS-1$
	return;
}
      
      if (app.getLogInfos() == null || app.getLogInfos().isEmpty()) {
      	Logger.logError("ShowAllLogsAction ran but there are no logs for the selected application: " + app.name); //$NON-NLS-1$
      	return;
      }
      
      // Create consoles for any log files that don't have one yet
      Job job = new Job(NLS.bind(Messages.ShowAllLogFilesJobLabel, app.name)) {
	@Override
	protected IStatus run(IProgressMonitor monitor) {
		try {
			for (ProjectLogInfo logInfo : app.getLogInfos()) {
				if (app.getConsole(logInfo) == null) {
					SocketConsole console = CodewindConsoleFactory.createLogFileConsole(app, logInfo);
					ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
					app.addConsole(console);
				}
			}
			return Status.OK_STATUS;
		} catch (Exception e) {
			Logger.logError("An error occurred opening the log files for: " + app.name + ", with id: " + app.projectID, e); //$NON-NLS-1$ //$NON-NLS-2$
			return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.ShowAllLogFilesError, app.name), e);
		}
	}
};
job.schedule();
  }
 
Example 9
Source File: ProjectConfigurationType.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected URL resolveLocation(ICheckConfiguration checkConfiguration) throws IOException {
  IResource configFileResource = ResourcesPlugin.getWorkspace().getRoot()
          .findMember(checkConfiguration.getLocation());

  if (configFileResource != null) {
    return configFileResource.getLocation().toFile().toURI().toURL();
  } else {
    throw new FileNotFoundException(NLS.bind(Messages.ProjectConfigurationType_msgFileNotFound,
            checkConfiguration.getLocation()));
  }
}
 
Example 10
Source File: ConnectDisconnectAction.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	if (conn == null) {
		// should not be possible
		Logger.logError("ConnectDisconnectAction ran but a remote connection was not selected"); //$NON-NLS-1$
		return;
	}
	
	if (conn.isConnected()) {
		Job job = new Job(NLS.bind(Messages.DisconnectJobLabel, conn.getBaseURI())) {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				try {
					conn.disconnect();
					CodewindUIPlugin.getUpdateHandler().updateConnection(conn);
					return Status.OK_STATUS;
				} catch (Exception e) {
					Logger.logError("An error occurred disconnecting from: " + conn.getBaseURI(), e); //$NON-NLS-1$
					return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.DisconnectJobError, conn.getBaseURI()), e);
				}
			}
		};
		job.schedule();
	} else {
		connectRemoteCodewind(conn);
	}
}
 
Example 11
Source File: Executor.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
/**
 * Run the given command, dealing with any exceptions.
 * @param command the command to run
 * @throws CoreException on error
 */
public void run(Command command) throws CoreException {
	try {
		command.run();
	}
	catch (Exception ex) {
		if (ex instanceof CoreException) {
			throw (CoreException) ex;
		}
		String msg = NLS.bind(this.failureMessage, ex.getMessage());
		throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, -1, msg, ex));
	}
}
 
Example 12
Source File: SVNMergeUtil.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
public static boolean copyLocalToDone(SVNMergeUnit mergeUnit) {
	LogUtil.entering(mergeUnit);

	boolean cancel = false;
	while (!cancel) {
		try {
			SftpUtil.getInstance().copyMergeUnitFromWorkToDoneAndDeleteInTodo(mergeUnit);
			mergeUnit.setStatus(MergeUnitStatus.DONE);
			break;
		} catch (SftpUtilException e) {
			String logMessage = String.format("Caught exception while copying from work to done. mergeUnit=[%s]", //$NON-NLS-1$
					mergeUnit);
			LOGGER.log(Level.WARNING, logMessage, e);

			String message = NLS.bind(Messages.MergeProcessorUtil_CopyLocalToDone_Error_Message, Choices.CANCEL,
					MergeUnitStatus.TODO);
			String messageScrollable = NLS.bind(Messages.MergeProcessorUtil_CopyLocalToDone_Error_Details,
					e.getMessage());
			if (MergeProcessorUtil.bugUserToFixProblem(message, messageScrollable)) {
				// user wants to retry
				LOGGER.fine(String.format("User wants to retry copying the merge file to the server. mergeUnit=%s.", //$NON-NLS-1$
						mergeUnit));
				continue;
			} else {
				// user didn't say 'retry' so we cancel the whole merge...
				LOGGER.fine(String.format("User cancelled committing changes from the working copy. mergeUnit=%s.", //$NON-NLS-1$
						mergeUnit));
				cancel = true;
			}
		}
	}

	return LogUtil.exiting(cancel);
}
 
Example 13
Source File: SVNMergeUtil.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
private static boolean mergeChangesIntoWorkingCopy(final SVNMergeUnit mergeUnit, final ISvnClient client) {
	LogUtil.entering(mergeUnit);

	boolean cancel = false;
	boolean success = false;
	while (!cancel && !success) {
		try {
			SvnUtil.mergeChanges(mergeUnit, client);
			success = true;
		} catch (SvnUtilException e) {
			LOGGER.log(Level.WARNING, "Caught exception while merging changes into working copy.", e); //$NON-NLS-1$
			String messageScrollable = NLS.bind(
					Messages.MergeProcessorUtil_MergeChangesIntoWorkingCopy_Error_Message_Prefix, e.getMessage());
			if (MergeProcessorUtil.bugUserToFixProblem(
					Messages.MergeProcessorUtil_MergeChangesIntoWorkingCopy_Error_Title, messageScrollable)) {
				// user wants to retry
				LOGGER.fine(String.format("User wants to retry merging changes into working copy for mergeUnit=%s.", //$NON-NLS-1$
						mergeUnit));
				continue;
			} else {
				// user didn't say 'retry' so we cancel the whole merge...
				LOGGER.fine(String.format("User cancelled merging changes into working copy for mergeUnit=%s.", //$NON-NLS-1$
						mergeUnit));
				cancel = true;
			}
		}
	}

	if (!success) {
		// if we haven't had success we cancel. we can't continue without success.
		cancel = true;
	}

	return LogUtil.exiting(cancel);
}
 
Example 14
Source File: CodewindConnectionComposite.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IStatus updateConnection(IProgressMonitor monitor) {
	SubMonitor mon = SubMonitor.convert(monitor, 100);
	
	if (connection.isConnected()) {
		connection.disconnect();
	}
	try {
		ConnectionUtil.updateConnection(connection.getConid(), name, url, user, mon.split(20));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
		connection.setName(name);
		connection.setBaseURI(new URI(url));
		connection.setUsername(user);
		
		AuthToken token = AuthUtil.genAuthToken(user, pass, connection.getConid(), mon.split(30));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
		connection.setAuthToken(token);
		
		connection.connect(mon.split(50));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
	} catch (Exception e) {
		return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.CodewindConnectionUpdateError, name), e);
	} finally {
		ViewHelper.openCodewindExplorerView();
		CodewindUIPlugin.getUpdateHandler().updateConnection(connection);
	}
	
	return Status.OK_STATUS;
}
 
Example 15
Source File: MergeProcessorUtil.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * Moves mergeUnit from its current folder on the sftp server to the ignored
 * folder.
 * 
 * @param mergeUnit
 */
public static void ignore(IMergeUnit mergeUnit) {
	LogUtil.entering(mergeUnit);
	boolean cancel = false;

	while (!cancel) {
		try {
			SftpUtil.getInstance().moveMergeUnitFromRemoteToIgnore(mergeUnit);
			mergeUnit.setStatus(MergeUnitStatus.IGNORED);
			break;
		} catch (SftpUtilException e) {
			String message = String.format("Caught exception while moving mergeUnit=[%s] to ignore.", mergeUnit); //$NON-NLS-1$
			LOGGER.log(Level.WARNING, message, e);

			String messageScrollable = NLS.bind(Messages.MergeProcessorUtil_Ignore_Error_Message, e.getMessage());
			if (bugUserToFixProblem(Messages.MergeProcessorUtil_Ignore_Error_Title, messageScrollable)) {
				// user wants to retry
				LOGGER.fine(String.format("User wants to retry ignore mergeUnit. mergeUnit=%s.", mergeUnit)); //$NON-NLS-1$
				continue;
			} else {
				// user didn't say 'retry' so we cancel the whole merge...
				LOGGER.fine(String.format("User cancelled ignore mergeUnit. mergeUnit=%s.", mergeUnit)); //$NON-NLS-1$
				cancel = true;
			}
		}
	}
	LogUtil.exiting();
}
 
Example 16
Source File: CheckConfigurationPropertiesDialog.java    From eclipse-cs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Initialize the dialogs controls with the data.
 */
private void initialize() {

  if (mCheckConfig == null) {

    IConfigurationType[] types = mTemplate != null
            ? ConfigurationTypes.getConfigurableConfigTypes()
            : ConfigurationTypes.getCreatableConfigTypes();

    mCheckConfig = mWorkingSet.newWorkingCopy(types[0]);

    if (mTemplate != null) {

      this.setTitle(NLS.bind(Messages.CheckConfigurationPropertiesDialog_titleCopyConfiguration,
              mTemplate.getName()));
      this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgCopyConfiguration);

      String nameProposal = NLS.bind(Messages.CheckConfigurationPropertiesDialog_CopyOfAddition,
              mTemplate.getName());
      setUniqueName(mCheckConfig, nameProposal);
      mCheckConfig.setDescription(mTemplate.getDescription());
      mCheckConfig.getResolvableProperties().addAll(mTemplate.getResolvableProperties());
    } else {
      this.setTitle(Messages.CheckConfigurationPropertiesDialog_titleCheckConfig);
      this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgCreateNewCheckConfig);
    }

    mConfigType.setInput(types);
    mConfigType.setSelection(new StructuredSelection(types[0]), true);

    createConfigurationEditor(mCheckConfig);
  } else {
    this.setTitle(Messages.CheckConfigurationPropertiesDialog_titleCheckConfig);
    this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgEditCheckConfig);

    mConfigType.getCombo().setEnabled(false);
    mConfigType.setInput(new IConfigurationType[] { mCheckConfig.getType() });

    // type of existing configs cannot be changed
    mConfigType.setSelection(new StructuredSelection(mCheckConfig.getType()), true);
    createConfigurationEditor(mCheckConfig);
  }
}
 
Example 17
Source File: ExplicitInitializationQuickfix.java    From eclipse-cs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getLabel() {
  return NLS.bind(Messages.ExplicitInitializationQuickfix_label, mFieldName);
}
 
Example 18
Source File: SvnUtil.java    From MergeProcessor with Apache License 2.0 4 votes vote down vote up
/**
 * Updates an existing, empty working copy so it contains the files needed for
 * the merge.
 * 
 * @param mergeUnit
 * @return <code>true</code> if the user cancelled the operation
 * @throws SvnUtilException
 */
private static boolean setupWorkingCopy(SVNMergeUnit mergeUnit, ISvnClient client) throws SvnUtilException {
	LogUtil.entering(mergeUnit);
	boolean cancel = false;

	final List<String> neededFiles = mergeUnit.getAffectedTargetFiles();
	final List<String> targetFile = new ArrayList<>(neededFiles);
	targetFile.addAll(mergeUnit.getTargetFilesToDelete());

	File workingCopy = new File(Configuration.getPathSvnWorkingCopy());
	if (!workingCopy.exists()) {
		workingCopy.mkdirs();
	}

	List<Path> paths = getPaths(targetFile, workingCopy);
	updateEmptyPath(paths, client);

	// check if files are missing.
	// files might be missing when they have been renamed in the target
	// branch.
	List<Path> missingFiles = getMissingFiles(paths, mergeUnit, workingCopy);

	if (!missingFiles.isEmpty()) {
		// so there are files missing...
		// inform the user about the missing files.
		// we give the user to choices
		// * 1 cancel the merge.
		// * 2 continue the merge without merging the missing files. the user must merge
		// the missing files manually.


		String joinedMissingFiles = Joiner.on(",\n\t").join(missingFiles); //$NON-NLS-1$
		LOGGER.info(() -> String.format("Found %s missing files:%n%s", missingFiles.size(), joinedMissingFiles)); //$NON-NLS-1$

		String workingFolderManual = "C:\\dev\\manual_merge\\"; //$NON-NLS-1$

		String dialogMessageScrollable = getDialogScrollableMessage(joinedMissingFiles, workingFolderManual,
				mergeUnit);

		String dialogMessage = NLS.bind(Messages.SvnUtilSvnkit_MovedFiles_Description, missingFiles.size());
		final MessageDialog dialog = new MessageDialogScrollable(ApplicationUtil.getApplicationShell(),
				Messages.SvnUtilSvnkit_MovedFiles_Title, null, dialogMessage, dialogMessageScrollable,
				MessageDialog.WARNING, new String[] { Messages.SvnUtilSvnkit_MovedFiles_CancelMerge,
						Messages.SvnUtilSvnkit_MovedFiles_ContinueWithoutMergingMissingFiles },
				0);

		final AtomicInteger choice = new AtomicInteger();
		E4CompatibilityUtil.getApplicationContext().get(UISynchronize.class)
				.syncExec(() -> choice.set(dialog.open()));

		if (choice.get() == 0) {
			LOGGER.info("User cancelled merged because of missing files."); //$NON-NLS-1$
			cancel = true;
		} else {
			LOGGER.info("User continues merge despite of missing files."); //$NON-NLS-1$
		}
	}

	return LogUtil.exiting(cancel);
}
 
Example 19
Source File: BuildProjectJob.java    From eclipse-cs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Creates an operation which builds a project.
 *
 * @param project
 *          the project to build
 * @param buildKind
 *          the kind of build to do
 */
public BuildProjectJob(IProject project, int buildKind) {
  super(NLS.bind(Messages.BuildProjectJob_msgBuildProject, project.getName()));
  mProjects = new IProject[] { project };
  mKind = buildKind;
}
 
Example 20
Source File: CheckstyleLog.java    From eclipse-cs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Logs the exception, describing it with the given message.
 * 
 * @param t
 *          the exception to log
 * @param message
 *          the message
 */
public static void log(Throwable t, String message) {
  Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.OK,
          NLS.bind(Messages.CheckstyleLog_msgStatusPrefix, message), t);
  sLog.log(status);
}