Révision 3953

TXM/trunk/bundles/org.txm.queryindex.rcp/plugin.xml (revision 3953)
30 30
         point="org.eclipse.ui.commands">
31 31
          <command
32 32
            categoryId="org.txm.rcp.category.txm"
33
            defaultHandler="org.txm.queryindex.rcp.commands.function.ComputeQueryIndex"
33
            defaultHandler="org.txm.queryindex.rcp.commands.ComputeQueryIndex"
34 34
            id="org.txm.rcp.commands.function.ComputeQueryIndex"
35 35
            name="%command.name">
36 36
      </command>
TXM/trunk/bundles/org.txm.queryindex.rcp/META-INF/MANIFEST.MF (revision 3953)
1 1
Manifest-Version: 1.0
2
Export-Package: org.txm.queryindex.core.functions,org.txm.queryindex.r
3
 cp.commands.function,org.txm.queryindex.rcp.commands.link,org.txm.que
4
 ryindex.rcp.editors,queryindexrcp,queryindexrcp.actions,queryindexrcp
5
 .adapters
2
Export-Package: org.txm.queryindex.core.functions,
3
 org.txm.queryindex.rcp.commands,
4
 org.txm.queryindex.rcp.editors,
5
 queryindexrcp,
6
 queryindexrcp.adapters
6 7
Bundle-SymbolicName: org.txm.queryindex.rcp;singleton:=true
7 8
Bundle-Version: 1.0.0.qualifier
8 9
Bundle-Name: %Bundle-Name
TXM/trunk/bundles/org.txm.queryindex.rcp/src/queryindexrcp/actions/SampleAction.java (revision 3953)
1
package queryindexrcp.actions;
2

  
3
import org.eclipse.jface.action.IAction;
4
import org.eclipse.jface.viewers.ISelection;
5
import org.eclipse.ui.IWorkbenchWindow;
6
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
7
import org.eclipse.jface.dialogs.MessageDialog;
8

  
9
/**
10
 * Our sample action implements workbench action delegate.
11
 * The action proxy will be created by the workbench and
12
 * shown in the UI. When the user tries to use the action,
13
 * this delegate will be created and execution will be 
14
 * delegated to it.
15
 * @see IWorkbenchWindowActionDelegate
16
 */
17
public class SampleAction implements IWorkbenchWindowActionDelegate {
18
	private IWorkbenchWindow window;
19
	/**
20
	 * The constructor.
21
	 */
22
	public SampleAction() {
23
	}
24

  
25
	/**
26
	 * The action has been activated. The argument of the
27
	 * method represents the 'real' action sitting
28
	 * in the workbench UI.
29
	 * @see IWorkbenchWindowActionDelegate#run
30
	 */
31
	public void run(IAction action) {
32
		MessageDialog.openInformation(
33
			window.getShell(),
34
			"QueryIndexRCP", //$NON-NLS-1$
35
			"Hello, Eclipse world"); //$NON-NLS-1$
36
	}
37

  
38
	/**
39
	 * Selection in the workbench has been changed. We 
40
	 * can change the state of the 'real' action here
41
	 * if we want, but this can only happen after 
42
	 * the delegate has been created.
43
	 * @see IWorkbenchWindowActionDelegate#selectionChanged
44
	 */
45
	public void selectionChanged(IAction action, ISelection selection) {
46
	}
47

  
48
	/**
49
	 * We can use this method to dispose of any system
50
	 * resources we previously allocated.
51
	 * @see IWorkbenchWindowActionDelegate#dispose
52
	 */
53
	public void dispose() {
54
	}
55

  
56
	/**
57
	 * We will cache window object in order to
58
	 * be able to provide parent shell for the message dialog.
59
	 * @see IWorkbenchWindowActionDelegate#init
60
	 */
61
	public void init(IWorkbenchWindow window) {
62
		this.window = window;
63
	}
64
}
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/QueryIndexEditor.java (revision 3953)
330 330
							return Status.CANCEL_STATUS;
331 331
						}
332 332
						
333
						if (monitor.isCanceled())
333
						if (monitor.isCanceled()) {
334 334
							return Status.CANCEL_STATUS;
335
						
335
						}
336 336
						queryindex.sortLines(SortMode.FREQUNIT, true);
337 337
						
338
						if (monitor.isCanceled())
338
						if (monitor.isCanceled()) {
339 339
							return Status.CANCEL_STATUS;
340
						
340
						}
341 341
						this.acquireSemaphore();
342 342
						this.releaseSemaphore();
343 343
						
344 344
						final String message = Messages.QueryIndexEditor_3;
345 345
						
346
						if (monitor.isCanceled())
346
						if (monitor.isCanceled()) {
347 347
							return Status.CANCEL_STATUS;
348
						
348
						}
349 349
						monitor.worked(95);
350 350
						// refresh ui
351 351
						syncExec(new Runnable() {
......
364 364
								setPartName(title);
365 365
								
366 366
								queryWidget.memorize();
367
								nblinesperpage = NLignePPageSpinner
368
										.getSelection();
367
								nblinesperpage = NLignePPageSpinner.getSelection();
369 368
								
370
								fillDisplayArea(0,
371
										NLignePPageSpinner.getSelection());
369
								fillDisplayArea(0, NLignePPageSpinner.getSelection());
372 370
								
373 371
								if (line != null) {
374 372
									queryWidget.setText(""); //$NON-NLS-1$
......
418 416
		
419 417
		final Group paramArea = getExtendedParametersGroup();
420 418
		
421
		
422 419
		GLComposite resultArea = getResultArea();
423 420
		
424 421
		// on créé une Query, ici le pivot de la concordance est "[]"
......
436 433
		// true));
437 434
		
438 435
		// [ (v)]
439
		queryWidget = new NamedAssistedQueryWidget(queryArea, SWT.DROP_DOWN,
440
				this.corpus);
436
		queryWidget = new NamedAssistedQueryWidget(queryArea, SWT.DROP_DOWN, this.corpus);
441 437
		GridData layoutData = new GridData(GridData.FILL);
442 438
		layoutData.horizontalAlignment = GridData.FILL;
443 439
		layoutData.grabExcessHorizontalSpace = true;
......
462 458
		loadFromFile.setEnabled(true);
463 459
		loadFromFile.setText(Messages.QueryIndexEditor_4);
464 460
		loadFromFile
465
				.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
461
		.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
466 462
		loadFromFile.addSelectionListener(new SelectionListener() {
467 463
			
468 464
			@Override
469 465
			public void widgetSelected(SelectionEvent e) {
470 466
				File propFile = null;
471
				if (LastOpened.getFile(ID) != null)
467
				if (LastOpened.getFile(ID) != null) {
472 468
					propFile = new File(LastOpened.getFolder(ID));
473
				
469
				}
474 470
				FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
475 471
				String[] exts = { "*.properties" }; // $NON-NLS //$NON-NLS-1$
476 472
				dialog.setFilterExtensions(exts);
......
560 556
		NLignePPageSpinner.setSelection(100);
561 557
		NLignePPageSpinner.setIncrement(1);
562 558
		NLignePPageSpinner.setPageIncrement(100);
563
		NLignePPageSpinner.setLayoutData(new GridData(
564
				GridData.VERTICAL_ALIGN_END));
559
		NLignePPageSpinner.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
565 560
		NLignePPageSpinner.addSelectionListener(new SelectionListener() {
566 561
			
567 562
			@Override
......
579 574
		// infosArea.setLayout(new GridLayout(6, false));
580 575
		
581 576
		navigationArea = new NavigationWidget(filtercontrols, SWT.NONE);
582
		navigationArea.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
583
				false));
577
		navigationArea.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
584 578
		
585 579
		navigationArea.addFirstListener(new SelectionListener() {
586 580
			
......
601 595
			
602 596
			@Override
603 597
			public void widgetSelected(SelectionEvent e) {
604
				int top = (queryindex.getV() / NLignePPageSpinner
605
						.getSelection()) * NLignePPageSpinner.getSelection();
598
				int top = (queryindex.getV() / NLignePPageSpinner.getSelection()) * NLignePPageSpinner.getSelection();
606 599
				int bottom = top + NLignePPageSpinner.getSelection();
607 600
				fillDisplayArea(top, bottom);
608 601
				viewer.getTable().select(0);
......
631 624
			@Override
632 625
			public void widgetSelected(SelectionEvent e) {
633 626
				int top = topLine - NLignePPageSpinner.getSelection();
634
				if (top < 0)
627
				if (top < 0) {
635 628
					top = 0;
629
				}
636 630
				int bottom = top + NLignePPageSpinner.getSelection();
637 631
				fillDisplayArea(top, bottom);
638 632
				viewer.getTable().select(0);
......
652 646
		lFminInfo = new Label(filtercontrols, SWT.NONE);
653 647
		lFminInfo.setText(""); //$NON-NLS-1$
654 648
		lFminInfo
655
				.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
649
		.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
656 650
		
657 651
		lFmaxInfo = new Label(filtercontrols, SWT.NONE);
658 652
		lFmaxInfo.setText(""); //$NON-NLS-1$
659 653
		lFmaxInfo
660
				.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
654
		.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
661 655
		
662 656
		// results
663 657
		viewer = new TableViewer(resultArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
......
665 659
		viewer.getTable().setHeaderVisible(true);
666 660
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
667 661
		viewer.getTable().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
668
		if (corpus != null && corpus.getProject().getFont() != null
669
				&& corpus.getProject().getFont().length() > 0) {
662
		if (corpus != null && corpus.getProject().getFont() != null && corpus.getProject().getFont().length() > 0) {
670 663
			Font old = viewer.getTable().getFont();
671 664
			FontData fD = old.getFontData()[0];
672
			Font font = new Font(Display.getCurrent(), corpus.getProject().getFont(),
673
					fD.getHeight(), fD.getStyle());
665
			Font font = new Font(Display.getCurrent(), corpus.getProject().getFont(), fD.getHeight(), fD.getStyle());
674 666
			viewer.getTable().setFont(font);
675 667
		}
676 668
		
......
682 674
			
683 675
			@Override
684 676
			public void mouseDoubleClick(MouseEvent e) {
685
				Point mouseposition = new Point(e.x
686
						+ viewer.getTable().getHorizontalBar().getSelection(),
687
						e.y);
677
				Point mouseposition = new Point(e.x + viewer.getTable().getHorizontalBar().getSelection(), e.y);
688 678
				int col = getPointedColumn(mouseposition);
689 679
				if (col == 1) {
690 680
					// IndexToConcordance.link(self,
......
802 792
		// rmv/creates parts columns if needed
803 793
		if (this.partition != null) {
804 794
			List<String> partnames = this.partition.getPartNames();
805
			if (partnames.size() > 1)
795
			if (partnames.size() > 1) {
806 796
				if (viewer.getTable().getColumnCount() < partnames.size() + 3) {
807
				for (int i = 0; i < partnames.size(); i++) {
808
				final TableColumn partColumn = new TableColumn(
809
						viewer.getTable(), SWT.RIGHT);
810
				try {
811
				partColumn.setText(partnames.get(i) + " t=" + partition.getParts().get(i).getSize()); //$NON-NLS-1$
812
				}
813
				catch (CqiClientException e1) {
814
				Log.printStackTrace(e1);
815
				return;
816
				}
817
				partColumn.setToolTipText(partnames.get(i));
818
				partColumn.setWidth(100);
819
				partColumn.addSelectionListener(new SelectionListener() {
820
					
821
					@Override
822
					public void widgetSelected(SelectionEvent e) {
823
						if (viewer.getTable().getSortColumn() != partColumn) {
824
							viewer.getTable().setSortColumn(partColumn);
825
							viewer.getTable().setSortDirection(SWT.UP);
826
							queryindex.sortLines(SortMode.FREQUNIT, false);
797
					for (int i = 0; i < partnames.size(); i++) {
798
						final TableColumn partColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
799
						try {
800
							partColumn.setText(partnames.get(i) + " t=" + partition.getParts().get(i).getSize()); //$NON-NLS-1$
827 801
						}
828
						else {
829
							if (viewer.getTable().getSortDirection() == SWT.UP) {
830
								viewer.getTable().setSortDirection(SWT.DOWN);
831
								queryindex.sortLines(SortMode.FREQUNIT, true);
832
							}
833
							else {
834
								viewer.getTable().setSortDirection(SWT.UP);
835
								queryindex.sortLines(SortMode.FREQUNIT, false);
836
							}
802
						catch (CqiClientException e1) {
803
							Log.printStackTrace(e1);
804
							return;
837 805
						}
838
						fillDisplayArea(topLine, bottomLine);
806
						partColumn.setToolTipText(partnames.get(i));
807
						partColumn.setWidth(100);
808
						partColumn.addSelectionListener(new SelectionListener() {
809
							
810
							@Override
811
							public void widgetSelected(SelectionEvent e) {
812
								if (viewer.getTable().getSortColumn() != partColumn) {
813
									viewer.getTable().setSortColumn(partColumn);
814
									viewer.getTable().setSortDirection(SWT.UP);
815
									queryindex.sortLines(SortMode.FREQUNIT, false);
816
								}
817
								else {
818
									if (viewer.getTable().getSortDirection() == SWT.UP) {
819
										viewer.getTable().setSortDirection(SWT.DOWN);
820
										queryindex.sortLines(SortMode.FREQUNIT, true);
821
									}
822
									else {
823
										viewer.getTable().setSortDirection(SWT.UP);
824
										queryindex.sortLines(SortMode.FREQUNIT, false);
825
									}
826
								}
827
								fillDisplayArea(topLine, bottomLine);
828
							}
829
							
830
							@Override
831
							public void widgetDefaultSelected(SelectionEvent e) {}
832
						});
839 833
					}
840
					
841
					@Override
842
					public void widgetDefaultSelected(SelectionEvent e) {}
843
				});
844 834
				}
845
				}
835
			}
846 836
		}
847 837
		separatorColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
848 838
		separatorColumn.setText(""); //$NON-NLS-1$
......
856 846
	/**
857 847
	 * Gets the pointed column.
858 848
	 * 
859
	 * @param mouseposition
860
	 *            the mouseposition
849
	 * @param mouseposition the mouseposition
850
	 * 
861 851
	 * @return the pointed column
862 852
	 */
863 853
	public int getPointedColumn(Point mouseposition) {
......
880 870
	/**
881 871
	 * Creates the context menu.
882 872
	 * 
883
	 * @param tableViewer
884
	 *            the table viewer
873
	 * @param tableViewer the table viewer
885 874
	 */
886 875
	private void createContextMenu(TableViewer tableViewer) {
876
		
887 877
		MenuManager menuManager = new MenuManager();
888 878
		Menu menu = menuManager.createContextMenu(tableViewer.getTable());
889 879
		
......
898 888
	 * Initialize fields.
899 889
	 */
900 890
	public void initializeFields() {
891
		
901 892
		if (this.queryindex != null) {
902 893
			
903 894
			if (queryindex.getPartition() != null)
......
930 921
	/**
931 922
	 * Fill display area.
932 923
	 * 
933
	 * @param from
934
	 *            the from
935
	 * @param to
936
	 *            the to
924
	 * @param from the from
925
	 * @param to the to
937 926
	 */
938 927
	public void fillDisplayArea(int from, int to) {
939 928
		// System.out.println("call fill from "+from+" to "+to);
......
943 932
		if (queryindex.getV() > 0) {
944 933
			lines = queryindex.getLines(from, to);
945 934
		}
946
		else
935
		else {
947 936
			lines = new ArrayList<>();
948
		
937
		}
949 938
		navigationArea.setInfoLineText("" + (from + 1), //$NON-NLS-1$
950 939
				"-" + (to) + " / " + queryindex.getV()); //$NON-NLS-1$ //$NON-NLS-2$
951 940
		navigationArea.setPreviousEnabled(from > 0);
......
978 967
	 */
979 968
	@Override
980 969
	public String getTitleToolTip() {
970
		
981 971
		if (queryindex != null) {
982
			String str = Messages.QueryIndexEditor_11;
983 972
			
973
			String str = Messages.QueryIndexEditor_11;
984 974
			return str;
985 975
		}
986 976
		return ""; //$NON-NLS-1$
......
993 983
	 */
994 984
	@Override
995 985
	public void _setFocus() {
986
		
996 987
		this.queryWidget.setFocus();
997 988
		StatusLine.setMessage(IndexUIMessages.openingTheIndexResults);
998 989
	}
......
1003 994
	 * @return the corpus
1004 995
	 */
1005 996
	public CQPCorpus getCorpus() {
997
		
1006 998
		return this.corpus;
1007 999
	}
1008 1000
	
......
1012 1004
	 * @return the partition
1013 1005
	 */
1014 1006
	public Partition getPartition() {
1007
		
1015 1008
		return this.partition;
1016 1009
	}
1017 1010
	
1018 1011
	/**
1019 1012
	 * Sets the focus.
1020 1013
	 * 
1021
	 * @param query
1022
	 *            the new focus
1014
	 * @param query the new focus
1023 1015
	 */
1024 1016
	public void setFocus(String query) {
1017
		
1025 1018
		this.queryWidget.setText(query);
1026 1019
	}
1027 1020
	
......
1031 1024
	 * @return the index
1032 1025
	 */
1033 1026
	public Object getIndex() {
1027
		
1034 1028
		return this.queryindex;
1035 1029
	}
1036 1030
}
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/commands/ComputeQueryIndex.java (revision 3953)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
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.queryindex.rcp.commands;
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.jface.viewers.IStructuredSelection;
34
import org.eclipse.ui.IEditorPart;
35
import org.eclipse.ui.IWorkbenchPage;
36
import org.eclipse.ui.handlers.HandlerUtil;
37
import org.txm.queryindex.core.functions.QueryIndex;
38
import org.txm.queryindex.rcp.editors.QueryIndexEditor;
39
import org.txm.index.rcp.messages.IndexUIMessages;
40
import org.txm.rcp.StatusLine;
41
import org.txm.rcp.TXMWindows;
42
import org.txm.rcp.editors.TXMResultEditorInput;
43
import org.txm.rcp.handlers.BaseAbstractHandler;
44
import org.txm.searchengine.cqp.corpus.CQPCorpus;
45
import org.txm.searchengine.cqp.corpus.Partition;
46
import org.txm.utils.logger.Log;
47

  
48
/**
49
 * Open the Query Index Editor
50
 * 
51
 * @author mdecorde.
52
 */
53
public class ComputeQueryIndex extends BaseAbstractHandler {
54

  
55
	/** The ID. */
56
	public static String ID = "org.txm.rcp.commands.function.ComputeQueryIndex"; //$NON-NLS-1$
57

  
58
	/** The selection. */
59
	private IStructuredSelection selection;
60
	
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
63
	 */
64
	@Override
65
	public Object execute(ExecutionEvent event) throws ExecutionException {
66
		Log.info("Compute QueryIndex: start");
67
		selection = this.getCorporaViewSelection(event);
68

  
69
		Object s = selection.getFirstElement();
70
		if (s instanceof CQPCorpus) {
71
			final CQPCorpus corpus = (CQPCorpus) s;
72
			openEditor(corpus);
73
		} else if (s instanceof Partition) {
74
			final Partition partition = (Partition) s;
75
			openEditor(partition);
76
		} else {
77
			Log.severe("Can not compute QueryIndex with: "+s);
78
		}
79

  
80
		return null;
81
	}
82
	
83
	public static void openEditor(CQPCorpus corpus) {
84
		IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage();
85
		TXMResultEditorInput<QueryIndex> editorInput = new TXMResultEditorInput<QueryIndex>(new QueryIndex(corpus));
86
		try {
87
			StatusLine.setMessage(IndexUIMessages.openingIndexResults);
88
			IEditorPart editor =  page.openEditor(editorInput,QueryIndexEditor.ID);
89
			if (editor instanceof QueryIndexEditor) {
90
				QueryIndexEditor voceditor = (QueryIndexEditor)editor;
91
				voceditor.initializeFields();
92
			}
93
		} catch (Exception e) {
94
			Log.printStackTrace(e);
95
		}
96
	}
97
	
98
	public static void openEditor(Partition partition) {
99
		IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage();
100
		TXMResultEditorInput<QueryIndex> editorInput = new TXMResultEditorInput<QueryIndex>(new QueryIndex(partition));
101
		try {
102
			StatusLine.setMessage(IndexUIMessages.openingIndexResults);
103
			QueryIndexEditor voceditor = (QueryIndexEditor) page
104
					.openEditor(editorInput, QueryIndexEditor.ID);
105
			voceditor.initializeFields();
106
		} catch (Exception e) {
107
			Log.printStackTrace(e);
108
		}
109
	}
110
}
0 111

  
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/commands/QueryIndexToLexicalTable.java (revision 3953)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
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.queryindex.rcp.commands;
29

  
30
import java.util.ArrayList;
31

  
32
import org.eclipse.core.commands.AbstractHandler;
33
import org.eclipse.core.commands.ExecutionEvent;
34
import org.eclipse.core.commands.ExecutionException;
35
import org.eclipse.jface.viewers.ArrayContentProvider;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.viewers.LabelProvider;
38
import org.eclipse.swt.widgets.Dialog;
39
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.ui.IWorkbenchWindow;
41
import org.eclipse.ui.dialogs.ListSelectionDialog;
42
import org.eclipse.ui.handlers.HandlerUtil;
43
import org.txm.lexicaltable.core.functions.LexicalTable;
44
import org.txm.lexicaltable.rcp.messages.LexicalTableUIMessages;
45
import org.txm.queryindex.core.functions.QueryIndex;
46
import org.txm.rcp.StatusLine;
47
import org.txm.rcp.messages.TXMUIMessages;
48
import org.txm.searchengine.cqp.corpus.Partition;
49
import org.txm.searchengine.cqp.corpus.Property;
50
import org.txm.utils.logger.Log;
51
// TODO: Auto-generated Javadoc
52
/**
53
 * The Class IndexToLexicalTable.
54
 */
55
public class QueryIndexToLexicalTable extends AbstractHandler {
56

  
57
	/** The window. */
58
	private IWorkbenchWindow window;
59
	
60
	/** The selection. */
61
	private IStructuredSelection selection;
62
	private static Shell shell;
63
	/* (non-Javadoc)
64
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
65
	 */
66
	@Override
67
	public Object execute(ExecutionEvent event) throws ExecutionException {
68
		// TODO Auto-generated method stub
69
		window = HandlerUtil.getActiveWorkbenchWindow(event);
70
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
71
		shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
72
		.getShell();
73
		return null;
74
	}
75

  
76
	/**
77
	 * Builds the lexical table.
78
	 *
79
	 * @param qindex the voc
80
	 * @param from the from
81
	 * @param to the to
82
	 * @return true, if successful
83
	 */
84
	public boolean buildLexicalTable(QueryIndex qindex, int from, int to) {
85
		LexicalTable table;
86
		Partition partition;
87
		Property property;
88

  
89
		if (!qindex.isComputedWithPartition()) {
90
			
91
			System.out.println(TXMUIMessages.cannotCreateALexicalTableFromAnIndexCreatedWithACorpusMoreThanOneColumnIsNeeded);
92
			StatusLine.setMessage(TXMUIMessages.cannotCreateALexicalTableFromAnIndexCreatedWithACorpusMoreThanOneColumnIsNeeded);
93
			return false;
94
		}
95

  
96
		Log.info(LexicalTableUIMessages.openingMargeConfigurationDialog);
97
		ArrayList<String> choices = new ArrayList<String>();
98
		choices.add(LexicalTableUIMessages.useAllOccurrences);
99
		choices.add(LexicalTableUIMessages.userIndexOccurrences);
100
		ListSelectionDialog dialog = new ListSelectionDialog(shell, 
101
				choices, new ArrayContentProvider(), new LabelProvider(), 
102
				LexicalTableUIMessages.selectWhichMarginsYouWantToUse);
103
		
104
		int ret = dialog.open();
105
		//System.out.println("ret= "+ret);
106
		if (ret != dialog.OK) {
107
			return false;
108
		}
109
		
110
		// TODO: fix line 119
111
//		try {
112
//			table = LexicalTableImpl.createLexicalTableImpl(voc, QuantitativeDataStructureImpl
113
//					.createSymbole(LexicalTableImpl.class));
114
//			partition = voc.getPartition();
115
//			property = voc.getCorpus().getProperties().get(0);
116
//		} catch (Exception e) {
117
//			org.txm.utils.logger.Log.printStackTrace(e);
118
//			return false;
119
//		}
120
//
121
//		try {
122
//			IWorkbenchWindow window = PlatformUI.getWorkbench()
123
//					.getActiveWorkbenchWindow();
124
//			IWorkbenchPage page = window.getActivePage();
125
//			LexicalTableEditorInput editorInput = new LexicalTableEditorInput(
126
//					table, partition, property);
127
//			StatusLine.setMessage(RCPMessages.ComputeLexicalTable_10);
128
//			page
129
//					.openEditor(editorInput,
130
//							"org.txm.rcp.editors.lexicaltable.LexicalTableEditor"); //$NON-NLS-1$
131
//		} catch (PartInitException e) {
132
//			org.txm.utils.logger.Log.printStackTrace(e);
133
//		} 
134

  
135
		return false;
136
	}
137

  
138
}
0 139

  
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/QueryIndex.java (revision 3953)
20 20
import org.eclipse.jface.resource.ImageDescriptor;
21 21
import org.eclipse.ui.model.IWorkbenchAdapter;
22 22
import org.txm.core.messages.TXMCoreMessages;
23
import org.txm.core.results.TXMParameters;
24 23
import org.txm.core.results.TXMResult;
25 24
import org.txm.index.core.functions.LineComparator.SortMode;
26 25
import org.txm.index.core.messages.IndexCoreMessages;
......
45 44
	LinkedHashMap<String, QueryIndexLine> lines = new LinkedHashMap<>();
46 45
	
47 46
	List<String> partnames;
48
	// private int FilterFmin;
49
	// private int FilterFmax;
50
	// private int FilterVmax;
47

  
51 48
	
52
	// public int getFilterFmin() {
53
	// return FilterFmin;
54
	// }
55
	//
56
	// public int getFilterFmax() {
57
	// return FilterFmax;
58
	// }
59
	//
60
	// public int getFilterVmax() {
61
	// return FilterVmax;
62
	// }
63
	
64 49
	/** The writer. */
65 50
	private OutputStreamWriter writer;
66 51
	
67 52
	public int getT() {
53
		
68 54
		int t = 0;
69 55
		for (QueryIndexLine line : lines.values()) {
70 56
			t += line.getFrequency();
......
73 59
	}
74 60
	
75 61
	public int getFmin() {
62
		
76 63
		int t = Integer.MAX_VALUE;
77 64
		for (QueryIndexLine line : lines.values()) {
78 65
			int f = line.getFrequency();
......
82 69
	}
83 70
	
84 71
	public int getFmax() {
72
		
85 73
		int t = 0;
86 74
		for (QueryIndexLine line : lines.values()) {
87 75
			int f = line.getFrequency();
......
95 83
	}
96 84
	
97 85
	public QueryIndex(CQPCorpus corpus) {
86
		
98 87
		super(corpus);
99 88
		this.corpus = corpus;
100 89
		partnames = Arrays.asList(corpus.getName());
......
103 92
	
104 93
	@Override
105 94
	public String getName() {
106
		if (partition != null)
95
		
96
		if (partition != null) {
107 97
			return partition.getName();
98
		}
108 99
		return corpus.getName();
109 100
	}
110 101
	
111 102
	public QueryIndex(Partition partition) {
103
		
112 104
		super(partition);
113 105
		this.corpus = partition.getParent();
114 106
		this.partition = partition;
......
117 109
	}
118 110
	
119 111
	public CQPCorpus getCorpus() {
112
		
120 113
		return corpus;
121 114
	}
122 115
	
123 116
	public Partition getPartition() {
117
		
124 118
		return partition;
125 119
	}
126 120
	
127 121
	public Collection<QueryIndexLine> getLines() {
122
		
128 123
		return lines.values();
129 124
	}
130 125
	
......
198 193
		lines = sortedMap;
199 194
	}
200 195
	
201
	// public void cut(int vmax) {
202
	// System.out.println("TODO cut tmax="+vmax );
203
	// this.FilterVmax = vmax;
204
	// }
205
	
206 196
	public boolean isComputedWithPartition() {
197
		
207 198
		return partition != null;
208 199
	}
209 200
	
210 201
	public void addLinesFromFile(File propFile) throws CqiClientException, IOException {
211
		BufferedReader reader = new BufferedReader(new InputStreamReader(
212
				new FileInputStream(propFile), "UTF-8")); //$NON-NLS-1$
213 202
		
203
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(propFile), "UTF-8")); //$NON-NLS-1$
204
		
214 205
		String line = reader.readLine();
215 206
		while (line != null) {
216 207
			String[] split = line.split("=", 2); //$NON-NLS-1$
......
240 231
	 */
241 232
	@Override
242 233
	public boolean _toTxt(File outfile, String encoding, String colseparator, String txtseparator) {
234
		
243 235
		try {
244 236
			toTxt(outfile, 0, lines.size(), encoding, colseparator, txtseparator);
245 237
		}
......
264 256
	 */
265 257
	public void toTxt(File outfile, int from, int to, String encoding, String colseparator, String txtseparator)
266 258
			throws CqiClientException, IOException {
259
		
267 260
		// NK: writer declared as class attribute to perform a clean if the operation is interrupted
268 261
		this.writer = new OutputStreamWriter(new FileOutputStream(outfile),
269 262
				encoding);
......
291 284
	}
292 285
	
293 286
	public List<String> getPartnames() {
287
		
294 288
		return partnames;
295 289
	}
296 290
	
297 291
	public QueryIndexLine addLine(String name, CQLQuery query) throws CqiClientException {
292
		
298 293
		if (lines.containsKey(name)) return null;
299 294
		QueryResult[] qresults;
300 295
		if (partition != null) {
......
317 312
	}
318 313
	
319 314
	public LexicalTable toLexicalTable() {
315
		
320 316
		if (partition == null) return null;
321 317
		
322 318
		int npart = partition.getPartsCount();
......
354 350
	}
355 351
	
356 352
	public boolean removeLine(String name) {
353
		
357 354
		if (lines.containsKey(name)) {
358 355
			lines.remove(name);
359 356
			return true;
......
364 361
	}
365 362
	
366 363
	public boolean hasLine(String name) {
364
		
367 365
		return lines.containsKey(name);
368 366
	}
369 367
	
370 368
	public ArrayList<QueryIndexLine> getLines(int from, int to) {
369
		
371 370
		if (lines.size() == 0) return new ArrayList<>();
372 371
		
373 372
		if (from < 0) from = 0;
......
388 387
	
389 388
	@Override
390 389
	public void clean() {
390
		
391 391
		try {
392 392
			this.writer.flush();
393 393
			this.writer.close();
......
399 399
	
400 400
	@Override
401 401
	public Object getAdapter(Class adapterType) {
402
		
402 403
		if (adapterType == IWorkbenchAdapter.class)
403 404
			return queryindexAdapter;
404 405
		return null;
......
437 438
	
438 439
	@Override
439 440
	public String getSimpleName() {
441
		
440 442
		return ""; //$NON-NLS-1$
441 443
	}
442 444
	
443 445
	@Override
444 446
	public String getDetails() {
447
		
445 448
		return ""; //$NON-NLS-1$
446 449
	}
447 450
	
448 451
	@Override
449 452
	public boolean canCompute() {
453
		
450 454
		return corpus != null || partition != null;
451 455
	}
452 456
	
......
473 477
	
474 478
	@Override
475 479
	public String getResultType() {
476
		return "Query index"; //$NON-NLS-1$
480
		
481
		return "Query Index"; //$NON-NLS-1$
477 482
	}
478 483
	
479 484
}

Formats disponibles : Unified diff