use of org.eclipse.ui.part.FileEditorInput in project dbeaver by serge-rider.
the class ScriptsHandlerImpl method openResource.
@Override
public void openResource(@NotNull IResource resource) throws CoreException, DBException {
if (resource instanceof IFile) {
FileEditorInput sqlInput = new FileEditorInput((IFile) resource);
DBeaverUI.getActiveWorkbenchWindow().getActivePage().openEditor(sqlInput, SQLEditor.class.getName());
} else {
super.openResource(resource);
}
}
use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method restorEditorHistory.
/**
* 重新恢复产品上次退时出所保存的编辑器,此修复针对 mac 下的 bug 2998 启动:某客户安装的软件只能使用一次. robert 2013-05-21
*/
private void restorEditorHistory() {
// 只针对 mac 下的用户
if (System.getProperty("os.name").indexOf("Mac") == -1) {
return;
}
final WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", 10);
String tempEditorHistoryLC = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(Constant.TEMP_EDITOR_HISTORY).toOSString();
File tempEditorHistoryFile = new File(tempEditorHistoryLC);
if (!tempEditorHistoryFile.exists()) {
return;
}
monitor.worked(1);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
VTDGen vg = new VTDGen();
try {
boolean parseResult = vg.parseFile(tempEditorHistoryLC, true);
if (!parseResult) {
return;
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
int storeFileSum = 0;
ap.selectXPath("count(/editors/editor)");
storeFileSum = (int) ap.evalXPathToNumber();
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", storeFileSum);
ap.selectXPath("/editors/editor");
String editorId = null;
String localFilePath = null;
boolean activate = false;
IEditorReference activateEditorRefe = null;
IEditorReference firstEditor = null;
IFile curIFile = null;
int index = -1;
while (ap.evalXPath() != -1) {
activate = false;
editorId = null;
localFilePath = null;
if ((index = vn.getAttrVal("id")) != -1) {
editorId = vn.toRawString(index);
}
if ((index = vn.getAttrVal("path")) != -1) {
localFilePath = vn.toRawString(index);
}
if (editorId == null || editorId.trim().length() <= 0 || localFilePath == null || localFilePath.trim().length() <= 0) {
continue;
}
if ((index = vn.getAttrVal("active")) != -1) {
if ("true".equals(vn.toRawString(index))) {
activate = true;
}
}
curIFile = root.getFileForLocation(new Path(localFilePath));
if (!curIFile.exists()) {
subMonitor.worked(1);
continue;
}
if (activate) {
activateEditorRefe = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
} else {
if (firstEditor == null) {
firstEditor = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
} else {
page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
}
subMonitor.worked(1);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
if (activateEditorRefe != null) {
if (firstEditor != null) {
page.activate(firstEditor.getEditor(true));
}
page.activate(activateEditorRefe.getEditor(true));
}
subMonitor.done();
monitor.done();
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.
the class ResourceLinkHelper method activateEditor.
/* (non-Javadoc)
* @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
*/
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
if (aSelection == null || aSelection.isEmpty())
return;
if (aSelection.getFirstElement() instanceof IFile) {
IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement());
IEditorPart editor = null;
if ((editor = aPage.findEditor(fileInput)) != null)
aPage.bringToTop(editor);
}
}
use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.
the class ConcordanceSearchHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
} else if (selectText == null) {
selectText = "";
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
dialog.open();
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
}
if (selectText != null && !selectText.trim().equals("")) {
dialog.initGroupIdAndSearch();
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (Exception e1) {
}
}
}
}
return null;
}
use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.
the class UpdateTMWizard method performFinish.
public boolean performFinish() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final boolean isDraft = page.isDraft();
final boolean isApproved = page.isApproved();
final boolean isSignedOff = page.isSignedOff();
final boolean isTranslated = page.isTranslated();
final boolean isLocked = page.isLocked();
if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
return false;
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
IRunnableWithProgress progress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
for (final IFile xliffFile : lstXLIFF) {
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
FileEditorInput editorInput = new FileEditorInput(xliffFile);
IEditorPart editorPart = activePage.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
} else {
// xliff 文件未打开
handler = new XLFHandler();
}
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
// 修改获取系统用户方式/*System.getProperty("user.name");*/
String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
monitor.worked(1);
if (arrTempTMX != null) {
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
// }
try {
DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
}
});
canFinish = false;
return;
}
}
}
monitor.done();
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
canFinish = true;
}
};
try {
getContainer().run(true, true, progress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return canFinish;
}
Aggregations