use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class RenameResourceAndCloseEditorAction method createOperation.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.actions.WorkspaceAction#createOperation(org.eclipse.core.runtime.IStatus[])
*
* Overridden to create and execute an undoable operation that performs the
* rename.
* @since 3.3
*/
protected IRunnableWithProgress createOperation(final IStatus[] errorStatus) {
return new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
IResource[] resources = (IResource[]) getActionResources().toArray(new IResource[getActionResources().size()]);
// been validated.
if (resources.length == 1) {
// check for overwrite
IWorkspaceRoot workspaceRoot = resources[0].getWorkspace().getRoot();
IResource newResource = workspaceRoot.findMember(newPath);
boolean go = true;
if (newResource != null) {
go = checkOverwrite(shellProvider.getShell(), newResource);
}
if (go) {
MoveResourcesOperation op = new MoveResourcesOperation(resources[0], newPath, IDEWorkbenchMessages.RenameResourceAction_operationTitle);
op.setModelProviderIds(getModelProviderIds());
try {
PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
} catch (ExecutionException e) {
if (e.getCause() instanceof CoreException) {
errorStatus[0] = ((CoreException) e.getCause()).getStatus();
} else {
errorStatus[0] = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, getProblemsMessage(), e);
}
}
}
}
}
};
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class DeleteResourceAndCloseEditorAction method scheduleDeleteJob.
/**
* Schedule a job to delete the resources to delete.
* @param resourcesToDelete
*/
private void scheduleDeleteJob(final IResource[] resourcesToDelete) {
// use a non-workspace job with a runnable inside so we can avoid
// periodic updates
Job deleteJob = new Job(IDEWorkbenchMessages.DeleteResourceAction_jobName) {
public IStatus run(final IProgressMonitor monitor) {
try {
final DeleteResourcesOperation op = new DeleteResourcesOperation(resourcesToDelete, IDEWorkbenchMessages.DeleteResourceAction_operationLabel, deleteContent);
op.setModelProviderIds(getModelProviderIds());
// added to the undo history.
if (deleteContent && containsOnlyProjects(resourcesToDelete)) {
// We must compute the execution status first so that any user prompting
// or validation checking occurs. Do it in a syncExec because
// we are calling this from a Job.
WorkbenchJob statusJob = new //$NON-NLS-1$
WorkbenchJob(//$NON-NLS-1$
"Status checking") {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus runInUIThread(IProgressMonitor monitor) {
return op.computeExecutionStatus(monitor);
}
};
statusJob.setSystem(true);
statusJob.schedule();
try {
// block until the status is ready
statusJob.join();
} catch (InterruptedException e) {
// Do nothing as status will be a cancel
}
if (statusJob.getResult().isOK()) {
return op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
}
return statusJob.getResult();
}
return PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
} catch (ExecutionException e) {
if (e.getCause() instanceof CoreException) {
return ((CoreException) e.getCause()).getStatus();
}
return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
*/
public boolean belongsTo(Object family) {
if (IDEWorkbenchMessages.DeleteResourceAction_jobName.equals(family)) {
return true;
}
return super.belongsTo(family);
}
};
deleteJob.setUser(true);
deleteJob.schedule();
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method InsertGridTgtToEditor.
private void InsertGridTgtToEditor() {
GridItem[] selection = grid.getSelection();
if (null == selection || selection.length == 0) {
return;
}
IXliffEditor tempEditor = null;
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor instanceof IXliffEditor) {
IXliffEditor editor = (IXliffEditor) activeEditor;
tempEditor = editor;
}
if (tempEditor == null) {
return;
}
int[] selectedRows = tempEditor.getSelectedRows();
if (null == selectedRows || selectedRows.length == 0) {
return;
}
int rowIndex = selectedRows[0];
if (tempEditor == null || rowIndex < 0) {
return;
}
TransUnitBean transUnit = tempEditor.getRowTransUnitBean(rowIndex);
Hashtable<String, String> tuProp = transUnit.getTuProps();
if (tuProp != null) {
String translate = tuProp.get("translate");
if (translate != null && translate.equalsIgnoreCase("no")) {
MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg1"));
return;
}
}
String tarTerm = selection[0].getText(1);
if (null == tarTerm || tarTerm.isEmpty()) {
return;
}
try {
tempEditor.insertCell(rowIndex, tempEditor.getTgtColumnIndex(), tarTerm);
// tempEditor.setFocus(); // 焦点给回编辑器
} catch (ExecutionException e) {
if (Constant.RUNNING_MODE == Constant.MODE_DEBUG) {
e.printStackTrace();
}
MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg2") + e.getMessage());
}
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class CatalogManagerHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
root = ResourcesPlugin.getWorkspace().getRoot();
//先检查目录管理器配置所需要的文件是否都存在于工作空间
File catalogXmlFile = root.getLocation().append(ADConstants.catalogueXmlPath).toFile();
// 如果不存在,就将net.heartsome.cat.ts.configurationfile.feature插件的net.heartsome.cat.converter里的catalogue.xml拷到工作空间
if (!catalogXmlFile.exists() || new File(catalogXmlFile.getParent()).list().length <= 0) {
//这是产品打包后,catalogue.xml所在的路径
String srcLocation = Platform.getConfigurationLocation().getURL().getPath() + "net.heartsome.cat.converter" + System.getProperty("file.separator") + "catalogue" + System.getProperty("file.separator") + "catalogue.xml";
String tagLoaction = catalogXmlFile.getParent();
try {
ResourceUtils.copyDirectory(new File(srcLocation).getParentFile(), new File(tagLoaction));
} catch (Exception e) {
e.printStackTrace();
}
}
catalogXmlFile = root.getLocation().append(ADConstants.catalogueXmlPath).toFile();
if (!catalogXmlFile.exists()) {
MessageDialog.openInformation(HandlerUtil.getActiveSite(event).getShell(), Messages.getString("handlers.CatalogManagerHandler.msgTitle"), Messages.getString("handlers.CatalogManagerHandler.msg"));
return null;
}
CatalogManagerDialog dialog = new CatalogManagerDialog(HandlerUtil.getActiveSite(event).getShell(), root);
dialog.open();
return null;
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class XmlConverterConfigurationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
root = ResourcesPlugin.getWorkspace().getRoot();
String configFileLocation = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).toOSString();
Shell shell = HandlerUtil.getActiveShell(event);
// 首先验证安装文件中本次所需要的文件是否转存至工作工间,如果没有,就转过去。
File xmlConfigFolderFile = new File(configFileLocation);
String tgtLocation = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).toOSString();
// 如果不存在,则将安装文件中的相关配置文件复制到工作工间
if (!xmlConfigFolderFile.exists() || !xmlConfigFolderFile.isDirectory() || new File(tgtLocation).list().length <= 0) {
String srcLocation = Platform.getConfigurationLocation().getURL().getPath() + "net.heartsome.cat.converter" + System.getProperty("file.separator") + "ini";
try {
ResourceUtils.copyDirectory(new File(srcLocation), new File(tgtLocation));
} catch (Exception e) {
LOGGER.error("", e);
}
File _xmlConfigFolderFile = new File(configFileLocation);
if (!_xmlConfigFolderFile.exists() || !_xmlConfigFolderFile.isDirectory()) {
MessageDialog.openInformation(shell, Messages.getString("handlers.XmlConverterConfigurationHandler.msgTitle"), Messages.getString("handlers.XmlConverterConfigurationHandler.msg"));
return null;
}
}
XmlConverterConfigurationDialog dialog = new XmlConverterConfigurationDialog(shell, configFileLocation);
dialog.open();
return null;
}
Aggregations