|
From: Matthias K <mat...@us...> - 2006-07-08 17:35:24
|
Update of /cvsroot/jcommander/plugins/org.jcommander.ui.filepanel/src/org/jcommander/ui/filepanel/actions In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3108/src/org/jcommander/ui/filepanel/actions Modified Files: ViewFileAction.java Log Message: - [Feature Requests-1105827]: First implementation of simple build in editor, currently capable of highlighting html and xml - removed compare perspective, now using edit instead - All Editors can be closed with Esc Index: ViewFileAction.java =================================================================== RCS file: /cvsroot/jcommander/plugins/org.jcommander.ui.filepanel/src/org/jcommander/ui/filepanel/actions/ViewFileAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ViewFileAction.java 20 Feb 2006 21:15:58 -0000 1.4 --- ViewFileAction.java 8 Jul 2006 17:35:20 -0000 1.5 *************** *** 4,18 **** package org.jcommander.ui.filepanel.actions; import org.apache.commons.vfs.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.ui.*; ! import org.jcommander.ui.externaltools.*; import org.jcommander.ui.filepanel.*; import org.jcommander.ui.logger.*; //import org.jcommander.ui.fileviewer.*; public class ViewFileAction implements IWorkbenchWindowActionDelegate { public void dispose() { // TODO Auto-generated method stub --- 4,30 ---- package org.jcommander.ui.filepanel.actions; + import java.text.MessageFormat; + import org.apache.commons.vfs.*; import org.eclipse.jface.action.*; + import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.*; import org.eclipse.ui.*; ! import org.jcommander.ui.editor.EditorPlugin; ! import org.jcommander.ui.editor.JCmdEditorInput; import org.jcommander.ui.filepanel.*; import org.jcommander.ui.logger.*; //import org.jcommander.ui.fileviewer.*; + import org.jcommander.ui.utils.EclipseBroker; public class ViewFileAction implements IWorkbenchWindowActionDelegate { + + private IWorkbenchPage workbenchPage; + + private IWorkbenchWindow fWindow; + public static final String COMPARE_PERSPECTIVE_ID = "org.jcommander.compare.Compare"; + + public void dispose() { // TODO Auto-generated method stub *************** *** 21,25 **** public void init(IWorkbenchWindow window) { ! // TODO Auto-generated method stub } --- 33,37 ---- public void init(IWorkbenchWindow window) { ! fWindow= window; } *************** *** 41,45 **** // For now we use an external viewer ! ExternaltoolsPlugin.getDefault().viewFile(currentFile); //FileViewerPlugin.getDefault().test(); --- 53,114 ---- // For now we use an external viewer ! //ExternaltoolsPlugin.getDefault().viewFile(currentFile); ! ! if (currentFile != null) { ! try{ ! workbenchPage = PlatformUI.getWorkbench().showPerspective(EditorPlugin.EDIT_PERSPECTIVE_ID, EclipseBroker.getWorkbenchWindow()); ! } catch (WorkbenchException e) { ! LoggerPlugin.rootLogger.error(e,e); ! } ! ! IEditorInput input= new JCmdEditorInput(currentFile); ! String editorId= getEditorId(currentFile); ! IWorkbenchPage page= fWindow.getActivePage(); ! workbenchPage.addPartListener(new IPartListener() { ! ! public void partOpened(IWorkbenchPart part) { ! // TODO Auto-generated method stub ! ! } ! ! public void partDeactivated(IWorkbenchPart part) { ! // TODO Auto-generated method stub ! ! } ! ! public void partClosed(IWorkbenchPart part) { ! if (workbenchPage.getEditorReferences().length==0) { ! try { ! workbenchPage.removePartListener(this); ! PlatformUI.getWorkbench().showPerspective("org.jcommander.ui.app.JCmdPerspective", EclipseBroker.getWorkbenchWindow()); ! } catch (WorkbenchException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } ! } ! ! } ! ! public void partBroughtToTop(IWorkbenchPart part) { ! // TODO Auto-generated method stub ! ! } ! ! public void partActivated(IWorkbenchPart part) { ! // TODO Auto-generated method stub ! ! } ! ! }); ! ! try { ! page.openEditor(input, editorId); ! } catch (PartInitException e) { ! e.printStackTrace(); ! } ! } else if (currentFile != null) { ! String msg = MessageFormat.format("File is null: {0}", new String[] {currentFile.getName().getBaseName()}); //$NON-NLS-1$ ! MessageDialog.openWarning(fWindow.getShell(), "Problem", msg); //$NON-NLS-1$ ! } //FileViewerPlugin.getDefault().test(); *************** *** 48,51 **** --- 117,129 ---- } } + + private String getEditorId(FileObject file) { + IWorkbench workbench= fWindow.getWorkbench(); + IEditorRegistry editorRegistry= workbench.getEditorRegistry(); + IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName().getBaseName()); + if (descriptor != null) + return descriptor.getId(); + return "org.jcommander.ui.editor.JCmdEditor"; //$NON-NLS-1$ + } public void selectionChanged(IAction action, ISelection selection) { |