Révision 1489

tmp/org.txm.core/src/java/org/txm/objects/Project.java (revision 1489)
262 262
			//			// convert to new preferences persistence
263 263
			//		}
264 264

  
265
			if (!rcpProject.getName().equals(userName)) { // project directory and project name must stay in sync
266
				IPath destination = new Path(this.getName());
267
				if (destination.toFile().exists()) {
268
					System.out.println("Error: could not rename project since one already existing with the same new name="+this.getName());
269
					return false;
270
				}
271
				rcpProject.move(destination, true, null);
272
			}
265
			//FIXME if the corpus name change, the TXMResults node path become wrong
266
//			if (!rcpProject.getName().equals(userName)) { // project directory and project name must stay in sync
267
//				IPath destination = new Path(this.getName());
268
//				if (destination.toFile().exists()) {
269
//					System.out.println("Error: could not rename project since one already existing with the same new name="+this.getName());
270
//					return false;
271
//				}
272
//				rcpProject.move(destination, true, null);
273
//			}
273 274

  
274 275
			ImportEngines engines = Toolbox.getImportEngines();
275 276

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/GeneralWizardPage.java (revision 1489)
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.ModifyEvent;
9
import org.eclipse.swt.events.ModifyListener;
10
import org.eclipse.swt.events.SelectionEvent;
11
import org.eclipse.swt.events.SelectionListener;
12
import org.eclipse.swt.layout.GridData;
13
import org.eclipse.swt.layout.GridLayout;
14
import org.eclipse.swt.widgets.Button;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.DirectoryDialog;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.widgets.Text;
19
import org.txm.core.preferences.TXMPreferences;
20
import org.txm.rcp.preferences.RCPPreferences;
21

  
22
public class GeneralWizardPage extends WizardPage {
23
//    private Text corpusName;
24
    private Text sourceDirectory;
25
//    private Text descriptionText;
26
    
27
    private Composite container;
28

  
29
    public GeneralWizardPage() {
30
        super("Select source directory");
31
        setTitle("Sources");
32
        setDescription("The source directory contains the sources files.");
33
    }
34

  
35
    @Override
36
    public void createControl(Composite parent) {
37
        container = new Composite(parent, SWT.NONE);
38
        GridLayout layout = new GridLayout();
39
        container.setLayout(layout);
40
        layout.numColumns = 3;
41
        
42
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
43
        
44
        Label label2 = new Label(container, SWT.NONE);
45
        label2.setText("Source directory");
46
        
47
        sourceDirectory = new Text(container, SWT.BORDER | SWT.SINGLE);
48
        final String lastSourcesLocation = RCPPreferences.getInstance().getString("lastSourcesLocation");
49
        sourceDirectory.setText(lastSourcesLocation);
50
        sourceDirectory.setToolTipText("The corpus source directory");
51
        sourceDirectory.setLayoutData(gd);
52
        sourceDirectory.addModifyListener(new ModifyListener() {
53
			@Override
54
			public void modifyText(ModifyEvent e) {
55
				setPageComplete(isCompleted());
56
			}
57
		});
58
        
59
        Button button = new Button(container, SWT.PUSH);
60
        button.setText("...");
61
        button.setToolTipText("click to select the corpus source directory");
62
        button.addSelectionListener(new SelectionListener() {
63
			
64
			@Override
65
			public void widgetSelected(SelectionEvent e) {
66
				DirectoryDialog dialog = new DirectoryDialog(e.display.getActiveShell());
67
				dialog.setFilterPath(getSourcePath());
68
				dialog.setText("Source directory");
69
				if (getSourcePath().length() > 0) {
70
					dialog.setFilterPath(getSourcePath());
71
				}
72
				String path = dialog.open();
73
				if (path != null) {
74
					sourceDirectory.setText(path);
75
					RCPPreferences.getInstance().put("lastSourcesLocation", path);
76
					RCPPreferences.getInstance().flush();
77
					setPageComplete(isCompleted());
78
				}
79
			}
80
			
81
			@Override
82
			public void widgetDefaultSelected(SelectionEvent e) { }
83
		});
84
//        Label label1 = new Label(container, SWT.NONE);
85
//        label1.setText("Name");
86
//
87
//        corpusName = new Text(container, SWT.BORDER | SWT.SINGLE);
88
//        corpusName.setText("");
89
//        corpusName.setToolTipText("The corpus name");
90
//        corpusName.addKeyListener(new KeyListener() {
91
//			@Override
92
//			public void keyReleased(KeyEvent e) {
93
//				setPageComplete(isCompleted());
94
//			}
95
//			
96
//			@Override
97
//			public void keyPressed(KeyEvent e) { }
98
//		});
99
//        
100
//        corpusName.setLayoutData(gd);
101
//        new Label(container, SWT.NONE);
102
        
103
//        label1 = new Label(container, SWT.NONE);
104
//        label1.setText("Description");
105
//        
106
//        descriptionText = new Text(container, SWT.BORDER | SWT.MULTI);
107
//        descriptionText.setText("\n\n\n\n\n");
108
//        descriptionText.setText("");
109
//        descriptionText.setToolTipText("The corpus description in HTML format");
110
//        gd = new GridData(GridData.FILL_HORIZONTAL);
111
//        gd.grabExcessVerticalSpace = true;
112
//        descriptionText.setLayoutData(gd);
113
        
114
        // required to avoid an error in the system
115
        setControl(container);
116
        setPageComplete(false);
117
        
118
        setPageComplete(isCompleted());
119
    }
120

  
121
    protected boolean isCompleted() {
122
		//return getCorpusName().length() > 0 && getSourcePath().length() > 0 && !ResourcesPlugin.getWorkspace().getRoot().getProject(getCorpusName()).exists();
123
    	return getSourcePath().length() > 0;
124
	}
125

  
126
//	public String getCorpusName() {
127
//        return corpusName.getText();
128
//    }
129
    
130
    public String getSourcePath() {
131
        return sourceDirectory.getText().trim();
132
    }
133
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/ImportWizard.java (revision 1489)
1 1
package org.txm.rcp.corpuswizard;
2 2

  
3 3
import java.io.File;
4
import java.util.Date;
5 4
import java.util.Locale;
6 5

  
7
import org.eclipse.core.resources.IFolder;
8
import org.eclipse.core.resources.IProject;
9
import org.eclipse.core.resources.IProjectDescription;
10
import org.eclipse.core.resources.IProjectNatureDescriptor;
11
import org.eclipse.core.resources.IResource;
12
import org.eclipse.core.resources.IWorkspace;
13
import org.eclipse.core.resources.ResourcesPlugin;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Path;
17 6
import org.eclipse.jface.viewers.IStructuredSelection;
18 7
import org.eclipse.jface.wizard.Wizard;
8
import org.eclipse.osgi.util.NLS;
19 9
import org.eclipse.ui.INewWizard;
20 10
import org.eclipse.ui.IWorkbench;
21 11
import org.txm.Toolbox;
22
import org.txm.objects.BaseOldParameters;
23
import org.txm.objects.CorpusBuild;
24 12
import org.txm.objects.EditionDefinition;
25 13
import org.txm.objects.Project;
26
import org.txm.searchengine.cqp.corpus.MainCorpus;
27
import org.txm.stat.utils.ConsoleProgressBar;
28
import org.txm.utils.AsciiUtils;
29 14

  
30 15
public class ImportWizard extends Wizard implements INewWizard {
31 16

  
32
	private GeneralWizardPage page1 = new GeneralWizardPage();
17
	private SourceDirectoryPage page1 = new SourceDirectoryPage();
33 18
	private Project project;
34 19

  
35 20
	public ImportWizard() {
......
47 32
		if (page1.isCompleted()) {
48 33
			try {
49 34
				File path = new File(page1.getSourcePath());
35
				String name = page1.getCorpusName();//AsciiUtils.buildId(path.getName()).toUpperCase();
50 36
				
51 37
				project = null;
52 38
				
......
56 42
					if (!path.equals(psrc)) {
57 43
						continue;
58 44
					}
45
					if (!name.equals(p.getRCPProject().getName())) {
46
						continue;
47
					}
59 48
					
49
					// get the more recent one
60 50
					if (project != null && p.getComputeDate().compareTo(project.getComputeDate()) > 0) {
61 51
						project = p;
62 52
					} else {
......
64 54
					}
65 55
				}
66 56
				
67
				if (project == null) { // it's a new project
68
					System.out.println("New import corpus project.");
69
					String name = AsciiUtils.buildId(path.getName()).toUpperCase();
70
					project = new Project(Toolbox.workspace, name);
57
				if (project == null) { // it's a new project configuration
58
					project = Toolbox.workspace.getProject(name);
59
					if (project == null) {
60
						project = new Project(Toolbox.workspace, name);
61
					}
71 62
					project.setSourceDirectory(path.getAbsolutePath());
72 63
					project.setDescription(page1.getDescription());
73 64
					project.setLang(Locale.getDefault().getCountry());
65
					System.out.println(NLS.bind("The {0} corpus will be created.", project));
74 66
				} else {
75
					System.out.println("Using parameters from already imported corpus: "+project.getCorpusBuild(project.getName()));
67
					System.out.println(NLS.bind("The {0} ({1}) corpus will be replaced.", project, project.getComputeDate()));
76 68
				}
77 69
				
78 70
				//project.compute(); // create/update files
tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/SourceDirectoryPage.java (revision 1489)
1
package org.txm.rcp.corpuswizard;
2

  
3
import java.io.File;
4

  
5
import org.eclipse.core.resources.ResourcesPlugin;
6
import org.eclipse.jface.layout.GridDataFactory;
7
import org.eclipse.jface.wizard.WizardPage;
8
import org.eclipse.osgi.util.NLS;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.KeyEvent;
11
import org.eclipse.swt.events.KeyListener;
12
import org.eclipse.swt.events.ModifyEvent;
13
import org.eclipse.swt.events.ModifyListener;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.events.SelectionListener;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.DirectoryDialog;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.swt.widgets.Text;
23
import org.txm.rcp.preferences.RCPPreferences;
24
import org.txm.utils.AsciiUtils;
25

  
26
public class SourceDirectoryPage extends WizardPage {
27
	private Text corpusName;
28
	private Text sourceDirectory;
29
	//    private Text descriptionText;
30

  
31
	private Composite container;
32
	private Label newOrEdit;
33

  
34
	public SourceDirectoryPage() {
35
		super("Select source directory");
36
		setTitle("Sources");
37
		setDescription("The source directory contains the sources files.");
38
	}
39

  
40
	@Override
41
	public void createControl(Composite parent) {
42
		container = new Composite(parent, SWT.NONE);
43
		GridLayout layout = new GridLayout();
44
		container.setLayout(layout);
45
		layout.numColumns = 3;
46

  
47
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
48

  
49
		Label label2 = new Label(container, SWT.NONE);
50
		label2.setText("Source directory");
51

  
52
		sourceDirectory = new Text(container, SWT.BORDER | SWT.SINGLE);
53
		final String lastSourcesLocation = RCPPreferences.getInstance().getString("lastSourcesLocation");
54
		sourceDirectory.setText(lastSourcesLocation);
55
		sourceDirectory.setToolTipText("The corpus source directory");
56
		sourceDirectory.setLayoutData(gd);
57
		sourceDirectory.addModifyListener(new ModifyListener() {
58
			@Override
59
			public void modifyText(ModifyEvent e) {
60
				corpusName.setText(AsciiUtils.buildId(new File(getSourcePath()).getName()).toUpperCase());
61
				setPageComplete(isCompleted());
62
			}
63
		});
64

  
65
		Button button = new Button(container, SWT.PUSH);
66
		button.setText("...");
67
		button.setToolTipText("click to select the corpus source directory");
68
		button.addSelectionListener(new SelectionListener() {
69

  
70
			@Override
71
			public void widgetSelected(SelectionEvent e) {
72
				DirectoryDialog dialog = new DirectoryDialog(e.display.getActiveShell());
73
				dialog.setFilterPath(getSourcePath());
74
				dialog.setText("Source directory to use");
75
				if (getSourcePath().length() > 0) {
76
					dialog.setFilterPath(getSourcePath());
77
				}
78
				String path = dialog.open();
79
				if (path != null) {
80
					sourceDirectory.setText(path);
81
					RCPPreferences.getInstance().put("lastSourcesLocation", path);
82
					RCPPreferences.getInstance().flush();
83

  
84
					corpusName.setText(AsciiUtils.buildId(new File(path).getName()).toUpperCase());
85

  
86
					setPageComplete(isCompleted());
87
				}
88
			}
89

  
90
			@Override
91
			public void widgetDefaultSelected(SelectionEvent e) { }
92
		});
93
		Label label1 = new Label(container, SWT.NONE);
94
		label1.setText("Corpus name");
95

  
96
		corpusName = new Text(container, SWT.BORDER | SWT.SINGLE);
97
		corpusName.setText(AsciiUtils.buildId(new File(lastSourcesLocation).getName()).toUpperCase());
98
		corpusName.setToolTipText("The corpus name");
99
		corpusName.addKeyListener(new KeyListener() {
100
			@Override
101
			public void keyReleased(KeyEvent e) {
102
				setPageComplete(isCompleted());
103
			}
104

  
105
			@Override
106
			public void keyPressed(KeyEvent e) { }
107
		});
108

  
109
		corpusName.setLayoutData(gd);
110
		new Label(container, SWT.NONE);
111
		
112
		newOrEdit = new Label(container, SWT.NONE);
113
		newOrEdit.setLayoutData(GridDataFactory.fillDefaults().span(3, 1).create());
114

  
115
		//        label1 = new Label(container, SWT.NONE);
116
		//        label1.setText("Description");
117
		//        
118
		//        descriptionText = new Text(container, SWT.BORDER | SWT.MULTI);
119
		//        descriptionText.setText("\n\n\n\n\n");
120
		//        descriptionText.setText("");
121
		//        descriptionText.setToolTipText("The corpus description in HTML format");
122
		//        gd = new GridData(GridData.FILL_HORIZONTAL);
123
		//        gd.grabExcessVerticalSpace = true;
124
		//        descriptionText.setLayoutData(gd);
125

  
126
		// required to avoid an error in the system
127
		setControl(container);
128
		setPageComplete(false);
129

  
130
		setPageComplete(isCompleted());
131
	}
132

  
133
	protected boolean isCompleted() {
134
		if (corpusName.getText().length() > 0) {
135
			//File srcProjectLink = ResourcesPlugin.getWorkspace().getRoot().getProject(corpusName.getText()).getFolder("src").getRawLocation().toFile();
136
			if (ResourcesPlugin.getWorkspace().getRoot().getProject(getCorpusName()).exists()) {
137
				newOrEdit.setText(NLS.bind("The ''{0}'' corpus will be replaced.", getCorpusName()));
138
			} else {
139
				newOrEdit.setText(NLS.bind("The ''{0}'' corpus will be created.", getCorpusName()));
140
			}
141
		}
142

  
143
		return getCorpusName().length() > 0 && getSourcePath().length() > 0;
144
		//    	return getSourcePath().length() > 0;
145
	}
146

  
147
	public String getCorpusName() {
148
		return corpusName.getText();
149
	}
150

  
151
	public String getSourcePath() {
152
		return sourceDirectory.getText().trim();
153
	}
154
}
0 155

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/ProjectNamePage.java (revision 1489)
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.ModifyEvent;
9
import org.eclipse.swt.events.ModifyListener;
10
import org.eclipse.swt.events.SelectionEvent;
11
import org.eclipse.swt.events.SelectionListener;
12
import org.eclipse.swt.layout.GridData;
13
import org.eclipse.swt.layout.GridLayout;
14
import org.eclipse.swt.widgets.Button;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.DirectoryDialog;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.widgets.Text;
19
import org.txm.core.preferences.TXMPreferences;
20
import org.txm.rcp.preferences.RCPPreferences;
21

  
22
public class ProjectNamePage extends WizardPage {
23
   // private Text corpusName;
24
    private Text sourceDirectory;
25
//    private Text descriptionText;
26
    
27
    private Composite container;
28

  
29
    public ProjectNamePage() {
30
        super("Select source directory");
31
        setTitle("Sources");
32
        setDescription("The source directory contains the sources files.");
33
    }
34

  
35
    @Override
36
    public void createControl(Composite parent) {
37
        container = new Composite(parent, SWT.NONE);
38
        GridLayout layout = new GridLayout();
39
        container.setLayout(layout);
40
        layout.numColumns = 3;
41
        
42
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
43
        
44
        Label label2 = new Label(container, SWT.NONE);
45
        label2.setText("Source directory");
46
        
47
        sourceDirectory = new Text(container, SWT.BORDER | SWT.SINGLE);
48
        final String lastSourcesLocation = RCPPreferences.getInstance().getString("lastSourcesLocation");
49
        sourceDirectory.setText(lastSourcesLocation);
50
        sourceDirectory.setToolTipText("The corpus source directory");
51
        sourceDirectory.setLayoutData(gd);
52
        sourceDirectory.addModifyListener(new ModifyListener() {
53
			@Override
54
			public void modifyText(ModifyEvent e) {
55
				setPageComplete(isCompleted());
56
			}
57
		});
58
        
59
        Button button = new Button(container, SWT.PUSH);
60
        button.setText("...");
61
        button.setToolTipText("click to select the corpus source directory");
62
        button.addSelectionListener(new SelectionListener() {
63
			
64
			@Override
65
			public void widgetSelected(SelectionEvent e) {
66
				DirectoryDialog dialog = new DirectoryDialog(e.display.getActiveShell());
67
				dialog.setFilterPath(getSourcePath());
68
				dialog.setText("Source directory");
69
				if (getSourcePath().length() > 0) {
70
					dialog.setFilterPath(getSourcePath());
71
				}
72
				String path = dialog.open();
73
				if (path != null) {
74
					sourceDirectory.setText(path);
75
					RCPPreferences.getInstance().put("lastSourcesLocation", path);
76
					RCPPreferences.getInstance().flush();
77
					setPageComplete(isCompleted());
78
				}
79
			}
80
			
81
			@Override
82
			public void widgetDefaultSelected(SelectionEvent e) { }
83
		});
84
//        Label label1 = new Label(container, SWT.NONE);
85
//        label1.setText("Name");
86
//
87
//        corpusName = new Text(container, SWT.BORDER | SWT.SINGLE);
88
//        corpusName.setText("");
89
//        corpusName.setToolTipText("The corpus name");
90
//        corpusName.addKeyListener(new KeyListener() {
91
//			@Override
92
//			public void keyReleased(KeyEvent e) {
93
//				setPageComplete(isCompleted());
94
//			}
95
//			
96
//			@Override
97
//			public void keyPressed(KeyEvent e) { }
98
//		});
99
//        
100
//        corpusName.setLayoutData(gd);
101
        new Label(container, SWT.NONE);
102
        
103
//        label1 = new Label(container, SWT.NONE);
104
//        label1.setText("Description");
105
//        
106
//        descriptionText = new Text(container, SWT.BORDER | SWT.MULTI);
107
//        descriptionText.setText("\n\n\n\n\n");
108
//        descriptionText.setText("");
109
//        descriptionText.setToolTipText("The corpus description in HTML format");
110
//        gd = new GridData(GridData.FILL_HORIZONTAL);
111
//        gd.grabExcessVerticalSpace = true;
112
//        descriptionText.setLayoutData(gd);
113
        
114
        // required to avoid an error in the system
115
        setControl(container);
116
        setPageComplete(false);
117
        
118
        setPageComplete(isCompleted());
119
    }
120

  
121
    protected boolean isCompleted() {
122
		//return getCorpusName().length() > 0 && getSourcePath().length() > 0 && !ResourcesPlugin.getWorkspace().getRoot().getProject(getCorpusName()).exists();
123
    	return getSourcePath().length() > 0;
124
	}
125

  
126
//	public String getCorpusName() {
127
//        return corpusName.getText();
128
//    }
129
    
130
    public String getSourcePath() {
131
        return sourceDirectory.getText().trim();
132
    }
133
}
0 134

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/InfosSection.java (revision 1489)
61 61
		corpusText = toolkit.createText(sectionClient, "", SWT.BORDER); //$NON-NLS-1$
62 62
		gdata = new TableWrapData(TableWrapData.FILL, TableWrapData.TOP);
63 63
		corpusText.setLayoutData(gdata);
64
		corpusText.setEnabled(false);
64 65

  
65 66
		descText = toolkit.createText(sectionClient, "", SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); //$NON-NLS-1$
66 67
		gdata = new TableWrapData(TableWrapData.FILL, TableWrapData.FILL);
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 1489)
251 251
							public void run() throws Exception {
252 252
								@SuppressWarnings("unchecked")
253 253
								TXMEditorExtension<T> ext = ((TXMEditorExtension<T>) o);
254
								if (ext.getTXMResultValidClasses()== null || ext.getTXMResultValidClasses().contains(getResult().getClass())) {
254
								
255
								if (getResult() == null) return;
256
								
257
								if (ext.getTXMResultValidClasses() == null || ext.getTXMResultValidClasses().contains(getResult().getClass())) {
255 258
									Log.finest("Installing TXMEditorExtension: "+ext.getName()); //$NON-NLS-1$
256 259
									ext.setEditor(TXMEditor.this);
257 260
									extensions.add(ext);

Formats disponibles : Unified diff