Révision 3203

tmp/org.txm.rcp/src/main/java/org/txm/rcp/InstallationPage/PathsInstallationPage.java (revision 3203)
1
package org.txm.rcp.InstallationPage;
2

  
3
import java.io.File;
4
import java.util.Arrays;
5
import java.util.List;
6

  
7
import org.eclipse.jface.viewers.ColumnLabelProvider;
8
import org.eclipse.jface.viewers.DoubleClickEvent;
9
import org.eclipse.jface.viewers.IDoubleClickListener;
10
import org.eclipse.jface.viewers.ITreeContentProvider;
11
import org.eclipse.jface.viewers.TreeViewer;
12
import org.eclipse.jface.viewers.TreeViewerColumn;
13
import org.eclipse.jface.viewers.ViewerComparator;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.events.SelectionListener;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.program.Program;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.swt.widgets.Tree;
24
import org.eclipse.ui.about.InstallationPage;
25
import org.txm.Toolbox;
26

  
27
/**
28
 * Paths TabFolder for the Installation details page
29
 * 
30
 * @author mdecorde
31
 *
32
 */
33
public class PathsInstallationPage extends InstallationPage {
34
	
35
	private TreeViewer treeViewer;
36

  
37
	public PathsInstallationPage() {
38
		
39
		this.setTitle(" TXM's paths");
40
	}
41
	
42
	@Override
43
	public void createControl(Composite parent) {
44
		
45
		parent.setLayout(new GridLayout(1, false));
46
		
47
		Label l = new Label(parent, SWT.NONE);
48
		l.setText("TXM commons paths list.\nClick on the 'Open...' button or double-click a line to open the selected path.");
49
		l.setLayoutData(new GridData());
50
		
51
		treeViewer = new TreeViewer(parent);
52
		Tree tree = treeViewer.getTree();
53
		tree.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
54
		tree.setHeaderVisible(true);
55
		treeViewer.setContentProvider(new  ITreeContentProvider() {
56
			
57
			@SuppressWarnings("rawtypes")
58
			@Override
59
			public boolean hasChildren(Object element) {
60
				if (element instanceof List) {
61
					return !((List) element).isEmpty();
62
				}
63
				return false;
64
			}
65
			
66
			@Override
67
			public Object getParent(Object element) {
68
				
69
				return null;
70
			}
71
			
72
			@Override
73
			public Object[] getElements(Object inputElement) {
74
				
75
				return ((List) inputElement).toArray();
76
			}
77
			
78
			@SuppressWarnings("rawtypes")
79
			@Override
80
			public Object[] getChildren(Object parentElement) {
81
				if (parentElement instanceof List) {
82
					return ((List) parentElement).toArray();
83
				}
84
				return new Object[0];
85
			}
86
		});
87
		
88
		//treeViewer.setComparator(new ViewerComparator());
89
		treeViewer.addDoubleClickListener(new IDoubleClickListener() {
90
			
91
			@Override
92
			public void doubleClick(DoubleClickEvent event) {
93
				openSelection();
94
			}
95
		});
96
		
97
		TreeViewerColumn nameColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
98
		nameColumn.getColumn().setText("What");
99
		nameColumn.getColumn().setWidth(200);
100
		nameColumn.setLabelProvider(new ColumnLabelProvider() {
101
			public String getText(Object element) {
102
				return ((Object[]) element)[0].toString();
103
			}
104
		});
105
		
106
		TreeViewerColumn pathColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
107
		pathColumn.getColumn().setText("Paths");
108
		pathColumn.getColumn().setWidth(200);
109
		pathColumn.setLabelProvider(new ColumnLabelProvider() {
110
			public String getText(Object element) {
111
				return ((Object[]) element)[1].toString();
112
			}
113
		});
114
		
115
		treeViewer.setInput(Arrays.asList(
116
				
117
				new Object[]{"Logs directory", new File(Toolbox.getTxmHomePath(), "logs")}, 
118
				new Object[]{"Crash logs directory", new File(Toolbox.getInstallDirectory())},
119
				new Object[]{"TXM user home directory", new File(Toolbox.getTxmHomePath())},
120
				new Object[]{"Installation directory", new File(Toolbox.getInstallDirectory())}, 
121
				new Object[]{"Instance configuration file", new File(Toolbox.getConfigurationDirectory(), "launcher.ini")}, 
122
				new Object[]{"Instance configuration directory", new File(Toolbox.getConfigurationDirectory())} 
123
				
124
		));
125
		
126
		Button openButton = new Button(parent, SWT.NONE);
127
		openButton.setLayoutData(new GridData());
128
		openButton.setText("Open...");
129
		openButton.setToolTipText("Open the selected path with the default tool set by the system.");
130
		openButton.addSelectionListener(new SelectionListener() {
131
			
132
			@Override
133
			public void widgetSelected(SelectionEvent e) {
134
				
135
				openSelection();
136
			}
137
			
138
			@Override
139
			public void widgetDefaultSelected(SelectionEvent e) { }
140
		});
141
	}
142

  
143
	protected void openSelection() {
144
		
145
		Object selection = treeViewer.getStructuredSelection().getFirstElement();
146
		if (selection != null && selection instanceof Object[]) {
147
			Program.launch(((Object[])selection)[1].toString());
148
		}
149
	}
150
}
0 151

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMBrowserEditor.java (revision 3203)
123 123
	public void setWordsIds(List<String> wordids2, List<String> lineids2) {
124 124
		this.wordids = wordids2;
125 125
		this.lineids = lineids2;
126
		if (progresslistener != null)
126
		
127
		if (progresslistener != null) {
127 128
			this.getBrowser().removeProgressListener(progresslistener);
129
		}
130
		
128 131
		progresslistener = new ProgressListener() {
129 132
			
130 133
			@Override
......
166 169
			}
167 170
		};
168 171
		getBrowser().addProgressListener(progresslistener);
172
		new CommandLink(this, getBrowser());
169 173
	}
170 174
	
171 175
	/**
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/CommandLink.java (revision 3203)
1
package org.txm.rcp.editors;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5

  
6
import org.eclipse.core.commands.Command;
7
import org.eclipse.core.commands.IParameter;
8
import org.eclipse.core.commands.Parameterization;
9
import org.eclipse.core.commands.ParameterizedCommand;
10
import org.eclipse.core.commands.common.NotDefinedException;
11
import org.eclipse.osgi.util.NLS;
12
import org.eclipse.swt.browser.Browser;
13
import org.eclipse.swt.browser.BrowserFunction;
14
import org.eclipse.ui.IEditorPart;
15
import org.eclipse.ui.IWorkbenchWindow;
16
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.commands.ICommandService;
18
import org.eclipse.ui.handlers.IHandlerService;
19
import org.txm.core.messages.TXMCoreMessages;
20

  
21
import org.txm.utils.logger.Log;
22

  
23
public class CommandLink extends BrowserFunction {
24
	
25
	String data = "";
26
	
27
	Browser browser;
28
	
29
	Object ret;
30
	
31
	IEditorPart editor;
32
	
33
	public CommandLink(IEditorPart editor, Browser browser) {
34
		super(browser, "txmcommand"); //$NON-NLS-1$
35
		this.browser = browser;
36
		this.editor = editor;
37
	}
38
	
39
	@Override
40
	public synchronized Object function(Object[] arguments) {
41
		if (editor != null) {
42
			try { // TODO add option (or another browser command) to not force activated editor
43
				editor.getSite().getPage().activate(editor);
44
			}
45
			catch (Exception e) {
46
				System.out.println(e);
47
			}
48
		}
49
		ret = null;
50
		browser.getDisplay().asyncExec(new Runnable() {
51
			
52
			@Override
53
			public void run() {
54
				ret = callTXMCommand(arguments);
55
			}
56
		});
57
		return ret;
58
	}
59
	/**
60
	 * 
61
	 * @param editor may be null, will be used by the command to display its result
62
	 * @param arguments array of command id + (parameters+values).
63
	 * 
64
	 *            <pre>
65
	 * ex: String[] arguments = {"commandid", "paramname", "value", "paramname2", "othervalue"};
66
	 *            </pre>
67
	 * 
68
	 * @return
69
	 */
70
	public static Object callTXMCommand(Object[] arguments) {
71
		HashMap<String, String> params = new HashMap<>();
72
		for (int i = 0; i + 1 < arguments.length; i += 2) {
73
			params.put(arguments[i].toString(), arguments[i + 1].toString());
74
		}
75
		
76
		String id = params.get("id"); //$NON-NLS-1$
77
		if (id != null) {
78
			params.remove("id"); //$NON-NLS-1$
79
			// System.out.println("CALLING CMD with id="+id+" and parameters="+params);
80
			// get the command from plugin.xml
81
			callTXMCommand(id, params);
82
		}
83
		else {
84
			System.out.println(NLS.bind("Cannot call a TXM command without ID (parameters={0}).", params));
85
		}
86
		return arguments;
87
	}
88
	/**
89
	 * Browser command that opens an edition
90
	 * 
91
	 * @author mdecorde
92
	 *
93
	 */
94
	public static Object callTXMCommand(String id, HashMap<String, String> params) {
95
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
96
		ICommandService cmdService = window.getService(ICommandService.class);
97
		Command cmd = cmdService.getCommand(id);
98
		
99
		// get the parameter
100
		ArrayList<Parameterization> parameters = new ArrayList<>();
101
		ArrayList<String> failedParameters = new ArrayList<>();
102
		for (String k : params.keySet()) {
103
			try {
104
				IParameter iparam = cmd.getParameter(k);
105
				Parameterization p = new Parameterization(iparam, params.get(k));
106
				parameters.add(p);
107
			}
108
			catch (NotDefinedException e) {
109
				// Log.warning(NLS.bind(EditionUIMessages.warningColonUnknownedParameterIdEqualsP0, k));
110
				failedParameters.add(k);
111
			}
112
		}
113
		
114
		// build the parameterized command
115
		ParameterizedCommand pc = new ParameterizedCommand(cmd, parameters.toArray(new Parameterization[parameters.size()]));
116
		
117
		// execute the command
118
		IHandlerService handlerService = window.getService(IHandlerService.class);
119
		try {
120
			return handlerService.executeCommand(pc, null);
121
		}
122
		catch (Exception e) {
123
			Log.warning(TXMCoreMessages.bind("The ''{0}'' hyperlinked command failed with the ''{1}'' parameters and the not recognized ''{2}'' parameters.", id, parameters, failedParameters));
124
			// Log.printStackTrace(e);
125
		}
126
		return null;
127
	}
128
}
0 129

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/GLComposite.java (revision 3203)
11 11
 *
12 12
 */
13 13
public class GLComposite extends Composite {
14

  
14
	
15 15
	private GridLayout gl;
16 16
	private String name;
17

  
17
	
18 18
	public GLComposite(Composite parent, int style, String name) {
19 19
		super(parent, style);
20 20
		gl = createDefaultLayout(1);
21 21
		this.name = name;
22 22
		super.setLayout(gl);
23 23
	}
24

  
24
	
25 25
	public final GridLayout getLayout() {
26 26
		return gl;
27 27
	}
tmp/org.txm.rcp/rcpapplication.product (revision 3203)
6 6
   <aboutInfo>
7 7
      <image path="/org.txm.rcp/icons/logo/about TXM.png"/>
8 8
      <text>
9
         &lt;TXM Software User Agreement&gt;
9
         [Contrat d&apos;utilisation du logiciel TXM]
10 10

  
11
TXM 0.8.1 Copyright © 2010-2020 ENS de Lyon, University of Franche-Comté, CNRS
11
TXM 0.8.1 Copyright © 2010-2021 ENS de Lyon, University of Franche-Comté, CNRS
12 12

  
13 13
&lt;English version below&gt;
14 14

  
15
EN ACCEPTANT CETTE MISE À JOUR ET EN UTILISANT TXM, VOUS VOUS ENGAGEZ À CITER L&apos;ARTICLE DE RÉFÉRENCE DE LA PLATEFORME* DANS VOS PUBLICATIONS DE RÉSULTATS OBTENUS À PARTIR D&apos;ELLE. CELA EST ESSENTIEL POUR NOUS PERMETTRE DE JUSTIFIER LE BESOIN DE PÉRENNISATION DE CET INSTRUMENT DE TRAVAIL POUR LA COMMUNAUTÉ SCIENTIFIQUE.
15
EN ACCEPTANT CETTE INSTALLATION OU MISE À JOUR ET EN UTILISANT TXM, VOUS VOUS ENGAGEZ À CITER L&apos;ARTICLE DE RÉFÉRENCE DE LA PLATEFORME* DANS VOS PUBLICATIONS DE RÉSULTATS OBTENUS À PARTIR D&apos;ELLE. CELA EST ESSENTIEL POUR NOUS PERMETTRE DE JUSTIFIER LE BESOIN DE PÉRENNISATION DE CET INSTRUMENT DE TRAVAIL POUR LA COMMUNAUTÉ SCIENTIFIQUE.
16 16

  
17 17
Le logiciel TXM est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier suivant les termes de la Licence publique générale GNU telle que publiée par la Free Software Foundation, soit la version 2 de cette License, soit une version ultérieure.
18 18

  
......
27 27

  
28 28
ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH ENGLISH
29 29

  
30
[TXM Software User Agreement]
30 31

  
31 32
By accepting this update and by using TXM, you agree to cite the TXM platform reference article** in your publications of results obtained from it. That is essential for us to justify the need for sustainability of this instrument for the scientific community.
32 33

  
......
78 79
      </win>
79 80
   </launcher>
80 81

  
82

  
81 83
   <vm>
82 84
      <linux include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</linux>
83 85
      <macos include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</macos>
tmp/org.txm.rcp/plugin.xml (revision 3203)
3312 3312
         </run>
3313 3313
      </runtime>
3314 3314
   </extension>
3315
   <extension
3316
         point="org.eclipse.ui.installationPages">
3317
      <page
3318
            class="org.txm.rcp.InstallationPage.PathsInstallationPage"
3319
            id="org.txm.rcp.installationPages.paths"
3320
            name="Paths">
3321
      </page>
3322
   </extension>
3315 3323

  
3316 3324
</plugin>

Formats disponibles : Unified diff