use of org.eclipse.ltk.core.refactoring.PerformRefactoringOperation in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.eclipse.ltk.core.refactoring.PerformRefactoringOperation in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method refreshName.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.IUIRefresher#refreshName()
*/
@Override
public void refreshName() {
ICompilationUnit unit = (ICompilationUnit) this.getInputJavaElement();
String newName = item.getProperty().getLabel();
try {
boolean noError = true;
// String newName2 = newName + SuffixConstants.SUFFIX_STRING_java;
//$NON-NLS-1$
String newName2 = newName + ".java";
if (item instanceof RoutineItem && !unit.getElementName().equals(newName2)) {
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
processor.setNewElementName(newName2);
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus != null && conditionStatus.hasError()) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String errorMessage = "Rename " + unit.getElementName() + " to " + newName + " has errors!";
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
//$NON-NLS-1$
MessageDialog.openError(this.getSite().getShell(), "Warning", errorMessage);
noError = false;
}
}
if (noError) {
doSave(null);
}
setName();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.ltk.core.refactoring.PerformRefactoringOperation in project jbosstools-hibernate by jbosstools.
the class HibernateConsolePlugin method listenForConfigurations.
private void listenForConfigurations() {
final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
kcl = new KnownConfigurationsAdapter() {
/**
* @param root
* @param forUpdate - shows whether physical removal necessary
*/
public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
if (!forUpdate) {
try {
removeConfiguration(root.getName());
} catch (CoreException e) {
logErrorMessage(HibernateConsoleMessages.HibernateConsolePlugin_could_not_delete_launch_config_for + root.getName(), e);
}
}
}
};
KnownConfigurations.getInstance().addConsoleConfigurationListener(kcl);
icl = new ILaunchConfigurationListener() {
boolean isConsoleConfiguration(ILaunchConfiguration configuration) {
try {
return configuration.getType().getIdentifier().equals(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
} catch (CoreException e) {
// HibernateConsolePlugin.getDefault().log( e );
// ignore since it occurs on delete
}
return false;
}
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
ConsoleConfiguration cfg = KnownConfigurations.getInstance().find(configuration.getName());
if (cfg != null) {
// file system removal have been made already.
KnownConfigurations.getInstance().removeConfiguration(cfg, true);
}
}
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
if (configuration.isWorkingCopy() || isTemporary(configuration)) {
return;
}
if (isConsoleConfiguration(configuration)) {
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfiguration oldcfg = instance.find(configuration.getName());
if (oldcfg != null) {
// reset it no matter what.
oldcfg.reset();
} else {
// A new one!
ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
instance.addConfiguration(new ConsoleConfiguration(adapter), true);
}
}
}
private ConsoleConfigurationPreferences buildConfigurationPreferences(ILaunchConfiguration configuration) {
return new EclipseLaunchConsoleConfigurationPreferences(configuration);
}
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
if (isConsoleConfiguration(configuration)) {
ILaunchConfiguration movedFrom = launchManager.getMovedFrom(configuration);
if (movedFrom != null && isConsoleConfiguration(movedFrom)) {
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfiguration oldcfg = instance.find(movedFrom.getName());
if (oldcfg != null) {
// call this before we remove old configuration
refactor(movedFrom, configuration);
// reset it no matter what.
oldcfg.reset();
instance.removeConfiguration(oldcfg, false);
}
}
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
boolean temporary = isTemporary(configuration);
if (!temporary) {
instance.addConfiguration(new ConsoleConfiguration(adapter), true);
}
}
}
private void refactor(ILaunchConfiguration oldConfiguration, ILaunchConfiguration newConfiguration) {
if (!oldConfiguration.getName().equals(newConfiguration.getName())) {
// only rename of console configuration refactoring is supported.
ConsoleConfigurationRenameProcessor proc = new ConsoleConfigurationRenameProcessor(oldConfiguration, newConfiguration.getName());
// Refactor for rename
PerformRefactoringOperation refOperation = new PerformRefactoringOperation(new ProcessorBasedRefactoring(proc), CheckConditionsOperation.ALL_CONDITIONS);
try {
ResourcesPlugin.getWorkspace().run(refOperation, null);
} catch (OperationCanceledException oce) {
throw new OperationCanceledException();
} catch (CoreException ce) {
HibernateConsolePlugin.openError(new Shell(), HibernateConsoleMessages.EditConsoleConfiguration_rename_refactoring_error_totle, ce.getLocalizedMessage(), ce, HibernateConsolePlugin.PERFORM_SYNC_EXEC);
}
}
}
private boolean isTemporary(ILaunchConfiguration configuration) {
boolean temporary = true;
try {
temporary = configuration.getAttribute(AddConfigurationAction.TEMPORARY_CONFIG_FLAG, false);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().showError(getShell(), HibernateConsoleMessages.HibernateConsolePlugin_problem_to_get_flag, e);
}
return temporary;
}
};
launchManager.addLaunchConfigurationListener(icl);
}
use of org.eclipse.ltk.core.refactoring.PerformRefactoringOperation in project eclipse.platform.runtime by eclipse.
the class ConvertMessageBundleAction method run.
@Override
public void run(IAction action) {
if (fAccessorUnit == null)
return;
try {
final GotoResourceAction pAction = new GotoResourceAction(fPart);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
pAction.run();
}
};
PlatformUI.getWorkbench().getProgressService().run(false, false, runnable);
IFile propertiesFile = (IFile) pAction.getResource();
if (propertiesFile == null)
return;
MessageBundleRefactoring refactoring = new MessageBundleRefactoring(fAccessorUnit.getTypes()[0], propertiesFile);
PerformRefactoringOperation op = new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
PlatformUI.getWorkbench().getProgressService().run(false, false, new WorkbenchRunnableAdapter(op));
} catch (CoreException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.ltk.core.refactoring.PerformRefactoringOperation in project eclipse.platform.runtime by eclipse.
the class RemoveUnusedMessagesAction method run.
@Override
public void run(IAction action) {
if (fAccessorUnit == null)
return;
try {
final GotoResourceAction pAction = new GotoResourceAction(fPart);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
pAction.run();
}
};
PlatformUI.getWorkbench().getProgressService().run(false, false, runnable);
IFile propertiesFile = (IFile) pAction.getResource();
if (propertiesFile == null)
return;
RemoveUnusedMessages refactoring = new RemoveUnusedMessages(fAccessorUnit.getTypes()[0], propertiesFile);
PerformRefactoringOperation op = new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
PlatformUI.getWorkbench().getProgressService().run(false, true, new WorkbenchRunnableAdapter(op));
} catch (CoreException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Aggregations