Révision 936

tmp/org.txm.edition.rcp/OSGI-INF/l10n/bundle.properties (revision 936)
1
command.label = Edition
2
command.tooltip = Read corpus texts
3
command.tooltip.0 = Read corpus texts
4
command.name = Edition
5
command.name.0 = Display in full text
6
editor.name = Edition
7
Bundle-Name = SynopticEditor
8
menu.label.1 = Corpus
0 9

  
tmp/org.txm.edition.rcp/OSGI-INF/l10n/bundle_fr.properties (revision 936)
1

  
2
Bundle-Name = SynopticEditor
3

  
4
command.label = \u00C9dition
5

  
6
command.name = \u00C9dition
7

  
8
command.name.0 = Lire en plein texte
9

  
10
command.tooltip = Lire l'\u00E9dition
11

  
12
command.tooltip.0 = Lire l'\u00E9dition
13

  
14
editor.name = \u00C9dition
15

  
16
menu.label.1 = Corpus
0 17

  
tmp/org.txm.edition.rcp/plugin.xml (revision 936)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.ui.menus">
6
      <menuContribution
7
            locationURI="menu:menu.help.plugins">
8
         <command
9
               commandId="org.txm.rcp.commands.OpenBrowser"
10
               icon="icons/objects/edition.png"
11
               label="%command.label"
12
               style="push">
13
            <parameter
14
                  name="org.txm.rcp.commands.commandParameter2"
15
                  value="https://groupes.renater.fr/wiki/txm-users/public/extensions#synoptic_editor">
16
            </parameter>
17
         </command>
18
      </menuContribution>
19
      <menuContribution
20
            allPopups="true"
21
            locationURI="toolbar:org.txm.rcp.toolbarcorpus?after=org.txm.rcp.toolbarcorpus.read">
22
         <command
23
               commandId="org.txm.edition.rcp.handlers.OpenEdition"
24
               icon="icons/objects/edition.png"
25
               style="push"
26
               tooltip="%command.tooltip.0">
27
            <visibleWhen
28
                  checkEnabled="false">
29
               <or>
30
                  <reference
31
                        definitionId="OneCorpusSelected">
32
                  </reference>
33
               </or>
34
            </visibleWhen>
35
         </command>
36
      </menuContribution>
37
      <menuContribution
38
            locationURI="popup:org.txm.rcp.views.corpora.CorporaView?after=org.txm.rcp.corporaview.corpus.read">
39
         <command
40
               commandId="org.txm.edition.rcp.handlers.OpenEdition"
41
               icon="icons/objects/edition.png"
42
               style="push"
43
               tooltip="%command.tooltip.0">
44
            <visibleWhen
45
                  checkEnabled="false">
46
               <or>
47
                  <reference
48
                        definitionId="OneCorpusSelected">
49
                  </reference>
50
               </or>
51
            </visibleWhen>
52
         </command>
53
      </menuContribution>
54
      <menuContribution
55
            locationURI="menu:menu.corpus?after=menu.corpus.read">
56
         <command
57
               commandId="org.txm.edition.rcp.handlers.OpenEdition"
58
               icon="icons/objects/edition.png"
59
               style="push"
60
               tooltip="%command.tooltip.0">
61
            <visibleWhen
62
                  checkEnabled="false">
63
               <or>
64
                  <reference
65
                        definitionId="OneCorpusSelected">
66
                  </reference>
67
               </or>
68
            </visibleWhen>
69
         </command>
70
      </menuContribution>
71
      <menuContribution
72
            locationURI="popup:org.txm.concordance.rcp.editors.ConcordanceEditor">
73
         <command
74
               commandId="org.txm.edition.rcp.handlers.BackToText"
75
               icon="icons/objects/edition.png"
76
               style="push">
77
         </command>
78
      </menuContribution>
79
   </extension>
80
   <extension
81
         point="org.eclipse.ui.commands">
82
      <command
83
            defaultHandler="org.txm.edition.rcp.handlers.OpenEdition"
84
            id="org.txm.edition.rcp.handlers.OpenEdition"
85
            name="%command.name">
86
      </command>
87
      <command
88
            defaultHandler="org.txm.edition.rcp.handlers.BackToText"
89
            id="org.txm.edition.rcp.handlers.BackToText"
90
            name="%command.name.0">
91
         <commandParameter
92
               id="org.txm.edition.rcp.handlers.BackToText.wordid"
93
               name="wordid"
94
               optional="true">
95
         </commandParameter>
96
         <commandParameter
97
               id="org.txm.edition.rcp.handlers.BackToText.textid"
98
               name="textid"
99
               optional="true">
100
         </commandParameter>
101
         <commandParameter
102
               id="org.txm.edition.rcp.handlers.BackToText.corpusid"
103
               name="corpusid"
104
               optional="true">
105
         </commandParameter>
106
         <commandParameter
107
               id="org.txm.edition.rcp.handlers.BackToText.editionid"
108
               name="editionid"
109
               optional="true">
110
         </commandParameter>
111
      </command>
112
   </extension>
113
   <extension
114
         point="org.eclipse.ui.editors">
115
      <editor
116
            class="org.txm.edition.rcp.editors.SynopticEditionEditor"
117
            default="false"
118
            icon="icons/objects/edition.png"
119
            id="org.txm.edition.rcp.editors.SynopticEditionEditor"
120
            name="%editor.name">
121
      </editor>
122
   </extension>
123
   <extension
124
         point="org.eclipse.ui.bindings">
125
      <key
126
            commandId="org.txm.edition.rcp.handlers.BackToText"
127
            contextId="org.eclipse.ui.contexts.window"
128
            schemeId="org.txm.rcp.scheme"
129
            sequence="M1+E">
130
      </key>
131
   </extension>
132
   <extension
133
         point="org.txm.rcp.extensionpoint.backtotext">
134
      <command
135
            class="org.txm.edition.rcp.handlers.BackToText"
136
            name="Synoptic">
137
      </command>
138
   </extension>
139
   <extension
140
         point="org.eclipse.ui.preferencePages">
141
      <page
142
            category="org.txm.rcp.preferences.UserPreferencePage"
143
            class="org.txm.edition.rcp.preferences.SynopticEditionPreferencePage"
144
            id="org.txm.edition.rcp.preferences.SynopticEditionPreferencePage"
145
            name="Edition">
146
      </page>
147
   </extension>
148
   <extension
149
         point="org.eclipse.ui.handlers">
150
      <handler
151
            class="org.txm.edition.rcp.handlers.SendEditionTo"
152
            commandId="org.txm.concordance.rcp.commands.SendToConcordance">
153
         <activeWhen>
154
            <reference
155
                  definitionId="EditionEditorActive">
156
            </reference>
157
         </activeWhen>
158
      </handler>
159
   </extension>
160
   <extension
161
         point="org.eclipse.core.expressions.definitions">
162
      <definition
163
            id="EditionEditorActive">
164
         <with
165
               variable="activePart">
166
            <instanceof
167
                  value="org.txm.edition.rcp.editors.SynopticEditionEditor">
168
            </instanceof>
169
         </with>
170
      </definition>
171
   </extension>
172

  
173
</plugin>
0 174

  
tmp/org.txm.edition.rcp/.settings/org.eclipse.jdt.core.prefs (revision 936)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.edition.rcp/.classpath (revision 936)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
9
	<classpathentry kind="src" path="src"/>
10
	<classpathentry kind="src" path="res"/>
11
	<classpathentry kind="output" path="bin"/>
12
</classpath>
0 13

  
tmp/org.txm.edition.rcp/META-INF/MANIFEST.MF (revision 936)
1
Manifest-Version: 1.0
2
Require-Bundle: org.txm.concordance.rcp;bundle-version="1.0.0";visibility:=reexport,
3
 org.txm.links.rcp;bundle-version="1.0.0";visibility:=reexport
4
Export-Package: org.txm.edition.rcp.editors,
5
 org.txm.edition.rcp.handlers,
6
 org.txm.edition.rcp.messages,
7
 org.txm.edition.rcp.preferences
8
Bundle-Vendor: Textometrie.org
9
Bundle-ActivationPolicy: lazy
10
Bundle-Version: 1.0.0.qualifier
11
Bundle-Name: org.txm.edition.rcp
12
Bundle-ManifestVersion: 2
13
Bundle-SymbolicName: org.txm.edition.rcp;singleton:=true
14
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
15

  
0 16

  
tmp/org.txm.edition.rcp/.project (revision 936)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.edition.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/handlers/OpenEdition.java (revision 936)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.edition.rcp.handlers;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32

  
33
import org.apache.commons.lang.StringUtils;
34
import org.eclipse.core.commands.AbstractHandler;
35
import org.eclipse.core.commands.ExecutionEvent;
36
import org.eclipse.core.commands.ExecutionException;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.ui.IWorkbenchPage;
39
import org.eclipse.ui.IWorkbenchWindow;
40
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.handlers.HandlerUtil;
42
import org.txm.edition.rcp.editors.SynopticEditionEditor;
43
import org.txm.edition.rcp.editors.SynopticEditorInput;
44
import org.txm.edition.rcp.messages.SynopticEditionUIMessages;
45
import org.txm.objects.BaseParameters;
46
import org.txm.objects.Text;
47
import org.txm.searchengine.cqp.corpus.Corpus;
48
import org.txm.searchengine.cqp.corpus.MainCorpus;
49
import org.txm.searchengine.cqp.corpus.Property;
50
import org.txm.searchengine.cqp.corpus.StructuralUnit;
51
import org.txm.searchengine.cqp.corpus.Subcorpus;
52
import org.txm.searchengine.cqp.corpus.query.Match;
53
import org.txm.utils.logger.Log;
54
import org.w3c.dom.Element;
55

  
56
// TODO: Auto-generated Javadoc
57
/**
58
 * Open a text edition from: a main corpus : the first text of the maincorpus a
59
 * sub-corpus : the first text of the subcorpus a partition : the user must
60
 * choose one of the text used in the partition @ author mdecorde.
61
 */
62
public class OpenEdition extends AbstractHandler {
63

  
64
	/** The Constant ID. */
65
	public final static String ID = "org.txm.synopticedition.rcp.handlers.OpenEdition"; //$NON-NLS-1$
66

  
67
	/** The lastopenedfile. */
68
	public static String lastopenedfile;
69

  
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
72
	 */
73
	@Override
74
	public Object execute(ExecutionEvent event) throws ExecutionException {
75

  
76
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
77
		if (selection.getFirstElement() instanceof Corpus) {
78
			try {
79
				Corpus c = (Corpus) selection.getFirstElement();
80
//				Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
81

  
82
				//EditionSelectorDialog d = new EditionSelectorDialog(shell, c, null);
83
				SynopticEditionEditor editor = null;
84
				//				if (c.getEditionNames().size() > 1 && d.open() == Window.OK) {
85
				//					Object[] rez = d.getResult();
86
				//					String[] rezS = new String[rez.length];
87
				//					for (int i =0 ; i < rez.length ; i++) rezS[i] = rez[i].toString();
88
				//					editor = openEdition(c, rezS);
89
				//				} else 
90
				String[] editionsToOpen = getDefaultEditions(c);
91

  
92
				if (editionsToOpen.length == 0) { // the defaultEdition parameter is not set
93
					ArrayList<String> editionNames = c.getEditionNames();
94
					if (editionNames.size() > 0) { // use the first edition declared
95
						editionsToOpen = new String[1];
96
						editionsToOpen[0] = editionNames.get(0);
97
						Log.info(SynopticEditionUIMessages.OpenEdition_0+editionNames.get(0));
98
					} else { // no edition in the corpus
99
						Log.info(SynopticEditionUIMessages.OpenEdition_1);
100
						editionsToOpen = new String[0];
101
						return false;
102
					}
103
				} else {
104
					Log.info(SynopticEditionUIMessages.OpenEdition_3+StringUtils.join(editionsToOpen));
105
				}
106

  
107
				editor = openEdition(c, editionsToOpen);
108

  
109
				if (editor != null)
110
					editor.firstPage();
111

  
112
			} catch (Exception e) {
113
				System.out.println(SynopticEditionUIMessages.OpenEdition_4+e);
114
				org.txm.rcp.utils.Logger.printStackTrace(e);
115
			}
116
		} else {
117
			System.out.println(SynopticEditionUIMessages.OpenEdition_9);
118
		}
119
		return null;
120
	}
121
	public static String[] getDefaultEditions(Corpus c) {
122
		BaseParameters params = c.getBase().getBaseParameters();
123
		Element editionsElement = params.getEditionsElement(params.getCorpusElement());
124
		return editionsElement.getAttribute("default").split(","); //$NON-NLS-1$ //$NON-NLS-2$
125
	}
126

  
127
	/**
128
	 * Open edition, but don't show a page 
129
	 *
130
	 * @param corpus the corpus
131
	 * @return the object
132
	 */
133
	public static SynopticEditionEditor openEdition(Corpus corpus, String[] editions) {
134
		String textid = null;
135

  
136
		System.out.println("Opening edition of "+corpus); //$NON-NLS-1$
137
		try {
138
			Text text = null;
139
			if (corpus instanceof Subcorpus) {
140
				Subcorpus sub = (Subcorpus)corpus;
141
				List<Match> matches = sub.getMatches();
142
				if (matches.size() > 0) {
143
					StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$
144
					Property text_id = text_su.getProperty("id"); //$NON-NLS-1$
145

  
146
					textid = matches.get(0).getValueForProperty(text_id);
147
					if (textid != null) text = corpus.getMainCorpus().getText(textid);
148
				}
149
			}
150
			//			QueryResult result = corpus.query(new Query("<text> []"), "get_edition", false); //$NON-NLS-1$ //$NON-NLS-2$ 
151
			//			StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$
152
			//			Property text_id = text_su.getProperty("id"); //$NON-NLS-1$
153

  
154
			// 			if (result.getNMatch() > 0) textid = result.getMatches(0, 1).get(0).getValueForProperty(text_id);
155
			MainCorpus maincorpus = corpus.getMainCorpus();
156

  
157
			//			if (textid != null) text = maincorpus.getText(textid);
158

  
159
			if (text == null) {
160
				text = maincorpus.getFirstText();
161

  
162
				if (text == null) {
163
					System.out.println("** Could not find first text of ID "+textid+SynopticEditionUIMessages.OpenEdition_7); //$NON-NLS-1$ //$NON-NLS-1$
164
					return null;
165
				}
166

  
167
				textid = text.getName();
168
			}
169

  
170
			//String[] editions = {maincorpus.getDefaultEdition()};
171
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
172
			IWorkbenchPage page = window.getActivePage();
173

  
174
			SynopticEditorInput editorInput = new SynopticEditorInput(corpus, text.getName(), editions);
175
			SynopticEditionEditor editor = (SynopticEditionEditor) page.openEditor(editorInput,
176
					SynopticEditionEditor.ID, true);
177

  
178
			return editor;
179

  
180
		} catch (Exception e) {
181
			Log.printStackTrace(e);
182
			System.out.println(SynopticEditionUIMessages.OpenEdition_10+e);
183
			return null;
184
		}
185
	}
186
}
0 187

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/handlers/___TextToConcordance.java (revision 936)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.edition.rcp.handlers;
29

  
30
import org.eclipse.core.commands.AbstractHandler;
31
import org.eclipse.core.commands.ExecutionEvent;
32
import org.eclipse.core.commands.ExecutionException;
33
import org.eclipse.osgi.util.NLS;
34
import org.eclipse.ui.IEditorPart;
35
import org.eclipse.ui.IWorkbenchPage;
36
import org.eclipse.ui.IWorkbenchWindow;
37
import org.eclipse.ui.PartInitException;
38
import org.eclipse.ui.handlers.HandlerUtil;
39
import org.txm.concordance.core.functions.Concordance;
40
import org.txm.concordance.rcp.editors.ConcordanceEditor;
41
import org.txm.rcp.editors.IEditionEditor;
42
import org.txm.rcp.editors.TXMResultEditorInput;
43
import org.txm.rcp.messages.TXMUIMessages;
44
import org.txm.searchengine.cqp.corpus.Corpus;
45
import org.txm.searchengine.cqp.corpus.query.Query;
46

  
47
// TODO: Auto-generated Javadoc
48
/**
49
 * use the ITextSelection to compute a concordance
50
 * 
51
 * @author mdecorde.
52
 */
53
@Deprecated
54
public class ___TextToConcordance extends AbstractHandler {
55

  
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
58
	 */
59
	@Override
60
	public Object execute(ExecutionEvent event) throws ExecutionException {
61
		//System.out.println("Call TextToConcordance");
62
		IWorkbenchWindow window;
63
		TXMResultEditorInput editorInput;
64
		window = HandlerUtil.getActiveWorkbenchWindow(event);
65
		//selection = HandlerUtil.getCurrentSelection(event);
66
		
67
		IEditorPart editor = window.getActivePage().getActiveEditor();
68

  
69
		if (editor instanceof IEditionEditor) {
70
			
71
			//System.out.println(((TXMBrowser)editor).getWordIDsSelection());
72
			String query = ((IEditionEditor)editor).getTextSelection();
73
			if (query.length() == 0) {
74
				System.out.println("No text selection. Aborting.");
75
				return null;
76
			}
77
			query = fixQuery(query);
78
			
79
			Corpus corpus = ((IEditionEditor)editor).getCorpus();
80
			Concordance concordance = new Concordance(corpus);
81
			concordance.setParameters(new Query(query), null, null, null, null, null, null, null, null, null, null);
82
			editorInput = new TXMResultEditorInput(concordance);
83

  
84
			IWorkbenchPage page = window.getActivePage();
85
			try {
86
				ConcordanceEditor conceditor = (ConcordanceEditor) page
87
						.openEditor(editorInput, "ConcordanceEditor"); //$NON-NLS-1$
88
			} catch (PartInitException e) {
89
				System.err.println("Error: "+e.getLocalizedMessage());
90
			}
91
		}
92
		return null;
93
	}
94
	
95
	public static String fixQuery(String query) {
96
		query = "\""+query.replaceAll("\"", "\\\"");//.replaceAll("("+TokenizerClasses.regPunct+")", " $1 ");
97
		query = query.replaceAll(" +", "\" \"")+"\"";
98
		return query;
99
	}
100
}
0 101

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/handlers/BackToText.java (revision 936)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.edition.rcp.handlers;
29

  
30

  
31
import java.util.ArrayList;
32
import java.util.HashMap;
33
import java.util.HashSet;
34
import java.util.List;
35

  
36
import org.apache.commons.lang.StringUtils;
37
import org.eclipse.core.commands.ExecutionEvent;
38
import org.eclipse.core.commands.ExecutionException;
39
import org.eclipse.e4.ui.workbench.modeling.EModelService;
40
import org.eclipse.jface.viewers.ISelection;
41
import org.eclipse.jface.viewers.IStructuredSelection;
42
import org.eclipse.osgi.util.NLS;
43
import org.eclipse.ui.IEditorPart;
44
import org.eclipse.ui.IWorkbenchPage;
45
import org.eclipse.ui.IWorkbenchWindow;
46
import org.eclipse.ui.handlers.HandlerUtil;
47
import org.txm.concordance.core.functions.Concordance;
48
import org.txm.concordance.rcp.editors.ConcordanceEditor;
49
import org.txm.concordance.rcp.handlers.BackToTextCommand;
50
import org.txm.edition.rcp.editors.RGBA;
51
import org.txm.edition.rcp.editors.SynopticEditionEditor;
52
import org.txm.edition.rcp.messages.SynopticEditionUIMessages;
53
import org.txm.objects.Text;
54
import org.txm.rcp.StatusLine;
55
import org.txm.rcp.utils.SWTEditorsUtils;
56
import org.txm.searchengine.cqp.AbstractCqiClient;
57
import org.txm.searchengine.cqp.CQPSearchEngine;
58
import org.txm.searchengine.cqp.corpus.Corpus;
59
import org.txm.searchengine.cqp.corpus.CorpusManager;
60
import org.txm.searchengine.cqp.corpus.MainCorpus;
61
import org.txm.searchengine.cqp.corpus.Property;
62
import org.txm.searchengine.cqp.corpus.StructuralUnit;
63
import org.txm.searchengine.cqp.corpus.query.Match;
64
import org.txm.utils.logger.Log;
65

  
66
/**
67
 * Open a text edition from: a concordance Line 
68
 * 
69
 * Or Open a text edition from command parameters see plugin.xml
70
 * 
71
 * @author mdecorde.
72
 */
73
public class BackToText extends BackToTextCommand {
74

  
75
	/** The Constant ID. */
76
	public final static String ID = "org.txm.synopticedition.rcp.handlers.BackToText"; //$NON-NLS-1$
77
	public final static RGBA lightred = new RGBA(249,208,208);
78
	public final static RGBA red = new RGBA(249, 160, 160);
79
	//TODO: this kind of link associations must be transfered to a TXMEditor class
80
	private static HashMap<ConcordanceEditor, SynopticEditionEditor> associatedEditors = new HashMap<ConcordanceEditor, SynopticEditionEditor>();
81
	private static HashMap<ConcordanceEditor, List<String>> associatedEditorsPreviousOtherWordIDs = new HashMap<ConcordanceEditor, List<String>>();
82
	private static HashMap<ConcordanceEditor, List<String>> associatedEditorsPreviousLineids = new HashMap<ConcordanceEditor, List<String>>();
83

  
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
86
	 */
87
	@Override
88
	public Object execute(ExecutionEvent event) throws ExecutionException {
89

  
90
		String wordid = event
91
				.getParameter("org.txm.edition.rcp.handlers.BackToText.wordid");
92
		String textid = event
93
				.getParameter("org.txm.edition.rcp.handlers.BackToText.textid");
94
		String editionid = event
95
				.getParameter("org.txm.edition.rcp.handlers.BackToText.editionid");
96
		String corpusid = event
97
				.getParameter("org.txm.edition.rcp.handlers.BackToText.corpusid");
98
		if (corpusid != null) { // minimal parameter is the corpus id
99
			try {
100
				IWorkbenchWindow wb = HandlerUtil.getActiveWorkbenchWindow(event);
101
				IEditorPart ieditor = wb.getActivePage().getActiveEditor();
102

  
103
				if (!backToText(ieditor, corpusid, editionid, textid, wordid)) {
104
					System.out.println("Could not open edition for wordid="+wordid+" textid="+textid+" edition="+editionid);
105
				}
106
			} catch (Exception e) {
107
				// TODO Auto-generated catch block
108
				e.printStackTrace();
109
			}
110
			return null;
111
		}
112

  
113
		IWorkbenchWindow wb = HandlerUtil.getActiveWorkbenchWindow(event);
114
		IEditorPart ieditor = wb.getActivePage().getActiveEditor();
115
		if (!(ieditor instanceof ConcordanceEditor)) {
116
			return null;
117
		}
118
		ConcordanceEditor concordanceEditor = (ConcordanceEditor)ieditor;
119
		// FIXME: SJ: new version
120
		concordanceEditor.backToText();
121
		// FIXME: SJ: old version
122
//		ISelection sel = wb.getSelectionService().getSelection();
123
//		if (sel instanceof IStructuredSelection) {
124
//			IStructuredSelection selection = (IStructuredSelection) sel;
125
//			if (selection.getFirstElement() instanceof Match) {
126
//				backToText(concordanceEditor, (Match)(selection.getFirstElement()));
127
//			} else {
128
//				System.out.println(SynopticEditionUIMessages.BackToText_1+selection);
129
//			}
130
//		} else {
131
//			System.out.println(SynopticEditionUIMessages.BackToText_2);
132
//		}
133
		return null;
134
	}
135

  
136
	private boolean backToText(IEditorPart ieditor, String corpusid, String editionid, String textid, String wordid) throws Exception {
137
		MainCorpus corpus = CorpusManager.getCorpusManager().getCorpus(corpusid);
138

  
139
		if (corpus == null) {
140
			System.out.println("Error: no corpus with ID="+corpusid);
141
		}
142

  
143
		if (editionid != null && !corpus.getEditionNames().contains(editionid)) {
144
			System.out.println("Warning: corpus has no edition with id="+editionid);
145
			editionid = "default";
146
		}
147

  
148
		if (!corpus.getEditionNames().contains(editionid)) {
149
			System.out.println("Error: corpus has no default edition.");
150
			System.out.println("Availables: "+corpus.getEditionNames());
151
			return false;
152
		}
153

  
154
		if (editionid == null) editionid = "default";
155

  
156
		String[] editions = {editionid};
157
		SynopticEditionEditor editor = null;
158
		if (ieditor != null && ieditor instanceof SynopticEditionEditor) {
159
			editor = (SynopticEditionEditor)ieditor;
160
		} else {
161
			editor = OpenEdition.openEdition(corpus, editions);
162
		}
163

  
164
		Text text = null;
165
		if (textid != null) {
166
			text = corpus.getText(textid);
167
			if (text == null) {
168
				System.out.println("Error: corpus has no text with id="+textid);
169
				return false;
170
			}
171
		} else {
172
			text = corpus.getFirstText();
173
			if (text == null) {
174
				System.out.println("Error: corpus has no text.");
175
				return false;
176
			}
177
		}
178

  
179
		editor.backToText(text, wordid);
180
		if (wordid != null) {
181
			editor.addHighlightWordsById(red, wordid);
182
		}
183
		return false;
184
	}
185

  
186
	/**
187
	 * Open edition.
188
	 *
189
	 * @param corpus the corpus
190
	 * @return the object
191
	 */
192
	@Override
193
	public boolean backToText(ConcordanceEditor editor, Match match) {
194
		Concordance conc = editor.getConcordance();
195
		Corpus corpus = editor.getCorpus();
196

  
197
		try {
198
			if (match == null) return false;
199

  
200
			StructuralUnit textS = null;
201
			String textid = ""; //$NON-NLS-1$
202
			String baseid = ""; //$NON-NLS-1$
203

  
204
			Property xProperty = corpus.getProperty("x"), yProperty, wProperty, hProperty;
205
			String x="0",y="0",w="0",h="0";
206
			int[] pos = null;
207
			if (xProperty != null) {
208
				yProperty = corpus.getProperty("y");
209
				if (yProperty != null) {
210
					wProperty = corpus.getProperty("w");
211
					if (wProperty != null) {
212
						AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
213
						int[] cpos = {match.getStart()};
214
						hProperty = corpus.getProperty("h");
215
						if (hProperty != null) {
216
							x = CQI.cpos2Str(xProperty.getQualifiedName(), cpos)[0];
217
							y = CQI.cpos2Str(yProperty.getQualifiedName(), cpos)[0];
218
							w = CQI.cpos2Str(wProperty.getQualifiedName(), cpos)[0];
219
							h = CQI.cpos2Str(hProperty.getQualifiedName(), cpos)[0];
220

  
221
							pos = new int[4];
222
							pos[0] = Integer.parseInt(x);
223
							pos[1] = Integer.parseInt(y);
224
							pos[2] = Integer.parseInt(w);
225
							pos[3] = Integer.parseInt(h);
226
						}
227
					}
228
				}
229
			}
230

  
231

  
232
			String projectid = ""; //$NON-NLS-1$
233
			try {
234
				textS = corpus.getStructuralUnit("text"); //$NON-NLS-1$
235
				Property textP = textS.getProperty("id"); //$NON-NLS-1$
236
				textid = match.getValueForProperty(textP);// get text via text struct property id
237
			} catch (Exception e2) {
238
				System.out.println("The corpus has no text_id property" + e2); //$NON-NLS-1$
239
				org.txm.rcp.utils.Logger.printStackTrace(e2);
240
				return false;
241
			}
242

  
243
			Log.info("Loading line informations..."); //$NON-NLS-1$
244

  
245
			SynopticEditionEditor attachedBrowserEditor = associatedEditors.get(editor);
246
			if (attachedBrowserEditor!= null && attachedBrowserEditor.isDisposed()) {
247
				associatedEditorsPreviousOtherWordIDs.put(editor, new ArrayList<String>());
248
				associatedEditorsPreviousLineids.put(editor, new ArrayList<String>());
249
			}
250
			List<String> previousOtherWordIDs = associatedEditorsPreviousOtherWordIDs.get(editor);
251
			List<String> previousLineids = associatedEditorsPreviousLineids.get(editor);
252

  
253
			if (attachedBrowserEditor == null || attachedBrowserEditor.isDisposed()) {
254
				String[] editionsToOpen = OpenEdition.getDefaultEditions(corpus);
255

  
256
				if (editionsToOpen.length == 0) { // the defaultEdition parameter is not set
257
					ArrayList<String> editionNames = corpus.getEditionNames();
258
					if (editionNames.size() > 0) { // use the first edition declared
259
						editionsToOpen = new String[1];
260
						editionsToOpen[0] = editionNames.get(0);
261
						Log.info(SynopticEditionUIMessages.BackToText_0+editionNames.get(0));
262
					} else { // no edition in the corpus
263
						Log.info(SynopticEditionUIMessages.BackToText_4);
264
						editionsToOpen = new String[0];
265
						return false;
266
					}
267
				} else {
268
					Log.info(SynopticEditionUIMessages.BackToText_5+StringUtils.join(editionsToOpen));
269
				}
270

  
271
				attachedBrowserEditor = OpenEdition.openEdition(corpus, editionsToOpen);
272
				associatedEditors.put(editor, attachedBrowserEditor);
273
				SWTEditorsUtils.addEditor(editor, attachedBrowserEditor, EModelService.ABOVE);
274
			}
275

  
276
			// remove previous highlighted words
277
			if (previousOtherWordIDs != null) {
278
				//System.out.println("remove previousOtherWordIDs="+previousOtherWordIDs);
279
				attachedBrowserEditor.removeHighlightWordsById(lightred, previousOtherWordIDs);
280
				associatedEditorsPreviousOtherWordIDs.remove(editor); // free mem
281
			}
282
			if (previousLineids != null) {
283
				//System.out.println("remove previousLineids="+previousLineids);
284
				attachedBrowserEditor.removeHighlightWordsById(red, previousLineids);
285
				associatedEditorsPreviousLineids.remove(editor); // free mem
286
			}
287

  
288
			//System.out.println("getKeywordsId from "+editor.getTopLine()+" to "+editor.getBottomLine() + 1);
289
			List<String> otherWordIDs = conc.getKeywordsId(textid, editor.getTopLine(), editor.getBottomLine() + 1);
290
			//System.out.println("getKeywordsId="+otherWordIDs);
291
			List<String> lineids = null;
292
			try {
293
				lineids = match.getValuesForProperty(corpus.getProperty("id")); //$NON-NLS-1$
294
			} catch (Exception e1) {
295
				org.txm.rcp.utils.Logger.printStackTrace(e1);
296
				return false;
297
			}
298
			Log.info(NLS.bind("Project id {0} Corpus (Base) id {1} Text id {2}",  //$NON-NLS-1$
299
					new Object[]{projectid, baseid, textid}));
300

  
301
			otherWordIDs.removeAll(lineids); // remove the pivot from others words 
302

  
303
			Text text = corpus.getMainCorpus().getText(textid);
304
			if (text == null) {
305
				System.out.println(NLS.bind("BackToText: Text {0} is missing", textid)); //$NON-NLS-1$
306
				StatusLine.setMessage(NLS.bind("BackToText: Text {0} is missing", textid)); //$NON-NLS-1$
307
				Log.severe(NLS.bind("BackToText: Text {0} is missing", textid)); //$NON-NLS-1$
308
				return false;
309
			}
310

  
311
			String line_wordid = lineids.get(0);
312
			if (line_wordid == null) {
313
				System.out.println(SynopticEditionUIMessages.BackToText_3);
314
				return false;				
315
			}
316

  
317

  
318
			String focusid = null;
319
			if (lineids.size() > 0) focusid = lineids.get(0);
320

  
321
			//System.out.println("add otherWordIDs="+otherWordIDs);
322
			attachedBrowserEditor.addHighlightWordsById(lightred, otherWordIDs);
323

  
324
			//System.out.println("add linesids="+lineids);
325
			attachedBrowserEditor.addHighlightWordsById(red, lineids);
326

  
327
			associatedEditorsPreviousOtherWordIDs.put(editor, otherWordIDs);
328
			associatedEditorsPreviousLineids.put(editor, lineids);
329

  
330
			HashSet<int[]> posses = new HashSet<int[]>();
331
			posses.add(pos);
332
			attachedBrowserEditor.setHighlightedArea(posses);
333

  
334
			attachedBrowserEditor.setFocusedWordID(focusid);
335

  
336
			// reload the page and styles
337
			attachedBrowserEditor.backToText(text, line_wordid);// open the page(S) containing the word with id=line_wordid
338

  
339
			IWorkbenchPage attachedPage = attachedBrowserEditor.getEditorSite().getPage();
340
			attachedPage.activate(attachedBrowserEditor);
341

  
342
			return true;
343

  
344
		} catch (Exception err) {
345
			Log.severe(NLS.bind("Full text display failed: {0}", err)); //$NON-NLS-1$
346
			Log.printStackTrace(err);
347
		}
348
		return false;
349
	}
350
}
0 351

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/handlers/SendEditionTo.java (revision 936)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.edition.rcp.handlers;
29

  
30
import org.eclipse.core.commands.ExecutionEvent;
31
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.txm.core.results.TXMResult;
33
import org.txm.links.rcp.handlers.SendSelectionToQueryable;
34
import org.txm.rcp.editors.IEditionEditor;
35

  
36
/**
37
 * Sends the selected text of an edition to compute another command.
38
 * 
39
 * @author mdecorde
40
 * @author sjacquot
41
 * 
42
 */
43
public class SendEditionTo extends SendSelectionToQueryable {
44

  
45

  
46
	@Override
47
	public String createQuery(ExecutionEvent event, IStructuredSelection selection) {
48
		IEditionEditor editor = (IEditionEditor) this.getActiveEditor(event);
49
		String query = ((IEditionEditor)editor).getTextSelection();
50
		query = "\"" + query.replaceAll("\"", "\\\"");//.replaceAll("("+TokenizerClasses.regPunct+")", " $1 ");
51
		query = query.replaceAll(" +", "\" \"") + "\"";
52
		return query;
53
	}
54
	
55
	@Override
56
	public TXMResult getResultParent(ExecutionEvent event) {
57
		return ((IEditionEditor) this.getActiveEditor(event)).getCorpus();
58
	}
59

  
60
}
0 61

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/preferences/SynopticEditionPreferencePage.java (revision 936)
1
package org.txm.edition.rcp.preferences;
2

  
3
import org.eclipse.jface.preference.BooleanFieldEditor;
4
import org.eclipse.jface.preference.FieldEditorPreferencePage;
5
import org.eclipse.ui.IWorkbench;
6
import org.eclipse.ui.IWorkbenchPreferencePage;
7
import org.eclipse.ui.preferences.ScopedPreferenceStore;
8
import org.txm.rcp.Application;
9

  
10
public class SynopticEditionPreferencePage  extends FieldEditorPreferencePage
11
implements IWorkbenchPreferencePage {
12
	ScopedPreferenceStore preferences;
13

  
14
	private BooleanFieldEditor fast_highlight;
15
	
16
	
17
	public SynopticEditionPreferencePage() {
18
		super();
19
		preferences = new ScopedPreferenceStore(org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE,
20
				Application.PLUGIN_ID);
21
		setPreferenceStore(preferences);
22
		setTitle("Edition");
23
	}
24
	
25
	@Override
26
	public void init(IWorkbench workbench) { }
27

  
28
	@Override
29
	protected void createFieldEditors() {
30
		fast_highlight = new BooleanFieldEditor(SynopticEditionPreferences.FAST_HIGHLIGHT,
31
				"Enable fast word highlight", getFieldEditorParent());
32
		addField(fast_highlight);
33
	}
34
}
0 35

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/preferences/SynopticEditionPreferences.java (revision 936)
1
package org.txm.edition.rcp.preferences;
2

  
3
import org.eclipse.core.runtime.preferences.DefaultScope;
4
import org.osgi.service.prefs.Preferences;
5
import org.txm.core.preferences.TXMPreferences;
6

  
7
public class SynopticEditionPreferences extends TXMPreferences {
8

  
9
	public static String PREFERENCES_NODE = "org.txm.synopticedition.rcp.synoptic";
10
	
11
	public static String FAST_HIGHLIGHT = "fast_highlight";
12

  
13
	@Override
14
	public void initializeDefaultPreferences() {
15
		Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE);
16
		preferences.putBoolean(FAST_HIGHLIGHT, true);
17
	}
18
}
0 19

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/messages/messages.properties (revision 936)
1

  
2
BackToText_0 = Opening with first edition (no default edition set): 
3
BackToText_1 = Aborting: selection is not a concordance line: 
4
BackToText_2 = Aborting: error during selection.
5
BackToText_3 = Error: could not retrieve line word ids. Aborting back to text.
6
BackToText_4 = No edition to open.
7
BackToText_5 = Opening default editions: 
8

  
9
EditionPanel_0 = No edition found for text=
10
EditionPanel_1 = Fail to retrieve first page of edition 
11
EditionPanel_2 = \ and text 
12
EditionPanel_5 = \ edition=
13
EditionPanel_6 = No edition with name 
14
EditionPanel_7 = \ available for text 
15

  
16
EditionSelectorDialog_0 = Editions
17
EditionSelectorDialog_1 = Select one or more editions
18

  
19
OpenEdition_0  = Opening with first edition (no default edition set): 
20
OpenEdition_1  = No edition to open.
21
OpenEdition_10 = Error while opening editor: 
22
OpenEdition_3  = Opening default editions: 
23
OpenEdition_4  = Error while opening edition: 
24
OpenEdition_7  = \ in the corpus
25
OpenEdition_9  = Aborting: selection is not a corpus
26

  
27
SynopticEditionEditor_0  = First text of the corpus
28
SynopticEditionEditor_1  = Previous text
29
SynopticEditionEditor_10 = Next text
30
SynopticEditionEditor_11 = Last text of the corpus
31
SynopticEditionEditor_3  = First page of the text
32
SynopticEditionEditor_4  = Previous page
33
SynopticEditionEditor_5  = No edition found
34
SynopticEditionEditor_6  = Error while getting available editions: 
35
SynopticEditionEditor_7  = Next page
36
SynopticEditionEditor_8  = Last page of the text
37
SynopticEditionEditor_9  = Warning: could not find edition for name: 
0 38

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/messages/messages_fr.properties (revision 936)
1

  
2
BackToText_0 = Ouverture avec la première édition (pas de défaut) : 
3
BackToText_1 = Abandon : la sélection courante n'est pas une ligne de concordance : 
4
BackToText_2 = Abandon : erreur de sélection
5
BackToText_3 = Abandon : erreur pendant la récupération des identifiants de mot.
6
BackToText_4 = Pas d'édition disponible.
7
BackToText_5 = Ouverture de l'édition par défaut : 
8

  
9
EditionPanel_0 = Pas d'édition trouvée pour le texte : 
10
EditionPanel_1 = échec de la récupération de la première page d'édition
11
EditionPanel_2 = \ pour le texte  
12
EditionPanel_5 = \ édition=
13
EditionPanel_6 = Pas d'édition nommée   
14
EditionPanel_7 = \ disponible pour le texte  
15

  
16
EditionSelectorDialog_0 = éditions
17
EditionSelectorDialog_1 = Sélectionner une ou plusieurs éditions.
18

  
19
OpenEdition_0  = Ouverture avec la première édition (pas de défaut) : 
20
OpenEdition_1  = Pas d'édition disponible.
21
OpenEdition_10 = Erreur lors de l'ouverture de l'éditeur : 
22
OpenEdition_3  = Ouverture de l'édition par défaut : 
23
OpenEdition_4  = Erreur lors de l''ouverture de l'édition : 
24
OpenEdition_7  = \ dans le corpus
25
OpenEdition_9  = Abandon : la sélection n'est pas un corpus
26

  
27
SynopticEditionEditor_0  = Premier texte du corpus
28
SynopticEditionEditor_1  = Texte précédent
29
SynopticEditionEditor_10 = Texte suivant
30
SynopticEditionEditor_11 = Dernier texte du corpus
31
SynopticEditionEditor_3  = Première page du texte
32
SynopticEditionEditor_4  = Page précédente
33
SynopticEditionEditor_5  = Pas d'édition trouvée 
34
SynopticEditionEditor_6  = Erreur lors de la récupération des éditions disponibles : 
35
SynopticEditionEditor_7  = Page suivante
36
SynopticEditionEditor_8  = Dernière page du texte
37
SynopticEditionEditor_9  = Attention: échec de la récupération de l'édition  
0 38

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/messages/SynopticEditionUIMessages.java (revision 936)
1
package org.txm.edition.rcp.messages;
2

  
3
import org.eclipse.osgi.util.NLS;
4
import org.txm.utils.messages.Utf8NLS;
5

  
6
public class SynopticEditionUIMessages extends NLS {
7
	
8
	public static String BackToText_0;
9
	public static String BackToText_1;
10
	public static String BackToText_2;
11
	public static String BackToText_3;
12
	public static String BackToText_4;
13
	public static String BackToText_5;
14
	public static String EditionPanel_0;
15
	public static String EditionPanel_1;
16
	public static String EditionPanel_2;
17
	public static String EditionPanel_5;
18
	public static String EditionPanel_6;
19
	public static String EditionPanel_7;
20
	public static String EditionSelectorDialog_0;
21
	public static String EditionSelectorDialog_1;
22
	public static String OpenEdition_0;
23
	public static String OpenEdition_1;
24
	public static String OpenEdition_10;
25
	public static String OpenEdition_3;
26
	public static String OpenEdition_4;
27
	public static String OpenEdition_7;
28
	public static String OpenEdition_9;
29
	public static String SynopticEditionEditor_0;
30
	public static String SynopticEditionEditor_1;
31
	public static String SynopticEditionEditor_10;
32
	public static String SynopticEditionEditor_11;
33
	public static String SynopticEditionEditor_3;
34
	public static String SynopticEditionEditor_4;
35
	public static String SynopticEditionEditor_5;
36
	public static String SynopticEditionEditor_6;
37
	public static String SynopticEditionEditor_7;
38
	public static String SynopticEditionEditor_8;
39
	public static String SynopticEditionEditor_9;
40
	
41
	static {
42
		// initialize resource bundle
43
		Utf8NLS.initializeMessages(SynopticEditionUIMessages.class);
44
	}
45

  
46
	private SynopticEditionUIMessages() {
47
	}
48
}
0 49

  
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/editors/EditionPanel.java (revision 936)
1
package org.txm.edition.rcp.editors;
2

  
3
import java.io.File;
4
import java.net.URL;
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.Collection;
8
import java.util.HashMap;
9
import java.util.HashSet;
10
import java.util.List;
11
import java.util.Set;
12
import java.util.logging.Level;
13

  
14
import org.eclipse.core.commands.Command;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.IParameter;
17
import org.eclipse.core.commands.NotEnabledException;
18
import org.eclipse.core.commands.NotHandledException;
19
import org.eclipse.core.commands.Parameterization;
20
import org.eclipse.core.commands.ParameterizedCommand;
21
import org.eclipse.core.commands.common.NotDefinedException;
22
import org.eclipse.core.runtime.FileLocator;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.jface.action.MenuManager;
25
import org.eclipse.jface.text.ITextSelection;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelectionChangedListener;
28
import org.eclipse.jface.viewers.ISelectionProvider;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.browser.Browser;
31
import org.eclipse.swt.browser.BrowserFunction;
32
import org.eclipse.swt.browser.ProgressEvent;
33
import org.eclipse.swt.browser.ProgressListener;
34
import org.eclipse.swt.events.MenuEvent;
35
import org.eclipse.swt.events.MenuListener;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.events.SelectionListener;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Menu;
40
import org.eclipse.swt.widgets.MenuItem;
41
import org.eclipse.ui.IWorkbenchWindow;
42
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.commands.ICommandService;
44
import org.eclipse.ui.handlers.IHandlerService;
45
import org.eclipse.ui.internal.browser.BrowserViewer;
46
import org.osgi.framework.Bundle;
47
import org.txm.concordance.rcp.actions.BackToText;
48
import org.txm.core.preferences.TXMPreferences;
49
import org.txm.edition.rcp.messages.SynopticEditionUIMessages;
50
import org.txm.edition.rcp.preferences.SynopticEditionPreferencePage;
51
import org.txm.edition.rcp.preferences.SynopticEditionPreferences;
52
import org.txm.objects.Corpus;
53
import org.txm.objects.Edition;
54
import org.txm.objects.Page;
55
import org.txm.objects.Text;
56
import org.txm.rcp.StatusLine;
57
import org.txm.rcp.utils.IOClipboard;
58
import org.txm.utils.io.IOUtils;
59
import org.txm.utils.logger.Log;
60

  
61
public class EditionPanel extends BrowserViewer implements ISelectionProvider {
62

  
63

  
64
	private ProgressListener progresslistener;
65
	//	private List<String> wordids;
66
	//	private List<String> lineids;
67
	/** The edition. */
68
	Text currentText;
69
	Edition currentEdition;
70
	Page currentPage;
71
	protected SynopticEditionEditor synopticEditionEditor;
72
	private ISelectionProvider selProvider;
73
	private MenuManager menuManager;
74

  
75
	private HashSet<int[]> highlightedAreas = null;
76

  
77
	//HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color
78

  
79
	HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>(); // background color
80
	public static final String STYLE_NORMAL = "normal";
81
	public static final String STYLE_ITALIC = "italic";
82
	public static final String STYLE_OBLIQUE = "oblique";
83
	HashMap<String, String> fontStylePerWordIDS = new HashMap<String, String>();
84
	public static final String WEIGHT_NORMAL = "normal";
85
	public static final String WEIGHT_BOLD = "bold";
86
	HashMap<String, String> fontWeightPerWordIDS = new HashMap<String, String>();
87
	HashMap<String, ArrayList<RGBA>> fontColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>();
88
	public static final String SIZE_SMALL = "small";
89
	public static final String SIZE_MEDIUM = "medium";
90
	public static final String SIZE_LARGE = "larger";
91
	public static final String SIZE_SMALLER = "smaller";
92
	public static final String SIZE_LARGER = "larger";
93
	HashMap<String, String> fontSizePerWordIDS = new HashMap<String, String>();
94
	public static final String FAMILLY_TIMES = "\"Times New Roman\", Times";
95
	public static final String FAMILLY_ARIAL = "Arial";
96
	public static final String FAMILLY_COURIER = "\"Courier New\", Courier";
97
	HashMap<String, String> fontFamillyPerWordIDS = new HashMap<String, String>();
98
	public static final String VARIANT_NORMAL = "normal";
99
	public static final String VARIANT_SMALLCAPS = "small-caps";
100
	HashMap<String, String> fontVariantPerWordIDS = new HashMap<String, String>();
101
	String focusedWordID = null;
102

  
103
	public static final String highlightscript = "try { var elt = document.getElementById(\"%s\");" + //$NON-NLS-1$ //$NON-NLS-2$
104
			"elt.style.backgroundColor=\"rgb(%s,%s,%s)\";" + //$NON-NLS-1$
105
			//"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
106
			//"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
107
			//"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
108
			//"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
109
			"} catch (e) { };"; //$NON-NLS-1$
110
	public static final String highlightscriptRuleFast = "sheet.insertRule(\"#%s {background-color:rgba(%s,%s,%s,%s);}\", 0);";
111
	public static final String colorscriptRuleFast = "sheet.insertRule(\"#%s {color:rgba(%s,%s,%s,%s);}\", 0);";
112
	public static final String sizescriptRuleFast = "sheet.insertRule(\"#%s {font-size:%s;}\", 0);";
113
	public static final String stylescriptRuleFast = "sheet.insertRule(\"#%s {font-style:%s;}\", 0);";
114
	public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);";
115
	public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);";
116
	public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);";
117

  
118
	public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);";
119

  
120
	public static final String clearhighlightscript = "try { var elt = document.getElementById(\"%s\"); elt.style.backgroundColor=\"white\";elt.style.fontWeight=\"\";" + //$NON-NLS-1$
121
			"} catch (e) { };"; //$NON-NLS-1$
122

  
123
	public String functions = 
124
			""//"alert(\"loading functions\");"
125
					+"\nfunction getNodeText(node) {"
126
					+"\n	if (typeof node == 'string') return node;"
127
					+"\n	else if (typeof  node.innerText != 'undefined') return node.innerText;"
128
					+"\n	else if (typeof  node.InnerText != 'undefined') return node.InnerText;"
129
					+"\n	else if (typeof  node.textContent != 'undefined') return node.textContent;"
130
					+"\n	else return null;"
131
					+"\n}"
132
					+"\nfunction txmGetParent(node) {"
133
					+"\n	if (typeof  node.parentNode != 'undefined') return node.parentNode;"
134
					+"\n	else return null;"
135
					+"\n}"
136
					+"\nfunction txmGetChildren(node) {"
137
					+"\n	if (typeof node == 'string') return 'STRING HTML';"
138
					+"\n	else if (typeof  node.children != 'undefined') return node.children;"
139
					+"\n	else if (typeof  node.ChildNodes != 'undefined') return node.ChildNodes;"
140
					+"\n	else if (typeof  node.childNodes != 'undefined') return node.childNodes;"
141
					+"\n	else return null;"
142
					+"\n}"
143
					+"\nfunction txmGetSelection() {"
144
					+"\n	if (typeof window.getSelection != 'undefined') {return window.getSelection();}"
145
					+"\n	else if (typeof document.selection != 'undefined') { return document.selection;}"
146
					+"\n	else return 'NO SELECTION';"
147
					+"\n}"
148
					+"\nfunction txmGetRangeSize(selection) {"
149
					+"\n	if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}"
150
					+"\n	else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection"
151
					+"\n}"
152
					+"\nfunction txmGetRange(selection, i) {"
153
					+"\n	if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}"
154
					+"\n	else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5 
155
					+"\n	else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection"
156
					+"\n	else return 'NO RANGE';"
157
					+"\n}"
158
					+"\nfunction txmGetParentElementRange(range) {"
159
					+"\n	if (typeof range.parentElement != 'undefined') {return range.parentElement();}"
160
					+"\n	else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}"
161
					+"\n	else return 'NO PARENT';"
162
					+"\n}"
163
					+"\nfunction txmGetFragment(range) {"
164
					+"\n	if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}"
165
					+"\n	else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; 		return node;"
166
					+"\n	} else return 'NO FRAG';"
167
					+"\n}"
168
					+"\nfunction txmGetTagName(node) {"
169
					+"\n	if (typeof node.tagName != 'undefined') {return node.tagName;}"
170
					+"\n	else if (typeof node.nodeName != 'undefined') { return node.nodeName;}"
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff