Révision 3662

TXM/trunk/bundles/org.txm.xmleditor.rcp/plugin.xml (revision 3662)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>  
4
   <extension
5
         point="org.eclipse.ui.commands">
6
      <command
7
            categoryId="org.txm.rcp.category.txm"
8
            defaultHandler="org.txm.xmleditor.OpenXMLEditor"
9
            id="org.txm.xmleditor.OpenXMLEditor"
10
            name="%command.name">
11
      </command>
12
   </extension>
13
   <extension
14
         point="org.eclipse.ui.menus">
15
      <menuContribution
16
            locationURI="menu:menu.file?after=menu.file.separator.open">
17
      </menuContribution>
18
      <menuContribution
19
            locationURI="menu:menu.help.plugins">
20
      </menuContribution>
21
      <menuContribution
22
            locationURI="popup:org.txm.rcp.views.fileexplorer.Explorer">
23
      </menuContribution>
24
      <menuContribution
25
            locationURI="popup:org.txm.edition.rcp.editors.SynopticEditionEditor">
26
         <command
27
               commandId="org.txm.xmleditor.OpenXMLEditor"
28
               label="%command.label.0"
29
               style="push">
30
         </command>
31
      </menuContribution>
32
      <menuContribution
33
            locationURI="popup:org.txm.concordance.rcp.editors.ConcordanceEditor">
34
         <command
35
               commandId="org.txm.xmleditor.OpenXMLEditor"
36
               label="%command.label.0"
37
               style="push">
38
         </command>
39
      </menuContribution>
40
   </extension>
41
   <extension
42
         point="org.eclipse.ui.activities">
43
         
44
  <activityPatternBinding
45
        activityId="arm.activity.disabled"
46
        pattern=".*org\.eclipse\.search\..*">
47
  </activityPatternBinding>
48
  <activityPatternBinding
49
        activityId="arm.activity.disabled"
50
        pattern=".*ValidationPreferencePage.*">
51
  </activityPatternBinding>
52
  <activityPatternBinding
53
        activityId="arm.activity.disabled"
54
        pattern=".*org\.eclipse\.debug\.ui\.DebugPreferencePage.*">
55
  </activityPatternBinding>
56
      <activityPatternBinding
57
        activityId="arm.activity.disabled"
58
        pattern=".*org\.eclipse\.team\.ui\.TeamPreferences.*">
59
  </activityPatternBinding>
60
  
61
      <activity
62
            id="arm.activity.disabled"
63
            name="%activity.name">
64
            <enabledWhen>
65
        <with
66
              variable="selection">
67
           <count
68
                 value="-1">
69
           </count>
70
        </with>
71
     </enabledWhen>
72
      </activity>
73
   </extension>
74

  
75
</plugin>
0 76

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/.classpath (revision 3662)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con"
4
		path="org.eclipse.jdt.launching.JRE_CONTAINER" />
5
	<classpathentry kind="con"
6
		path="org.eclipse.pde.core.requiredPlugins">
7
		<accessrules>
8
			<accessrule kind="accessible" pattern="**" />
9
		</accessrules>
10
	</classpathentry>
11
	<classpathentry kind="src" path="src" />
12
	<classpathentry kind="output" path="bin" />
13
</classpath>
0 14

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/META-INF/MANIFEST.MF (revision 3662)
1
Manifest-Version: 1.0
2
Export-Package: org.txm.xmleditor,org.txm.xmleditor.messages
3
Bundle-SymbolicName: org.txm.xmleditor.rcp;singleton:=true
4
Bundle-Version: 1.0.0.qualifier
5
Bundle-Name: %Bundle-Name
6
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.12.0,4.0.0)";visibility:=reexport,
7
 org.eclipse.ui.views;bundle-version="[3.8.0,4.0.0)";visibility:=reexport,
8
 org.eclipse.jface.text;bundle-version="[3.10.0,4.0.0)";visibility:=reexport,
9
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.10.0,4.0.0)";visibility:=reexport,
10
 org.eclipse.wst.sse.ui;bundle-version="1.3.500";visibility:=reexport,
11
 org.eclipse.wst.sse.core;bundle-version="1.1.900";visibility:=reexport,
12
 org.eclipse.ui;bundle-version="[3.107.0,4.0.0)";visibility:=reexport,
13
 org.eclipse.core.resources;bundle-version="[3.11.0,4.0.0)";visibility:=reexport,
14
 org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)";visibility:=reexport,
15
 org.eclipse.wst.common.uriresolver;bundle-version="1.3.0";visibility:=reexport,
16
 org.eclipse.wst.xml.core;bundle-version="1.1.1100";visibility:=reexport,
17
 org.eclipse.wst.common.ui;bundle-version="1.2.100";visibility:=reexport,
18
 org.eclipse.wst.validation;bundle-version="[1.2.700,1.3.0)";visibility:=reexport,
19
 org.eclipse.wst.validation.ui;visibility:=reexport,
20
 org.eclipse.core.expressions;bundle-version="[3.5.0,4.0.0)";visibility:=reexport,
21
 org.eclipse.core.filesystem;bundle-version="[1.6.0,2.0.0)";visibility:=reexport,
22
 org.txm.rcp;bundle-version="0.7.8",
23
 org.eclipse.wst.xml.ui;bundle-version="1.1.800";visibility:=reexport,
24
 org.txm.concordance.rcp;bundle-version="1.0.0",
25
 org.txm.edition.rcp;bundle-version="1.0.0",
26
 org.eclipse.search;visibility:=reexport
27
Bundle-ActivationPolicy: lazy
28
Bundle-ManifestVersion: 2
29
Bundle-RequiredExecutionEnvironment: JavaSE-16
30
Bundle-Vendor: Textometrie.org
31
Automatic-Module-Name: org.txm.xmleditor.rcp
32

  
0 33

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/.project (revision 3662)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.xmleditor.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

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/src/org/txm/xmleditor/messages/XMLEditorMessages.java (revision 3662)
1
package org.txm.xmleditor.messages;
2

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

  
6
public class XMLEditorMessages extends NLS {
7
	
8
	private static final String BUNDLE_NAME = "org.txm.xmleditor.messages.messages"; //$NON-NLS-1$
9
	
10
	public static String AbortingTheOpeningOfP0;
11

  
12
	public static String BigFile;
13

  
14
	public static String OpenXMLEditor_1;
15
	
16
	public static String OpenXMLEditor_3;
17
	
18
	public static String OpenXMLEditor_4;
19

  
20
	public static String P0IsAVeryBigFileDoYouWantToContinueAndOpensIt;
21
	
22
	public static String SelectedWordFromP0ToP1;
23

  
24
	public static String SelectedWordP0;
25

  
26
	public static String WordSelectionIdentifiersP0;
27

  
28
	static {
29
		// initialize resource bundle
30
		Utf8NLS.initializeMessages(BUNDLE_NAME, XMLEditorMessages.class);
31
	}
32
	
33
	private XMLEditorMessages() {}
34
}
0 35

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/src/org/txm/xmleditor/messages/messages.properties (revision 3662)
1
AbortingTheOpeningOfP0=Aborting the opening of {0}
2
BigFile=Big file
3
OpenXMLEditor_1=Open XML Editor...
4
OpenXMLEditor_3=Opening XML editor...
5
OpenXMLEditor_4=Error: 
6
P0IsAVeryBigFileDoYouWantToContinueAndOpensIt={0} is a very big file. Do you want to continue and opens it?
7
SelectedWordFromP0ToP1=Selected word: from {0} to {1}
8
SelectedWordP0=Selected word: {0}
9
WordSelectionIdentifiersP0=Word selection identifiers: {0}
0 10

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/src/org/txm/xmleditor/messages/messages_fr.properties (revision 3662)
1
OpenXMLEditor_1=Ouverture de l''?diteur XML...
2
OpenXMLEditor_3=Ouverture de l''?diteur XML...
3
OpenXMLEditor_4=Erreur : 
0 4

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/src/org/txm/xmleditor/OpenXMLEditor.java (revision 3662)
1
package org.txm.xmleditor;
2

  
3
import java.io.File;
4

  
5
import org.eclipse.core.commands.AbstractHandler;
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.core.filesystem.EFS;
9
import org.eclipse.core.filesystem.IFileStore;
10
import org.eclipse.jface.dialogs.MessageDialog;
11
import org.eclipse.jface.viewers.ISelection;
12
import org.eclipse.jface.viewers.IStructuredSelection;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.widgets.FileDialog;
15
import org.eclipse.swt.widgets.Shell;
16
import org.eclipse.ui.IEditorPart;
17
import org.eclipse.ui.IWorkbenchPage;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.PartInitException;
20
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.handlers.HandlerUtil;
22
import org.eclipse.ui.ide.FileStoreEditorInput;
23
import org.eclipse.wst.sse.ui.StructuredTextEditor;
24
import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
25
import org.txm.Toolbox;
26
import org.txm.concordance.core.functions.Concordance;
27
import org.txm.concordance.core.functions.Line;
28
import org.txm.edition.rcp.editors.SynopticEditionEditor;
29
import org.txm.objects.Text;
30
import org.txm.rcp.StatusLine;
31
import org.txm.rcp.swt.dialog.LastOpened;
32
import org.txm.utils.logger.Log;
33
import org.txm.xmleditor.messages.XMLEditorMessages;
34

  
35
public class OpenXMLEditor extends AbstractHandler {
36
	
37
	public static final String ID = "org.txm.xmleditor.OpenXMLEditor"; //$NON-NLS-1$
38
	
39
	public static String lastopenedfile;
40
	
41
	public int ALERT = 1000000;
42
	
43
	@Override
44
	public Object execute(ExecutionEvent event) throws ExecutionException {
45
		
46
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
47
		IEditorPart editor = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage().getActiveEditor();
48
		ISelection iselection = HandlerUtil.getCurrentSelection(event);
49
		Object selection = null;
50
		if (iselection instanceof IStructuredSelection) {
51
			selection = ((IStructuredSelection) iselection).getFirstElement();
52
		}
53
		
54
		String txmhome = Toolbox.getTxmHomePath();
55
		String filename = event.getParameter("org.txm.rcp.commands.commandParameter2"); //$NON-NLS-1$
56
		IEditorPart reditor = null;
57
		if (editor instanceof SynopticEditionEditor) {
58
			Text text = ((SynopticEditionEditor) editor).getEditionPanel(0).getEdition().getText();
59
			String[] wordSelection = ((SynopticEditionEditor) editor).getEditionPanel(0).getWordSelection();
60
			
61
			File txmFile = text.getXMLTXMFile();
62
			if (txmFile != null && txmFile.exists()) {
63
				if (txmFile.length() > ALERT) {
64
					if (!MessageDialog.openQuestion(shell, XMLEditorMessages.BigFile,
65
							XMLEditorMessages.bind(XMLEditorMessages.P0IsAVeryBigFileDoYouWantToContinueAndOpensIt, txmFile.getAbsolutePath()))) {
66
						Log.info(XMLEditorMessages.bind(XMLEditorMessages.AbortingTheOpeningOfP0, txmFile));
67
						return null;
68
					}
69
				}
70
				reditor = openfile(txmFile);
71
			}
72
			else { // wrong link ?
73
				txmFile = new File(text.getProject().getProjectDirectory(), "txm/" + text.getProject().getName() + "/" + text.getName() + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
74
				reditor = openfile(txmFile);
75
			}
76
			
77
			if (wordSelection != null && wordSelection[0] != null && reditor instanceof XMLMultiPageEditorPart) {
78
				XMLMultiPageEditorPart xmlEditor = (XMLMultiPageEditorPart) reditor;
79
				// System.out.println("xmlEditor=" + xmlEditor);
80
				// System.out.println("word=" + wordSelection[0]);
81
				Object selectedPage = xmlEditor.getSelectedPage();
82
				if (selectedPage != null && selectedPage instanceof StructuredTextEditor) {
83
					// StructuredTextEditor textEditor = (StructuredTextEditor) selectedPage;
84
					//
85
					// String search = "\""+wordSelection[0]+"\"";
86
					if (wordSelection[1] == null) {
87
						System.out.println(XMLEditorMessages.bind(XMLEditorMessages.SelectedWordP0, wordSelection[0]));
88
					}
89
					else {
90
						System.out.println(XMLEditorMessages.bind(XMLEditorMessages.SelectedWordFromP0ToP1, wordSelection[0], wordSelection[1])); //$NON-NLS-2$
91
					}
92
				}
93
			}
94
		}
95
		else if (selection != null && selection instanceof Line) {
96
			Line line = (Line) selection;
97
			Concordance conc = line.getConcordance();
98
			String text = line.getTextId();
99
			
100
			File txmFile = new File(conc.getProject().getProjectDirectory(), "txm/" + conc.getCorpus().getID() + "/" + text + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
101
			reditor = openfile(txmFile);
102
			if (reditor != null & reditor instanceof XMLMultiPageEditorPart) {
103
				XMLMultiPageEditorPart xmlEditor = (XMLMultiPageEditorPart) reditor;
104
				Object selectedPage = xmlEditor.getSelectedPage();
105
				if (selectedPage != null && selectedPage instanceof StructuredTextEditor) {
106
					System.out.println(XMLEditorMessages.bind(XMLEditorMessages.WordSelectionIdentifiersP0, line.getKeywordIds()));
107
				}
108
			}
109
		}
110
		else if (filename != null && !filename.matches("") && !filename.matches(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
111
			String filepath = txmhome + "/scripts/" + filename; //$NON-NLS-1$
112
			return openfile(new File(filepath));
113
		}
114
		
115
		if (reditor != null) return null;
116
		
117
		
118
		File file = null;
119
		if (iselection != null & iselection instanceof IStructuredSelection) {
120
			for (Object o : ((IStructuredSelection) iselection).toList()) {
121
				if (o != null && o instanceof File) {
122
					file = (File) o;
123
					break;
124
				}
125
			}
126
		}
127
		
128
		if (file == null) {
129
			
130
			FileDialog dialog = new FileDialog(shell, SWT.OPEN);
131
			if (LastOpened.getFile(ID) != null) {
132
				dialog.setFilterPath(LastOpened.getFolder(ID));
133
				dialog.setFileName(LastOpened.getFile(ID));
134
			}
135
			else {
136
				dialog.setFilterPath(txmhome);
137
			}
138
			if (dialog.open() == null) return null;
139
			String filepath = dialog.getFilterPath()
140
					+ "/" + dialog.getFileName(); //$NON-NLS-1$
141
			lastopenedfile = filepath;
142
			LastOpened.set(ID, dialog.getFilterPath(), dialog.getFileName());
143
			openfile(new File(filepath));
144
		}
145
		else {
146
			if (file.isDirectory()) {
147
				FileDialog dialog = new FileDialog(shell, SWT.OPEN);
148
				dialog.setFilterPath(file.getAbsolutePath());
149
				dialog.open();
150
				String filepath = dialog.getFilterPath()
151
						+ "/" + dialog.getFileName(); //$NON-NLS-1$
152
				openfile(new File(filepath));
153
			}
154
			else {
155
				openfile(file);
156
			}
157
		}
158
		
159
		return null;
160
	}
161
	
162
	private IEditorPart openfile(File file) {
163
		// XMLMultiPageEditorPart editorInput = new ConcordancesEditorInput(corpus, null);
164
		Log.fine(XMLEditorMessages.OpenXMLEditor_1);
165
		IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(
166
				file.toURI());
167
		
168
		FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk);
169
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
170
		IWorkbenchPage page = window.getActivePage();
171
		
172
		String ID = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$
173
		try {
174
			StatusLine.setMessage(XMLEditorMessages.OpenXMLEditor_3);
175
			IEditorPart editor = page.openEditor(editorInput, ID); // $NON-NLS-1$
176
			if (editor != null && editor instanceof XMLMultiPageEditorPart) {
177
				XMLMultiPageEditorPart xmlEditor = ((XMLMultiPageEditorPart) editor);
178
				xmlEditor.removePage(0);
179
				return xmlEditor;
180
			}
181
			
182
			return editor;
183
		}
184
		catch (PartInitException e) {
185
			System.out.println(XMLEditorMessages.OpenXMLEditor_4 + e);
186
		}
187
		return null;
188
	}
189
}
0 190

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/build.properties (revision 3662)
1
#Fri Jul 06 10:25:20 CEST 2018
2
output..=bin/
3
bin.includes = plugin.xml,\
4
               META-INF/,\
5
               .,\
6
               OSGI-INF/
7
source..=src/
8
#qualifier=svn
0 9

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/OSGI-INF/l10n/bundle.properties (revision 3662)
1
#Properties file for XmlEditorRCP
2
command.name = Open XML File...
3
command.label = XmlEditor
4
command.tooltip = Open the selected file with the XML editor
5
activity.name = disable activity
6
Bundle-Name = XmlEditorRCP
7
command.label.0 = Open the XML-TEI TXM file
0 8

  
TXM/trunk/bundles/org.txm.xmleditor.rcp/OSGI-INF/l10n/bundle_fr.properties (revision 3662)
1
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
2
#Properties file for XmlEditorRCP
3

  
4
Bundle-Name = \u00C9diteur XML
5

  
6
activity.name = disable activity
7

  
8
command.label = \u00C9diteur XML
9

  
10
command.name = Ouvrir un fichier XML
11

  
12
command.label.0 = Ouvrir le fichier XML-TEI TXM
13
command.tooltip = Ouvre le fichier s\u00E9lectionner dans l'\u00E9diteur XML
0 14

  

Formats disponibles : Unified diff