Revision 1003

tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/GeneralWizardPage.java (revision 1003)
1
package org.txm.rcp.corpuswizard;
2

  
3
import org.eclipse.core.resources.ResourcesPlugin;
4
import org.eclipse.jface.wizard.WizardPage;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.events.KeyEvent;
7
import org.eclipse.swt.events.KeyListener;
8
import org.eclipse.swt.events.SelectionEvent;
9
import org.eclipse.swt.events.SelectionListener;
10
import org.eclipse.swt.layout.GridData;
11
import org.eclipse.swt.layout.GridLayout;
12
import org.eclipse.swt.widgets.Button;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.DirectoryDialog;
15
import org.eclipse.swt.widgets.Label;
16
import org.eclipse.swt.widgets.Text;
17

  
18
public class GeneralWizardPage extends WizardPage {
19
    private Text corpusName;
20
    private Text sourceDirectory;
21
    private Text descriptionText;
22
    
23
    private Composite container;
24

  
25
    public GeneralWizardPage() {
26
        super("General Page");
27
        setTitle("General Page");
28
        setDescription("All general corpus parameters");
29
    }
30

  
31
    @Override
32
    public void createControl(Composite parent) {
33
        container = new Composite(parent, SWT.NONE);
34
        GridLayout layout = new GridLayout();
35
        container.setLayout(layout);
36
        layout.numColumns = 3;
37
        
38
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
39
        
40
        Label label2 = new Label(container, SWT.NONE);
41
        label2.setText("Source directory");
42
        
43
        sourceDirectory = new Text(container, SWT.BORDER | SWT.SINGLE);
44
        sourceDirectory.setText("");
45
        sourceDirectory.setToolTipText("The corpus source directory");
46
        sourceDirectory.setLayoutData(gd);
47
        
48
        Button button = new Button(container, SWT.PUSH);
49
        button.setText("...");
50
        button.setToolTipText("click to select the corpus source directory");
51
        button.addSelectionListener(new SelectionListener() {
52
			
53
			@Override
54
			public void widgetSelected(SelectionEvent e) {
55
				DirectoryDialog dialog = new DirectoryDialog(e.display.getActiveShell());
56
				dialog.setText("Source directory");
57
				if (getSourcePath().length() > 0) {
58
					dialog.setFilterPath(getSourcePath());
59
				}
60
				String path = dialog.open();
61
				if (path != null) {
62
					sourceDirectory.setText(path);
63
					setPageComplete(isCompleted());
64
				}
65
			}
66
			
67
			@Override
68
			public void widgetDefaultSelected(SelectionEvent e) { }
69
		});
70
        Label label1 = new Label(container, SWT.NONE);
71
        label1.setText("Name");
72

  
73
        corpusName = new Text(container, SWT.BORDER | SWT.SINGLE);
74
        corpusName.setText("");
75
        corpusName.setToolTipText("The corpus name");
76
        corpusName.addKeyListener(new KeyListener() {
77
			@Override
78
			public void keyReleased(KeyEvent e) {
79
				setPageComplete(isCompleted());
80
			}
81
			
82
			@Override
83
			public void keyPressed(KeyEvent e) { }
84
		});
85
        
86
        corpusName.setLayoutData(gd);
87
        new Label(container, SWT.NONE);
88
        
89
        label1 = new Label(container, SWT.NONE);
90
        label1.setText("Description");
91
        
92
        descriptionText = new Text(container, SWT.BORDER | SWT.MULTI);
93
        descriptionText.setText("\n\n\n\n\n");
94
        descriptionText.setText("");
95
        descriptionText.setToolTipText("The corpus description in HTML format");
96
        gd = new GridData(GridData.FILL_HORIZONTAL);
97
        gd.grabExcessVerticalSpace = true;
98
        descriptionText.setLayoutData(gd);
99
        
100
        // required to avoid an error in the system
101
        setControl(container);
102
        setPageComplete(false);
103

  
104
    }
105

  
106
    protected boolean isCompleted() {
107
		return getCorpusName().length() > 0 && getSourcePath().length() > 0 && !ResourcesPlugin.getWorkspace().getRoot().getProject(getCorpusName()).exists();
108
	}
109

  
110
	public String getCorpusName() {
111
        return corpusName.getText();
112
    }
113
    
114
    public String getSourcePath() {
115
        return sourceDirectory.getText();
116
    }
117
}
0 118

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/ImportWizard.java (revision 1003)
1
package org.txm.rcp.corpuswizard;
2

  
3
import org.eclipse.core.resources.IFolder;
4
import org.eclipse.core.resources.IProject;
5
import org.eclipse.core.resources.IProjectDescription;
6
import org.eclipse.core.resources.IProjectNatureDescriptor;
7
import org.eclipse.core.resources.IResource;
8
import org.eclipse.core.resources.IWorkspace;
9
import org.eclipse.core.resources.ResourcesPlugin;
10
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.IPath;
12
import org.eclipse.core.runtime.Path;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.ui.INewWizard;
16
import org.eclipse.ui.IWorkbench;
17
import org.txm.stat.utils.ConsoleProgressBar;
18

  
19
public class ImportWizard extends Wizard implements INewWizard {
20

  
21
	private GeneralWizardPage page1 = new GeneralWizardPage();
22
	
23
	public ImportWizard() {
24
		// TODO Auto-generated constructor stub
25
	}
26

  
27
	@Override
28
	public void init(IWorkbench workbench, IStructuredSelection selection) {
29
		// TODO Auto-generated method stub
30

  
31
	}
32

  
33
	@Override
34
	public boolean performFinish() {
35
		if (page1.isCompleted()) {
36
			IWorkspace workspace = ResourcesPlugin.getWorkspace();
37
			
38
			IProject newProject = workspace.getRoot().getProject(page1.getCorpusName());
39
			if (!newProject.exists()) {
40
	            IProjectDescription desc = workspace.newProjectDescription(newProject.getName());
41
	            desc.setComment("TXT corpus");
42
	            String[] natures = {"org.txm.core.project.corpus"};
43
	            desc.setNatureIds(natures);
44
	            try {
45
	                newProject.create(desc, null);
46
	                
47
	                if (!newProject.isOpen()) {
48
	                    newProject.open(null);
49
	                    IFolder srcFolder = newProject.getFolder("src");
50
		                ConsoleProgressBar cpb = new ConsoleProgressBar(2);
51
		                IPath path = new Path(page1.getSourcePath());
52
		                srcFolder.createLink(path, IResource.ALLOW_MISSING_LOCAL, cpb);
53
		                
54
		                cpb.done();
55
	                }
56
	                
57
	            } catch (CoreException e) {
58
	                e.printStackTrace();
59
	            }
60
	        }
61
		}
62
		return true;
63
	}
64

  
65
	@Override
66
	public void addPages() {
67
	  addPage(page1);
68
	}
69
}
0 70

  
tmp/org.txm.rcp/plugin.xml (revision 1003)
2954 2954
                  </count>
2955 2955
               </with>
2956 2956
            </definition>
2957
            <definition
2958
                  id="IscorpusProject">
2959
               <adapt
2960
                     type="org.eclipse.core.resources.IProject">
2961
                  <test
2962
                        property="org.eclipse.core.resources.projectNature"
2963
                        value="org.txm.core.project.corpus">
2964
                  </test>
2965
               </adapt>
2966
            </definition>
2957 2967
   </extension>
2958 2968
  
2959 2969
   <extension
......
3074 3084
            name="%context.name.0">
3075 3085
      </context>
3076 3086
   </extension>
3087
   <extension
3088
         point="org.eclipse.ui.newWizards">
3089
      <category
3090
            id="org.txm.rcp.corpus"
3091
            name="Corpus">
3092
      </category>
3093
      <primaryWizard
3094
            id="org.txm.rcp.corpuswizard.TxtWizard">
3095
      </primaryWizard>
3096
      <primaryWizard
3097
            id="org.txm.rcp.corpuswizard.XMLXTZWizard">
3098
      </primaryWizard>
3099
      <primaryWizard
3100
            id="org.txm.rcp.corpuswizard.FactivaWizard">
3101
      </primaryWizard>
3102
      <wizard
3103
            category="org.txm.rcp.corpus"
3104
            class="org.txm.rcp.corpuswizard.ImportWizard"
3105
            descriptionImage="icons/wizard/txt.png"
3106
            finalPerspective="org.txm.rcp.perspective.TXMPerspective"
3107
            icon="icons/objects/file.png"
3108
            id="org.txm.rcp.corpuswizard.TxtWizard"
3109
            name="TXT+CSV"
3110
            preferredPerspectives="org.txm.rcp.perspective.TXMPerspective"
3111
            project="true">
3112
      </wizard>
3113
      <wizard
3114
            category="org.txm.rcp.corpus"
3115
            class="org.txm.rcp.corpuswizard.ImportWizard"
3116
            descriptionImage="icons/wizard/factiva.png"
3117
            finalPerspective="org.txm.rcp.perspective.TXMPerspective"
3118
            icon="icons/objects/xml.png"
3119
            id="org.txm.rcp.corpuswizard.FactivaWizard"
3120
            name="Factiva"
3121
            preferredPerspectives="org.txm.rcp.perspective.TXMPerspective"
3122
            project="true">
3123
      </wizard>
3124
      <wizard
3125
            category="org.txm.rcp.corpus"
3126
            class="org.txm.rcp.corpuswizard.ImportWizard"
3127
            descriptionImage="icons/wizard/xtz.png"
3128
            finalPerspective="org.txm.rcp.perspective.TXMPerspective"
3129
            icon="icons/objects/xml.png"
3130
            id="org.txm.rcp.corpuswizard.XMLXTZWizard"
3131
            name="XML-XTZ + CSV"
3132
            preferredPerspectives="org.txm.rcp.perspective.TXMPerspective"
3133
            project="true">
3134
      </wizard>
3135
   </extension>
3136
   <extension
3137
         point="org.eclipse.ui.ide.projectNatureImages">
3138
      <image
3139
            icon="icons/objects/books.png"
3140
            id="org.txm.rcp.image1"
3141
            natureId="org.txm.core.project.corpus">
3142
      </image>
3143
   </extension>
3077 3144
</plugin>
tmp/org.txm.core/src/java/org/txm/core/CorpusProject.java (revision 1003)
1
package org.txm.core;
2

  
3
import org.eclipse.core.resources.IProject;
4
import org.eclipse.core.resources.IProjectNature;
5
import org.eclipse.core.runtime.CoreException;
6

  
7
public class CorpusProject implements IProjectNature {
8

  
9
	public static final String NATURE_ID = "org.txm.core.project.corpus";
10
	
11
	/**
12
	 * the eclipse project pointing to the TXM corpus project
13
	 */
14
	private IProject project;
15
	
16
	@Override
17
	public void configure() throws CoreException {
18
		// TODO Auto-generated method stub
19

  
20
	}
21

  
22
	@Override
23
	public void deconfigure() throws CoreException {
24
		// nothing to do
25
	}
26

  
27
	@Override
28
	public IProject getProject() {
29
		// TODO Auto-generated method stub
30
		return project;
31
	}
32

  
33
	@Override
34
	public void setProject(IProject project) {
35
		this.project = project;
36
	}
37
}
0 38

  
tmp/org.txm.core/plugin.xml (revision 1003)
11 11
            class="org.txm.core.preferences.TBXPreferences">
12 12
      </initializer>
13 13
   </extension>
14
   <extension
15
         id="org.txm.core.project.corpus"
16
         name="Corpus"
17
         point="org.eclipse.core.resources.natures">
18
      <runtime>
19
         <run
20
               class="org.txm.core.CorpusProject">
21
         </run>
22
      </runtime>
23
   </extension>
14 24

  
15 25
</plugin>
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Corpus.java (revision 1003)
93 93

  
94 94
	protected int[] textLimits;
95 95

  
96
	/** All the subcorpora that have been created from this corpus. */
97
	protected List<Subcorpus> subcorpora;
98

  
99
	/** All partitions that have been created from this corpus. */
100
	protected List<Partition> partitions;
101

  
102 96
	/** All private infos of the corpus. */
103 97
	private String charset = "latin1"; //$NON-NLS-1$
104 98

  
......
147 141
		this.cqpId = cqpId;
148 142
		
149 143
		// FIXME: at this moment, store the CQPID as UUIDD for persistence tests
150
		//this.uniqueID = this.cqpId;
151

  
152
		subcorpora = new ArrayList<Subcorpus>();
153
		partitions = new ArrayList<Partition>();
144
		this.uniqueID = this.cqpId;
154 145
	}
155

  
156 146
	
157
	
158 147
	/**
159 148
	 * Creates a partition using a list of CQP queries.
160 149
	 *
......
183 172
	 */
184 173
	public Partition createPartition(String name, List<String> queries, boolean registered) throws CqiClientException {
185 174
		Partition partition = new Partition(this, name, queries);
186
		partitions.add(partition);
187 175
		if (!registered) {
188 176
			partition.registerToParent();
189 177
		}
......
222 210
			List<String> partnames, boolean registered)
223 211
					throws CqiClientException {
224 212
		Partition partition = new Partition(this, name, queries, partnames);
225
		partitions.add(partition);
226 213
		if (!registered)
227 214
			partition.registerToParent();
228 215
		return partition;
......
319 306
			StructuralUnitProperty property, boolean registered)
320 307
					throws CqiClientException {
321 308
		Partition partition = new Partition(this, structure, property);
322
		partitions.add(partition);
323 309
		if (!registered)
324 310
			partition.registerToParent();
325 311
		return partition;
......
368 354
			StructuralUnitProperty property, List<String> values,
369 355
			boolean registered) throws CqiClientException {
370 356
		Partition partition = new Partition(this, structure, property, values);
371
		partitions.add(partition);
372 357
		if (!registered)
373 358
			partition.registerToParent();
374 359
		return partition;
......
394 379
					query.getQueryString());
395 380
			subcorpus = new Subcorpus(subcorpusCqpId, subcorpusName, this, query);
396 381
			subcorpus.setSelfElement(elem);
397
			subcorpora.add(subcorpus);
398 382
		} catch (Exception e) {
399 383
			throw new CqiClientException(e);
400 384
		}
......
444 428
					query.getQueryString());
445 429
			//System.out.println("SUBCORPUS: "+subcorpusCqpId+" q="+query.getQueryString());
446 430
			subcorpus = new Subcorpus(subcorpusCqpId, subcorpusName, this, query);
447
			subcorpora.add(subcorpus);
448 431
		} catch (Exception e) {
449 432
			throw new CqiClientException(e);
450 433
		}
......
458 441

  
459 442
	public Subcorpus createSubcorpus(String name, QueryResult queryResult) throws InvalidCqpIdException {
460 443
		Subcorpus sub = new Subcorpus(queryResult.getCqpId(), name, this, null);
461
		subcorpora.add(sub);
462 444
		return sub;
463 445
	}
464 446

  
465 447
	public Subcorpus createSubcorpus(String name, String cqpid) throws InvalidCqpIdException {
466 448
		Subcorpus sub = new Subcorpus(cqpid, name, this, null);
467
		subcorpora.add(sub);
468 449
		return sub;
469 450
	}
470 451
	
......
557 538
	 *             the cqi client exception
558 539
	 */
559 540
	public void dropAllPartitions() throws CqiClientException {
560
		List<Partition> _partitions = new ArrayList<Partition>();
561
		_partitions.addAll(partitions);
541
		List<Partition> _partitions = (List<Partition>) getChildren(Partition.class);
562 542
		for (Partition partition : _partitions) {
563 543
			this.dropPartition(partition);
564 544
		}
......
573 553
	 */
574 554
	public void dropAllSubcorpora() throws CqiClientException {
575 555
		//System.out.println("!! drop all subcorpora: "+subcorpora.size());
556
		List<Subcorpus> subcorpora = getSubcorpora();
576 557
		while(subcorpora.size() > 0) {
577 558
			this.dropSubcorpus(subcorpora.get(0));
578 559
		}
......
595 576
			} catch (Exception e) {
596 577
				throw new CqiClientException(e);
597 578
			}
598
		partitions.remove(partition);
599 579
	}
600 580

  
601 581
	/**
......
635 615
		} catch (Exception e) {
636 616
			throw new CqiClientException(e);
637 617
		}
638
		return subcorpora.remove(subcorpus);
618
		return true;
639 619
	}
640 620

  
641 621
	/**
......
657 637
	public abstract Base getBase();
658 638

  
659 639
	/**
660
	 * Get the charset using CQP registry.
640
	 * Get the charset set in the CQP registry file.
661 641
	 *
662 642
	 * @return the charset
663 643
	 */
......
821 801
	 * @return the partitions
822 802
	 */
823 803
	public Partition getPartition(String name) {
804
		List<Partition> partitions = (List<Partition>) getChildren(Partition.class);
824 805
		for (Partition p : partitions)
825 806
			if (p.getName().equals(name))
826 807
				return p;
......
833 814
	 * @return the partitions
834 815
	 */
835 816
	public List<Partition> getPartitions() {
836
		return partitions;
817
		return (List<Partition>) getChildren(Partition.class);
837 818
	}
838 819

  
839 820
	/**
......
859 840
	 */
860 841
	public abstract WordProperty getProperty(String name) throws CqiClientException;
861 842

  
862
	
863
	//FIXME: to remove when proved, should not be useful anymore in new TXMResult hierarchy
864
//	/**
865
//	 * Gets the results of textometric computation stored in the corpus.
866
//	 * 
867
//	 * @return the results
868
//	 */
869
//	@Override
870
//	public ArrayList<ITXMResult> getResults() {
871
//		ArrayList<ITXMResult> allResults = new ArrayList<ITXMResult>();
872
//		allResults.addAll(this.children);
873
//		allResults.addAll(this.lexicons.values());
874
//		return allResults;
875
//	}
876

  
877 843
	/**
878 844
	 * Gets the CQP size of the corpus.
879 845
	 *
......
942 908
	 * @return the subcorpora
943 909
	 */
944 910
	public List<Subcorpus> getSubcorpora() {
945
		return subcorpora;
911
		return (List<Subcorpus>) getChildren(Subcorpus.class);
946 912
	}
947 913

  
948 914
	/**
......
951 917
	 * @param name the name
952 918
	 * @return the subcorpus by name
953 919
	 */
954
	public Corpus getSubcorpusByName(String name)
955
	{
920
	public Corpus getSubcorpusByName(String name) {
921
		List<Subcorpus> subcorpora = getSubcorpora();
956 922
		for (Corpus corpus : subcorpora) {
957 923
			if (corpus.getName().equals(name))
958 924
				return corpus;
......
1000 966
	}
1001 967

  
1002 968
	/* (non-Javadoc)
1003
	 * @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject)
1004
	 */
1005
	@Override
1006
	public boolean hasChildren(TxmObject children) {
1007
		return this.subcorpora.size() > 0;
1008
	}
1009
	/* (non-Javadoc)
1010 969
	 * @see org.txm.objects.TxmObject#load()
1011 970
	 */
1012 971
	@Override
......
1136 1095
					System.out.println("Corpus.removeChildren: dropSubcorpus returned false.");
1137 1096
					return null;
1138 1097
				}
1098
				super.removeChildren(children);
1139 1099
				return children;
1140 1100
			} catch (CqiClientException e) {
1141 1101
				return null;
......
1145 1105
					children.getSelfElement().getParentNode() == getSelfElement()) {
1146 1106
				preBuildElement.removeChild(children.getSelfElement());
1147 1107
			}
1148
			partitions.remove(children);
1149 1108
			try {
1150 1109
				dropPartition((Partition) children);
1110
				super.removeChildren(children);
1151 1111
				return children;
1152 1112
			} catch (CqiClientException e) {
1153 1113
				return null;
......
1157 1117
		return null;
1158 1118
	}
1159 1119

  
1160
//	/**
1161
//	 * Removes a result stored in this corpus.
1162
//	 *
1163
//	 * @param result the result
1164
//	 * @return true, if successful
1165
//	 */
1166
//	public Object removeResult(int idx) {
1167
//		return results.remove(idx);
1168
//	}
1169

  
1170
//	/**
1171
//	 * Removes a result stored in thsi corpus.
1172
//	 *
1173
//	 * @param result the result
1174
//	 * @return true, if successful
1175
//	 */
1176
//	@Override
1177
//	public boolean removeResult(Object result) {
1178
//		return results.remove(result);
1179
//	}
1180

  
1181 1120
	/* (non-Javadoc)
1182 1121
	 * @see org.txm.objects.TxmObject#save()
1183 1122
	 */
......
1288 1227
		this.language = corpusLanguage;
1289 1228
	}
1290 1229
	
1291
	
1292
//	/**
1293
//	 * Stores the result of textometric computation in this corpus.
1294
//	 * 
1295
//	 * @param result
1296
//	 *            the result
1297
//	 */
1298
//	public void storeResult(int idx, Object result) {
1299
//		results.add(idx, result);
1300
//	}
1301
//	/**
1302
//	 * Stores the result of textometric computation in this corpus.
1303
//	 * 
1304
//	 * @param result
1305
//	 *            the result
1306
//	 */
1307
//	public void storeResult(Object result) {
1308
//		results.add(result);
1309
//	}
1310
	
1311 1230
	@Override
1312 1231
	public String getCQLLimitQuery() {
1313 1232
		return cql_limit_query;
......
1419 1338
		}
1420 1339
		return output;
1421 1340
	}
1422

  
1423
	
1424 1341
}

Also available in: Unified diff