Révision 2440
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/SourceDirectoryPage.java (revision 2440) | ||
|---|---|---|
| 31 | 31 |
import org.txm.utils.logger.Log; |
| 32 | 32 |
|
| 33 | 33 |
public class SourceDirectoryPage extends WizardPage {
|
| 34 |
|
|
| 34 | 35 |
private Text corpusName; |
| 36 |
|
|
| 35 | 37 |
private Text sourceDirectory; |
| 36 |
// private Text descriptionText;
|
|
| 37 |
|
|
| 38 |
// private Text descriptionText; |
|
| 39 |
|
|
| 38 | 40 |
private Composite container; |
| 41 |
|
|
| 39 | 42 |
private Label newOrEdit, corpusNameLabel; |
| 40 |
|
|
| 43 |
|
|
| 41 | 44 |
public SourceDirectoryPage() {
|
| 42 | 45 |
super("Select source directory");
|
| 43 | 46 |
setTitle("Sources");
|
| 44 | 47 |
setDescription("The source directory contains the sources files read by the import module.");
|
| 45 | 48 |
} |
| 46 |
|
|
| 49 |
|
|
| 47 | 50 |
@Override |
| 48 | 51 |
public void createControl(Composite parent) {
|
| 49 | 52 |
container = new Composite(parent, SWT.NONE); |
| 50 | 53 |
GridLayout layout = new GridLayout(); |
| 51 | 54 |
container.setLayout(layout); |
| 52 | 55 |
layout.numColumns = 3; |
| 53 |
|
|
| 56 |
|
|
| 54 | 57 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
| 55 |
|
|
| 58 |
|
|
| 56 | 59 |
Label label2 = new Label(container, SWT.NONE); |
| 57 | 60 |
label2.setText("Source directory");
|
| 58 |
|
|
| 61 |
|
|
| 59 | 62 |
sourceDirectory = new Text(container, SWT.BORDER | SWT.SINGLE); |
| 60 | 63 |
final String lastSourcesLocation = RCPPreferences.getInstance().getString("lastSourcesLocation");
|
| 61 | 64 |
sourceDirectory.setText(lastSourcesLocation); |
| 62 | 65 |
sourceDirectory.setToolTipText("The corpus source directory");
|
| 63 | 66 |
sourceDirectory.setLayoutData(gd); |
| 64 | 67 |
sourceDirectory.addModifyListener(new ModifyListener() {
|
| 68 |
|
|
| 65 | 69 |
@Override |
| 66 | 70 |
public void modifyText(ModifyEvent e) {
|
| 67 | 71 |
corpusName.setText(AsciiUtils.buildId(new File(getSourcePath()).getName()).toUpperCase()); |
| 68 | 72 |
setPageComplete(isCompleted()); |
| 69 | 73 |
} |
| 70 | 74 |
}); |
| 71 |
|
|
| 75 |
|
|
| 72 | 76 |
Button button = new Button(container, SWT.PUSH); |
| 73 | 77 |
button.setText("...");
|
| 74 | 78 |
button.setToolTipText("click to select the corpus source directory");
|
| 75 | 79 |
button.addSelectionListener(new SelectionListener() {
|
| 76 |
|
|
| 80 |
|
|
| 77 | 81 |
@Override |
| 78 | 82 |
public void widgetSelected(SelectionEvent e) {
|
| 79 | 83 |
DirectoryDialog dialog = new DirectoryDialog(e.display.getActiveShell()); |
| ... | ... | |
| 87 | 91 |
sourceDirectory.setText(path); |
| 88 | 92 |
RCPPreferences.getInstance().put("lastSourcesLocation", path);
|
| 89 | 93 |
RCPPreferences.getInstance().flush(); |
| 90 |
|
|
| 94 |
|
|
| 91 | 95 |
corpusName.setText(AsciiUtils.buildId(new File(path).getName()).toUpperCase()); |
| 92 |
|
|
| 96 |
|
|
| 93 | 97 |
setPageComplete(isCompleted()); |
| 94 | 98 |
} |
| 95 | 99 |
} |
| 96 |
|
|
| 100 |
|
|
| 97 | 101 |
@Override |
| 98 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
| 102 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
| 99 | 103 |
}); |
| 100 | 104 |
Label label1 = new Label(container, SWT.NONE); |
| 101 | 105 |
label1.setText("Corpus name");
|
| 102 |
|
|
| 106 |
|
|
| 103 | 107 |
corpusName = new Text(container, SWT.BORDER | SWT.SINGLE); |
| 104 | 108 |
corpusName.setText(AsciiUtils.buildId(new File(lastSourcesLocation).getName()).toUpperCase()); |
| 105 | 109 |
corpusName.setToolTipText("The corpus name");
|
| 106 | 110 |
corpusName.addKeyListener(new KeyListener() {
|
| 111 |
|
|
| 107 | 112 |
@Override |
| 108 | 113 |
public void keyReleased(KeyEvent e) {
|
| 109 | 114 |
setPageComplete(isCompleted()); |
| 110 | 115 |
} |
| 111 |
|
|
| 116 |
|
|
| 112 | 117 |
@Override |
| 113 |
public void keyPressed(KeyEvent e) { }
|
|
| 118 |
public void keyPressed(KeyEvent e) {}
|
|
| 114 | 119 |
}); |
| 115 |
|
|
| 120 |
|
|
| 116 | 121 |
corpusName.setLayoutData(gd); |
| 117 | 122 |
new Label(container, SWT.NONE); |
| 118 | 123 |
|
| 119 | 124 |
newOrEdit = new Label(container, SWT.NONE); |
| 120 | 125 |
newOrEdit.setLayoutData(GridDataFactory.fillDefaults().span(3, 1).create()); |
| 121 |
|
|
| 126 |
|
|
| 122 | 127 |
corpusNameLabel = new Label(container, SWT.NONE); |
| 123 | 128 |
corpusNameLabel.setLayoutData(GridDataFactory.fillDefaults().span(3, 1).create()); |
| 124 | 129 |
|
| 125 |
// label1 = new Label(container, SWT.NONE);
|
|
| 126 |
// label1.setText("Description");
|
|
| 127 |
//
|
|
| 128 |
// descriptionText = new Text(container, SWT.BORDER | SWT.MULTI);
|
|
| 129 |
// descriptionText.setText("\n\n\n\n\n");
|
|
| 130 |
// descriptionText.setText("");
|
|
| 131 |
// descriptionText.setToolTipText("The corpus description in HTML format");
|
|
| 132 |
// gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
| 133 |
// gd.grabExcessVerticalSpace = true;
|
|
| 134 |
// descriptionText.setLayoutData(gd);
|
|
| 135 |
|
|
| 130 |
// label1 = new Label(container, SWT.NONE); |
|
| 131 |
// label1.setText("Description");
|
|
| 132 |
// |
|
| 133 |
// descriptionText = new Text(container, SWT.BORDER | SWT.MULTI); |
|
| 134 |
// descriptionText.setText("\n\n\n\n\n");
|
|
| 135 |
// descriptionText.setText("");
|
|
| 136 |
// descriptionText.setToolTipText("The corpus description in HTML format");
|
|
| 137 |
// gd = new GridData(GridData.FILL_HORIZONTAL); |
|
| 138 |
// gd.grabExcessVerticalSpace = true; |
|
| 139 |
// descriptionText.setLayoutData(gd); |
|
| 140 |
|
|
| 136 | 141 |
// required to avoid an error in the system |
| 137 | 142 |
setControl(container); |
| 138 | 143 |
setPageComplete(false); |
| 139 |
|
|
| 144 |
|
|
| 140 | 145 |
setPageComplete(isCompleted()); |
| 141 | 146 |
} |
| 142 |
|
|
| 147 |
|
|
| 143 | 148 |
protected boolean isCompleted() {
|
| 144 | 149 |
if (corpusName.getText().length() > 0) {
|
| 145 |
//File srcProjectLink = ResourcesPlugin.getWorkspace().getRoot().getProject(corpusName.getText()).getFolder("src").getRawLocation().toFile();
|
|
| 150 |
// File srcProjectLink = ResourcesPlugin.getWorkspace().getRoot().getProject(corpusName.getText()).getFolder("src").getRawLocation().toFile();
|
|
| 146 | 151 |
if (ResourcesPlugin.getWorkspace().getRoot().getProject(getCorpusName()).exists()) {
|
| 147 | 152 |
Project p = Toolbox.workspace.getProject(); |
| 148 | 153 |
if (p != null && p.getChildren().size() > 0) {
|
| 149 | 154 |
newOrEdit.setText(NLS.bind("The ''{0}'' corpus will be replaced.", getCorpusName()));
|
| 150 |
} else {
|
|
| 155 |
} |
|
| 156 |
else {
|
|
| 151 | 157 |
newOrEdit.setText(NLS.bind("The ''{0}'' corpus import will be resumed.", getCorpusName()));
|
| 152 | 158 |
} |
| 153 |
} else {
|
|
| 159 |
} |
|
| 160 |
else {
|
|
| 154 | 161 |
newOrEdit.setText(NLS.bind("The ''{0}'' corpus will be created.", getCorpusName()));
|
| 155 | 162 |
} |
| 156 | 163 |
|
| 157 | 164 |
String corpusname = corpusName.getText(); |
| 158 |
Log.fine("Checking corpus name validity with '[A-Z][-A-Z0-9]+': "+corpusname);
|
|
| 165 |
Log.fine("Checking corpus name validity with '[A-Z][-A-Z0-9]+': " + corpusname);
|
|
| 159 | 166 |
if (!corpusname.matches("[A-Z][-A-Z0-9]+")) { //$NON-NLS-1$
|
| 160 | 167 |
newOrEdit.setText(NLS.bind(TXMUIMessages.corpusNameDoesNotMatchesTheAZAZ09120PatternColonP0, corpusname)); |
| 161 | 168 |
return false; |
| 162 | 169 |
} |
| 163 | 170 |
} |
| 164 |
|
|
| 171 |
|
|
| 165 | 172 |
return getCorpusName().length() > 0 && getSourcePath().length() > 0; |
| 166 | 173 |
} |
| 167 |
|
|
| 174 |
|
|
| 168 | 175 |
public String getCorpusName() {
|
| 169 | 176 |
return corpusName.getText(); |
| 170 | 177 |
} |
| 171 |
|
|
| 178 |
|
|
| 172 | 179 |
public String getSourcePath() {
|
| 173 |
return sourceDirectory.getText().trim();
|
|
| 180 |
return sourceDirectory.getText(); |
|
| 174 | 181 |
} |
| 175 |
} |
|
| 182 |
} |
|
Formats disponibles : Unified diff