use of org.eclipse.ui.IEditorInput in project tesb-studio-se by Talend.
the class OpenOnSelectionHelper method openEditor.
@Override
protected void openEditor(String resource, String spec) {
//$NON-NLS-1$
String pattern = "platform:/resource";
IWorkbenchPage workbenchPage = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = workbenchPage.getActiveEditor();
String currentEditorId = editorPart.getEditorSite().getId();
if (resource != null && resource.startsWith(pattern)) {
Path path = new Path(resource.substring(pattern.length()));
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (editorPart.getEditorInput() instanceof IFileEditorInput && ((IFileEditorInput) editorPart.getEditorInput()).getFile().equals(file)) {
workbenchPage.getNavigationHistory().markLocation(editorPart);
} else {
try {
Item item = ((ServiceEditorInput) editorPart.getEditorInput()).getItem();
// TODO: Use content type as below
if (resource.endsWith("xsd")) {
//$NON-NLS-1$
editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), WSDLEditorPlugin.XSD_EDITOR_ID);
} else {
// Since we are already in the wsdleditor
editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), editorPart.getEditorSite().getId());
}
} catch (PartInitException initEx) {
ExceptionHandler.process(initEx);
}
}
try {
Class<? extends IEditorPart> theClass = editorPart.getClass();
Class<?>[] methodArgs = { String.class };
//$NON-NLS-1$
Method method = theClass.getMethod("openOnSelection", methodArgs);
Object[] args = { spec };
method.invoke(editorPart, args);
workbenchPage.getNavigationHistory().markLocation(editorPart);
} catch (Exception e) {
ExceptionHandler.process(e);
}
} else if (resource != null && resource.startsWith("http")) {
IEditorPart newEditorPart = null;
boolean doOpenWsdlEditor = true;
if (//$NON-NLS-1$
resource.endsWith("xsd")) {
doOpenWsdlEditor = false;
}
try {
IEditorReference[] refs = workbenchPage.getEditorReferences();
int length = refs.length;
// Need to find if an editor on that schema has already been opened
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof ADTReadOnlyFileEditorInput) {
ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input;
if (readOnlyEditorInput.getUrlString().equals(resource) && (!doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.XSD_EDITOR_ID) || doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.WSDL_EDITOR_ID))) {
newEditorPart = refs[i].getEditor(true);
workbenchPage.activate(refs[i].getPart(true));
break;
}
}
}
if (newEditorPart == null) {
ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(resource);
IContentType contentType = null;
try (InputStream iStream = readOnlyStorageEditorInput.getStorage().getContents()) {
contentType = Platform.getContentTypeManager().findContentTypeFor(iStream, resource);
}
// content type more reliable check
if (//$NON-NLS-1$
contentType != null && contentType.equals(XSDEditorPlugin.XSD_CONTENT_TYPE_ID) || resource.endsWith("xsd")) {
readOnlyStorageEditorInput.setEditorID(WSDLEditorPlugin.XSD_EDITOR_ID);
//$NON-NLS-1$
workbenchPage.openEditor(readOnlyStorageEditorInput, WSDLEditorPlugin.XSD_EDITOR_ID, true, 0);
} else {
readOnlyStorageEditorInput.setEditorID(currentEditorId);
//$NON-NLS-1$
workbenchPage.openEditor(readOnlyStorageEditorInput, currentEditorId, true, 0);
}
}
} catch (IOException | CoreException e) {
ExceptionHandler.process(e);
}
}
}
use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.
the class PreviewTranslationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor == null) {
return false;
}
IEditorInput input = editor.getEditorInput();
IFile file = ResourceUtil.getFile(input);
shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
if (file == null) {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg1"));
} else {
String fileExtension = file.getFileExtension();
if (fileExtension != null && CommonFunction.validXlfExtension(fileExtension)) {
ConverterViewModel model = getConverterViewModel(file);
if (model != null) {
// model.convert();
try {
previewFiles(new ArrayList<IFile>(Arrays.asList(new IFile[] { file })));
} catch (Exception e) {
// 修改 当异常没有消息,提示信息为空
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg7"));
LOGGER.error("", e);
}
}
} else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) {
// UNDO 合并打开的预览翻译有问题,是针对合并打开的文件,而不是针对项目所有的文件 robert 2012-07-12
if (file.exists()) {
// IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF);
// Fixed Bug #2616 预览翻译--合并打开的文件不能进行预览翻译 by Jason
XLFHandler hander = new XLFHandler();
List<String> files = hander.getMultiFiles(file);
List<IFile> ifileList = new ArrayList<IFile>();
for (String tf : files) {
ifileList.add(ResourceUtils.fileToIFile(tf));
}
// if (xliffFolder.exists()) {
// ArrayList<IFile> files = new ArrayList<IFile>();
// try {
// ResourceUtils.getXliffs(xliffFolder, files);
// } catch (CoreException e) {
// throw new ExecutionException(e.getMessage(), e);
// }
previewFiles(ifileList);
// } else {
// MessageDialog
// .openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"),
// Messages.getString("handler.PreviewTranslationHandler.msg2"));
// }
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg3"));
}
}
return null;
}
use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.
the class BrokerConfOpenFileDialog method buttonPressed.
/**
* When press button,call it
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
if (!validate()) {
CommonUITool.openErrorBox(Messages.cubridBrokerConfOpenFileDialogErrMsg);
return;
}
}
try {
IEditorInput input = new BrokerConfigEditorInput(filePath.getText(), fileCharsetCombo.getText());
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, BrokerConfigEditorPart.ID);
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
setReturnCode(buttonId);
close();
}
use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.
the class QueryOpenAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor != null && editor.isDirty()) {
int confirm = CommonUITool.openMsgBox(editor.getSite().getShell(), MessageDialog.WARNING, Messages.saveResource, Messages.bind(Messages.saveConfirm, editor.getTitle()), new String[] { Messages.btnYes, Messages.btnNo, Messages.cancel });
switch(confirm) {
case 0:
editor.doSave(null);
break;
case 1:
break;
default:
return;
}
}
try {
if (editor == null) {
IEditorInput input = new QueryUnit();
editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
}
} catch (PartInitException e) {
CommonUITool.openErrorBox(e.getMessage());
}
if (editor == null) {
return;
}
try {
QueryEditorPart queryEditor = (QueryEditorPart) editor;
SQLEditorComposite editorComp = queryEditor.getCombinedQueryComposite().getSqlEditorComp();
String encoding = editorComp.getDocument().getEncoding();
SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), encoding, true);
if (IDialogConstants.OK_ID == dialog.open()) {
editorComp.open(dialog.getFilePath(), dialog.getEncoding());
}
} catch (IOException e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.
the class QueryNewCustomAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] selected = getSelectedObj();
LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
if (selected != null && selected.length == 1 && selected[0] instanceof ISchemaNode) {
dialog.setSelServerName(((ISchemaNode) selected[0]).getServer().getServerName());
dialog.setSelDatabaseName(((ISchemaNode) selected[0]).getDatabase().getName());
} else if (selected != null && selected.length == 1 && selected[0] instanceof CubridServer) {
dialog.setSelServerName(((CubridServer) selected[0]).getName());
} else {
dialog.setSelServerName(DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL);
}
if (dialog.open() == IDialogConstants.OK_ID) {
try {
IEditorInput input = new QueryUnit();
IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
((QueryEditorPart) editor).connect(DatabaseNavigatorMenu.SELF_DATABASE);
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
Aggregations