Revision 2392

tmp/org.txm.xmleditor.rcp/META-INF/MANIFEST.MF (revision 2392)
3 3
Bundle-SymbolicName: org.txm.xmleditor.rcp;singleton:=true
4 4
Bundle-Version: 1.0.0.qualifier
5 5
Bundle-Name: %Bundle-Name
6
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.12.0,4.0.0)",org
7
 .eclipse.ui.views;bundle-version="[3.8.0,4.0.0)",org.eclipse.jface.te
8
 xt;bundle-version="[3.10.0,4.0.0)",org.eclipse.ui.workbench.textedito
9
 r;bundle-version="[3.10.0,4.0.0)",org.eclipse.wst.sse.ui;bundle-versi
10
 on="1.3.500",org.eclipse.wst.sse.core;bundle-version="1.1.900",org.ec
11
 lipse.ui;bundle-version="[3.107.0,4.0.0)",org.eclipse.core.resources;
12
 bundle-version="[3.11.0,4.0.0)",org.eclipse.core.runtime;bundle-versi
13
 on="[3.12.0,4.0.0)",org.eclipse.wst.common.uriresolver;bundle-version
14
 ="[1.2.200,2.0.0)",org.eclipse.wst.xml.core;bundle-version="1.1.1100"
15
 ,org.eclipse.wst.common.ui;bundle-version="[1.1.500,1.2.0)",org.eclip
16
 se.wst.validation;bundle-version="[1.2.700,1.3.0)",org.eclipse.wst.va
17
 lidation.ui,org.eclipse.core.expressions;bundle-version="[3.5.0,4.0.0
18
 )",org.eclipse.core.filesystem;bundle-version="[1.6.0,2.0.0)",org.txm
19
 .core;bundle-version="0.7.0";visibility:=reexport,org.txm.rcp;bundle-
20
 version="0.7.8";visibility:=reexport,org.eclipse.wst.xml.ui;bundle-ve
21
 rsion="1.1.800"
6
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.12.0,4.0.0)",
7
 org.eclipse.ui.views;bundle-version="[3.8.0,4.0.0)",
8
 org.eclipse.jface.text;bundle-version="[3.10.0,4.0.0)",
9
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.10.0,4.0.0)",
10
 org.eclipse.wst.sse.ui;bundle-version="1.3.500",
11
 org.eclipse.wst.sse.core;bundle-version="1.1.900",
12
 org.eclipse.ui;bundle-version="[3.107.0,4.0.0)",
13
 org.eclipse.core.resources;bundle-version="[3.11.0,4.0.0)",
14
 org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)",
15
 org.eclipse.wst.common.uriresolver;bundle-version="[1.2.200,2.0.0)",
16
 org.eclipse.wst.xml.core;bundle-version="1.1.1100",
17
 org.eclipse.wst.common.ui;bundle-version="[1.1.500,1.2.0)",
18
 org.eclipse.wst.validation;bundle-version="[1.2.700,1.3.0)",
19
 org.eclipse.wst.validation.ui,
20
 org.eclipse.core.expressions;bundle-version="[3.5.0,4.0.0)",
21
 org.eclipse.core.filesystem;bundle-version="[1.6.0,2.0.0)",
22
 org.txm.core;bundle-version="0.7.0";visibility:=reexport,
23
 org.txm.rcp;bundle-version="0.7.8";visibility:=reexport,
24
 org.eclipse.wst.xml.ui;bundle-version="1.1.800",
25
 org.txm.concordance.rcp;bundle-version="1.0.0",
26
 org.txm.edition.rcp;bundle-version="1.0.0",
27
 org.eclipse.search
22 28
Bundle-ActivationPolicy: lazy
23 29
Bundle-ManifestVersion: 2
24 30
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
tmp/org.txm.xmleditor.rcp/src/org/txm/xmleditor/OpenXMLEditor.java (revision 2392)
8 8
import org.eclipse.core.commands.ExecutionException;
9 9
import org.eclipse.core.filesystem.EFS;
10 10
import org.eclipse.core.filesystem.IFileStore;
11
import org.eclipse.core.resources.IResource;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.FileLocator;
11 14
import org.eclipse.core.runtime.Path;
12 15
import org.eclipse.jface.viewers.ISelection;
13 16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.search.ui.ISearchQuery;
18
import org.eclipse.search.ui.NewSearchUI;
19
import org.eclipse.search.ui.text.TextSearchQueryProvider;
14 20
import org.eclipse.swt.SWT;
15 21
import org.eclipse.swt.widgets.FileDialog;
16 22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.ui.IEditorInput;
24
import org.eclipse.ui.IEditorPart;
17 25
import org.eclipse.ui.IWorkbenchPage;
18 26
import org.eclipse.ui.IWorkbenchWindow;
19 27
import org.eclipse.ui.PartInitException;
20 28
import org.eclipse.ui.PlatformUI;
21 29
import org.eclipse.ui.handlers.HandlerUtil;
22 30
import org.eclipse.ui.ide.FileStoreEditorInput;
31
import org.eclipse.wst.sse.ui.StructuredTextEditor;
32
import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
23 33
import org.txm.Toolbox;
34
import org.txm.concordance.core.functions.Concordance;
35
import org.txm.concordance.core.functions.Line;
36
import org.txm.concordance.rcp.editors.ConcordanceEditor;
37
import org.txm.edition.rcp.editors.SynopticEditionEditor;
38
import org.txm.objects.Text;
24 39
import org.txm.rcp.StatusLine;
25 40
import org.txm.rcp.swt.dialog.LastOpened;
26 41
import org.txm.utils.logger.Log;
......
31 46
	public static final String ID = "org.txm.xmleditor.OpenXMLEditor"; //$NON-NLS-1$
32 47
	public static String lastopenedfile;
33 48
	
49
	
34 50
	@Override
35 51
	public Object execute(ExecutionEvent event) throws ExecutionException {
36
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
37
				.getShell();
52
		
53
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
54
		IEditorPart editor = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage().getActiveEditor();
55
		ISelection iselection = HandlerUtil.getCurrentSelection(event);
56
		Object  selection = null;
57
		if (iselection instanceof IStructuredSelection) {
58
			selection = ((IStructuredSelection) iselection).getFirstElement();
59
		}
60
		
38 61
		String txmhome = Toolbox.getTxmHomePath();
39
		String filename = event
40
				.getParameter("org.txm.rcp.commands.commandParameter2"); //$NON-NLS-1$
41
		if (filename != null && !filename.matches("") && !filename.matches(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
62
		String filename = event.getParameter("org.txm.rcp.commands.commandParameter2"); //$NON-NLS-1$
63
		IEditorPart reditor = null;
64
		if (editor instanceof SynopticEditionEditor) {
65
			Text text = ((SynopticEditionEditor)editor).getEditionPanel(0).getEdition().getText();
66
			String[] wordSelection = ((SynopticEditionEditor)editor).getEditionPanel(0).getWordSelection();
67
			
68
			File txmFile = text.getXMLTXMFile();
69
			if (txmFile != null && txmFile.exists()) {
70
				reditor = openfile(txmFile);
71
			} else { // wrong link ?
72
				txmFile = new File(text.getProject().getProjectDirectory(), "txm/"+text.getProject().getName()+"/"+text.getName()+".xml");
73
				reditor = openfile(txmFile);
74
			}
75
			
76
			if (wordSelection[0] != null && reditor instanceof XMLMultiPageEditorPart) {
77
				XMLMultiPageEditorPart xmlEditor = (XMLMultiPageEditorPart)reditor;
78
				System.out.println("xmlEditor="+xmlEditor);
79
				System.out.println("word="+wordSelection[0]);
80
				Object selectedPage = xmlEditor.getSelectedPage();
81
				if (selectedPage != null && selectedPage instanceof StructuredTextEditor) {
82
//					StructuredTextEditor textEditor = (StructuredTextEditor) selectedPage;
83
//					
84
//					String search = "\""+wordSelection[0]+"\"";
85
					if (wordSelection[1] == null) {
86
						System.out.println("Selected word: "+wordSelection[0]);
87
					} else {
88
						System.out.println("Selected word: from "+wordSelection[0]+" to "+wordSelection[1]);
89
					}
90
				}
91
			}
92
		} else if (selection != null && selection instanceof Line) {
93
			Line line = (Line)selection;
94
			Concordance conc = line.getConcordance();
95
			String text = line.getTextId();
96
	
97
			File txmFile = new File(conc.getProject().getProjectDirectory(), "txm/"+conc.getCorpus().getID()+"/"+text+".xml");
98
			reditor = openfile(txmFile);
99
			if (reditor != null & reditor instanceof XMLMultiPageEditorPart) {
100
				XMLMultiPageEditorPart xmlEditor = (XMLMultiPageEditorPart)reditor;
101
				Object selectedPage = xmlEditor.getSelectedPage();
102
				if (selectedPage != null && selectedPage instanceof StructuredTextEditor) {
103
					System.out.println("Word selection: "+line.getKeywordIds());
104
				}
105
			}
106
		} else if (filename != null && !filename.matches("") && !filename.matches(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
42 107
			String filepath = txmhome + "/scripts/" + filename; //$NON-NLS-1$ 
43
			openfile(new File(filepath));
44
			return null;
108
			return openfile(new File(filepath));
45 109
		}
46 110

  
111
		if (reditor != null) return null;
112
		
113
		
47 114
		File file = null;
48
		ISelection selection = HandlerUtil.getCurrentSelection(event);
49
		if (selection != null & selection instanceof IStructuredSelection) {
50
			IStructuredSelection strucSelection = (IStructuredSelection) selection;
51
			for (Object o : strucSelection.toList()) {
115
		if (iselection != null & iselection instanceof IStructuredSelection) {
116
			for (Object o : ((IStructuredSelection)iselection).toList()) {
52 117
				if(o != null && o instanceof File) {
53 118
					file = (File)o;
54 119
					break;
......
87 152
		return null;
88 153
	}
89 154

  
90
	private boolean openfile(File file) {
155
	private IEditorPart openfile(File file) {
91 156
		//XMLMultiPageEditorPart editorInput = new ConcordancesEditorInput(corpus, null);
92 157
		Log.fine(XMLEditorMessages.OpenXMLEditor_1);
93 158
		IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(
......
100 165
		String ID = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$
101 166
		try {
102 167
			StatusLine.setMessage(XMLEditorMessages.OpenXMLEditor_3);
103
			page.openEditor(editorInput, ID); //$NON-NLS-1$
168
			IEditorPart editor = page.openEditor(editorInput, ID); //$NON-NLS-1$
169
			if (editor != null && editor instanceof XMLMultiPageEditorPart) {
170
				XMLMultiPageEditorPart xmlEditor = ((XMLMultiPageEditorPart)editor);
171
				xmlEditor.removePage(0);
172
				return xmlEditor;
173
			}
174
			
175
			return editor;
104 176
		} catch (PartInitException e) {
105 177
			System.out.println(XMLEditorMessages.OpenXMLEditor_4+e);
106 178
		}
107
		return true;
179
		return null;
108 180
	}
109 181
}
tmp/org.txm.xmleditor.rcp/plugin.xml (revision 2392)
21 21
      <menuContribution
22 22
            locationURI="popup:org.txm.rcp.views.fileexplorer.Explorer">
23 23
      </menuContribution>
24
      <menuContribution
25
            locationURI="popup:org.txm.edition.rcp.editors.SynopticEditionEditor">
26
         <command
27
               commandId="org.txm.xmleditor.OpenXMLEditor"
28
               style="push">
29
         </command>
30
      </menuContribution>
31
      <menuContribution
32
            locationURI="popup:org.txm.concordance.rcp.editors.ConcordanceEditor">
33
         <command
34
               commandId="org.txm.xmleditor.OpenXMLEditor"
35
               style="push">
36
         </command>
37
      </menuContribution>
24 38
   </extension>
25 39
   <extension
26 40
         point="org.eclipse.ui.activities">

Also available in: Unified diff