Révision 3534
| TXM/trunk/org.txm.analec.rcp/plugin.xml (revision 3534) | ||
|---|---|---|
| 232 | 232 |
</command> |
| 233 | 233 |
</menuContribution> |
| 234 | 234 |
<menuContribution |
| 235 |
locationURI="menu:menu.file.import?before=menu.file.import.separator.software"> |
|
| 235 |
locationURI="menu:menu.file.import.corpus?before=menu.file.import.separator.software">
|
|
| 236 | 236 |
<command |
| 237 | 237 |
commandId="org.txm.annotation.urs.commands.ImportGlozzCorpus" |
| 238 | 238 |
style="push"> |
| TXM/trunk/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/SimpleKRAnnotation.java (revision 3534) | ||
|---|---|---|
| 115 | 115 |
|
| 116 | 116 |
protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple |
| 117 | 117 |
|
| 118 |
protected TypedValue value_to_add; |
|
| 118 |
//protected TypedValue value_to_add;
|
|
| 119 | 119 |
|
| 120 | 120 |
protected Concordance concordance; |
| 121 | 121 |
|
| ... | ... | |
| 124 | 124 |
private ConcordanceAnnotations annotations = null; |
| 125 | 125 |
|
| 126 | 126 |
private Button addTypedValueLink; |
| 127 |
|
|
| 128 |
private TableViewerColumn annotationColumnViewer; |
|
| 127 | 129 |
|
| 128 | 130 |
@Override |
| 129 | 131 |
public String getName() {
|
| ... | ... | |
| 138 | 140 |
this.concordance = this.editor.getConcordance(); |
| 139 | 141 |
this.corpus = concordance.getCorpus(); |
| 140 | 142 |
this.annotations = new ConcordanceAnnotations(this.editor.getConcordance()); |
| 143 |
annotations.computeLines(this.editor.getConcordance().getLines()); // pre-compute the annotation lines ot avoid breaking the sort and co. |
|
| 141 | 144 |
this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus); |
| 142 | 145 |
|
| 143 | 146 |
TableViewer viewer = this.editor.getLineTableViewer(); |
| ... | ... | |
| 148 | 151 |
position = 3 + extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns |
| 149 | 152 |
} |
| 150 | 153 |
|
| 151 |
TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
|
|
| 154 |
this.annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
|
|
| 152 | 155 |
annotationColumn = annotationColumnViewer.getColumn(); |
| 153 | 156 |
annotationColumn.setText(KRAnnotationUIMessages.category); |
| 154 | 157 |
annotationColumn.setToolTipText(KRAnnotationUIMessages.keywordsAnnotation); |
| ... | ... | |
| 525 | 528 |
@Override |
| 526 | 529 |
public void run() {
|
| 527 | 530 |
try {
|
| 528 |
editor.refresh(false); |
|
| 531 |
notifyStartOfRefresh(); |
|
| 532 |
annotationColumnViewer.getViewer().refresh(); |
|
| 529 | 533 |
} |
| 530 | 534 |
catch (Exception e) {
|
| 531 | 535 |
// TODO Auto-generated catch block |
| ... | ... | |
| 536 | 540 |
} |
| 537 | 541 |
|
| 538 | 542 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
| 539 |
value_to_add = null; // reset |
|
| 543 |
TypedValue value_to_add = null; // reset
|
|
| 540 | 544 |
if (matches == null || matches.size() == 0) {
|
| 541 | 545 |
Log.warning("No line selected. Aborting.");
|
| 542 | 546 |
return; |
| ... | ... | |
| 585 | 589 |
return; |
| 586 | 590 |
} |
| 587 | 591 |
else {
|
| 588 |
value_to_add = kr.addValue(svalue, svalue, type.getId());
|
|
| 592 |
kr.addValue(svalue, svalue, type.getId()); |
|
| 589 | 593 |
KRView.refresh(); |
| 590 | 594 |
} |
| 591 | 595 |
} |
| 592 | 596 |
}); |
| 593 | 597 |
} |
| 594 | 598 |
|
| 599 |
value_to_add = kr.getValue(type, svalue); |
|
| 600 |
|
|
| 595 | 601 |
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) return; // canceled |
| 596 | 602 |
|
| 597 | 603 |
if (value_to_add == null) {
|
| ... | ... | |
| 653 | 659 |
@Override |
| 654 | 660 |
public void run() {
|
| 655 | 661 |
try {
|
| 656 |
editor.refresh(false); |
|
| 662 |
notifyStartOfRefresh(); |
|
| 663 |
annotationColumnViewer.getViewer().refresh(); |
|
| 657 | 664 |
CorporaView.refreshObject(corpus); |
| 658 | 665 |
} |
| 659 | 666 |
catch (Exception e) {
|
| TXM/trunk/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/KRAnnotation.java (revision 3534) | ||
|---|---|---|
| 123 | 123 |
|
| 124 | 124 |
protected Label equalLabel; |
| 125 | 125 |
|
| 126 |
protected TypedValue value_to_add; |
|
| 126 |
//protected TypedValue value_to_add;
|
|
| 127 | 127 |
|
| 128 | 128 |
protected Concordance concordance; |
| 129 | 129 |
|
| ... | ... | |
| 132 | 132 |
private ConcordanceAnnotations annotations = null; |
| 133 | 133 |
|
| 134 | 134 |
ConcordanceEditor editor; |
| 135 |
|
|
| 136 |
private TableViewerColumn annotationColumnViewer; |
|
| 135 | 137 |
|
| 136 | 138 |
public KRAnnotation() {
|
| 137 | 139 |
|
| ... | ... | |
| 150 | 152 |
this.concordance = this.editor.getConcordance(); |
| 151 | 153 |
this.corpus = concordance.getCorpus(); |
| 152 | 154 |
this.annotations = new ConcordanceAnnotations(this.editor.getConcordance()); |
| 155 |
annotations.computeLines(this.editor.getConcordance().getLines()); // pre-compute the annotation lines ot avoid breaking the sort and co. |
|
| 153 | 156 |
this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus); |
| 154 | 157 |
|
| 155 | 158 |
TableViewer viewer = this.editor.getLineTableViewer(); |
| ... | ... | |
| 160 | 163 |
position = 3 + extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns |
| 161 | 164 |
} |
| 162 | 165 |
|
| 163 |
TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
|
|
| 166 |
this.annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
|
|
| 164 | 167 |
annotationColumn = annotationColumnViewer.getColumn(); |
| 165 | 168 |
annotationColumn.setText(KRAnnotationUIMessages.category); |
| 166 | 169 |
annotationColumn.setToolTipText(KRAnnotationUIMessages.keywordsAnnotation); |
| ... | ... | |
| 199 | 202 |
} |
| 200 | 203 |
|
| 201 | 204 |
public boolean initialiseInput(ConcordanceEditor editor) throws Exception {
|
| 205 |
|
|
| 202 | 206 |
this.editor = editor; |
| 203 | 207 |
concordance = editor.getConcordance(); |
| 204 | 208 |
annotations = new ConcordanceAnnotations(concordance); |
| 209 |
annotations.computeLines(this.editor.getConcordance().getLines()); // pre-compute the annotation lines ot avoid breaking the sort and co. |
|
| 205 | 210 |
corpus = concordance.getCorpus(); |
| 206 | 211 |
|
| 207 | 212 |
CQPCorpus corpus = editor.getCorpus(); |
| ... | ... | |
| 336 | 341 |
annotations.setViewAnnotation(type); |
| 337 | 342 |
annotations.setAnnotationOverlap(true); |
| 338 | 343 |
try {
|
| 339 |
editor.refresh(false); |
|
| 344 |
notifyStartOfRefresh(); |
|
| 345 |
annotationColumnViewer.getViewer().refresh(); |
|
| 340 | 346 |
} |
| 341 | 347 |
catch (Exception e) {
|
| 342 | 348 |
// TODO Auto-generated catch block |
| ... | ... | |
| 483 | 489 |
}); |
| 484 | 490 |
|
| 485 | 491 |
if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
|
| 492 |
|
|
| 486 | 493 |
addTypedValueLink = new Button(annotationArea, SWT.PUSH); |
| 487 | 494 |
addTypedValueLink.setText("..."); //$NON-NLS-1$
|
| 488 | 495 |
addTypedValueLink.setToolTipText(KRAnnotationUIMessages.selectAValueAmongTheList); |
| ... | ... | |
| 714 | 721 |
if (addRemoveCombo.getSelectionIndex() == 0) { // add is default
|
| 715 | 722 |
|
| 716 | 723 |
if (getSelectedAnnotationType() != null) {
|
| 724 |
|
|
| 717 | 725 |
annotationValuesText.setEnabled(true); |
| 718 |
|
|
| 719 | 726 |
affectAnnotationButton.setEnabled(true); |
| 720 | 727 |
affectCombo.setEnabled(true); |
| 721 | 728 |
} |
| 722 | 729 |
else {
|
| 730 |
|
|
| 723 | 731 |
annotationValuesText.setEnabled(false); |
| 724 |
|
|
| 725 | 732 |
affectAnnotationButton.setEnabled(false); |
| 726 | 733 |
affectCombo.setEnabled(false); |
| 727 | 734 |
} |
| ... | ... | |
| 772 | 779 |
try {
|
| 773 | 780 |
if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
|
| 774 | 781 |
if (Log.getLevel().intValue() < Level.INFO.intValue()) annotManager.checkData(); |
| 775 |
concordance.reloadLines(editor.getTopLine(), editor.getBottomLine() + 1); |
|
| 782 |
//concordance.reloadLines(editor.getTopLine(), editor.getBottomLine() + 1);
|
|
| 776 | 783 |
} |
| 777 | 784 |
else {
|
| 778 | 785 |
return; |
| ... | ... | |
| 789 | 796 |
@Override |
| 790 | 797 |
public void run() {
|
| 791 | 798 |
try {
|
| 792 |
editor.refresh(false); |
|
| 799 |
notifyStartOfRefresh(); |
|
| 800 |
annotationColumnViewer.getViewer().refresh(); |
|
| 793 | 801 |
} |
| 794 | 802 |
catch (Exception e) {
|
| 795 | 803 |
// TODO Auto-generated catch block |
| ... | ... | |
| 802 | 810 |
} |
| 803 | 811 |
|
| 804 | 812 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
| 805 |
value_to_add = null; // reset |
|
| 813 |
|
|
| 814 |
TypedValue value_to_add = null; // reset |
|
| 806 | 815 |
if (concordance == null) {
|
| 807 | 816 |
Log.info("No concordance done. Aborting.");
|
| 808 | 817 |
return; |
| ... | ... | |
| 855 | 864 |
return; |
| 856 | 865 |
} |
| 857 | 866 |
else {
|
| 858 |
value_to_add = kr.addValue(svalue, svalue, type.getId());
|
|
| 867 |
kr.addValue(svalue, svalue, type.getId()); |
|
| 859 | 868 |
KRView.refresh(); |
| 860 | 869 |
} |
| 861 | 870 |
} |
| 862 | 871 |
}); |
| 863 | 872 |
} |
| 864 | 873 |
|
| 874 |
value_to_add = kr.getValue(type, svalue); // re-initialize value_to_add if the value was created |
|
| 875 |
|
|
| 865 | 876 |
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) return; // canceled |
| 866 | 877 |
|
| 867 | 878 |
if (value_to_add == null) {
|
| ... | ... | |
| 913 | 924 |
if (Log.getLevel().intValue() < Level.INFO.intValue() && annotManager != null) {
|
| 914 | 925 |
annotManager.checkData(); |
| 915 | 926 |
} |
| 916 |
concordance.reloadCurrentLines(); |
|
| 927 |
//concordance.reloadCurrentLines();
|
|
| 917 | 928 |
} |
| 918 | 929 |
catch (Exception e1) {
|
| 919 | 930 |
Log.warning(NLS.bind(KRAnnotationUIMessages.errorWhileAffectionAnnotationColonP0, e1)); |
| ... | ... | |
| 926 | 937 |
@Override |
| 927 | 938 |
public void run() {
|
| 928 | 939 |
try {
|
| 929 |
editor.refresh(false); |
|
| 940 |
notifyStartOfRefresh(); |
|
| 941 |
annotationColumnViewer.getViewer().refresh(); |
|
| 930 | 942 |
CorporaView.refreshObject(corpus); |
| 931 | 943 |
} |
| 932 | 944 |
catch (Exception e) {
|
| TXM/trunk/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java (revision 3534) | ||
|---|---|---|
| 125 | 125 |
|
| 126 | 126 |
protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple |
| 127 | 127 |
|
| 128 |
protected TypedValue value_to_add; |
|
| 128 |
//protected TypedValue value_to_add;
|
|
| 129 | 129 |
|
| 130 | 130 |
protected Concordance concordance; |
| 131 | 131 |
|
| ... | ... | |
| 185 | 185 |
} |
| 186 | 186 |
|
| 187 | 187 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
| 188 |
value_to_add = null; // reset |
|
| 188 |
TypedValue value_to_add = null; // reset
|
|
| 189 | 189 |
if (matches == null || matches.size() == 0) {
|
| 190 | 190 |
Log.warning("No line selected. Aborting.");
|
| 191 | 191 |
return; |
| ... | ... | |
| 237 | 237 |
|
| 238 | 238 |
// finally we can 'try' to create the annotations \o/ |
| 239 | 239 |
try {
|
| 240 |
System.out.println("CREATE ANNOTATIONS");
|
|
| 240 | 241 |
HashMap<Match, List<Annotation>> existingAnnots = annotManager.createAnnotations(type, value_to_add, matches, job); |
| 241 |
|
|
| 242 |
System.out.println("END OF CREATE ANNOTATIONS");
|
|
| 242 | 243 |
// did we had problems ? |
| 243 | 244 |
if (existingAnnots != null && existingAnnots.size() > 0) {
|
| 244 | 245 |
String message = NLS.bind(KRAnnotationUIMessages.couldNotAnnotateTheValueP0OnCertainSequences, value_to_add.getStandardName()); |
| ... | ... | |
| 282 | 283 |
@Override |
| 283 | 284 |
public void run() {
|
| 284 | 285 |
try {
|
| 286 |
System.out.println("REFRESH ANNOTATIONS");
|
|
| 285 | 287 |
annotationColumn.setText("*" + annotations.getViewAnnotation().getName());
|
| 286 |
editor.refresh(false); |
|
| 288 |
notifyStartOfRefresh(); |
|
| 289 |
System.out.println("END OF REFRESH ANNOTATIONS");
|
|
| 290 |
annotationColumnViewer.getViewer().refresh(); |
|
| 291 |
//editor.refresh(false); |
|
| 287 | 292 |
} |
| 288 | 293 |
catch (Exception e) {
|
| 289 | 294 |
// TODO Auto-generated catch block |
| ... | ... | |
| 364 | 369 |
public void run() {
|
| 365 | 370 |
try {
|
| 366 | 371 |
annotationColumn.setText("*" + annotations.getViewAnnotation().getName());
|
| 367 |
editor.refresh(false); |
|
| 372 |
notifyStartOfRefresh(); |
|
| 373 |
annotationColumnViewer.getViewer().refresh(); |
|
| 368 | 374 |
} |
| 369 | 375 |
catch (Exception e) {
|
| 370 | 376 |
// TODO Auto-generated catch block |
| ... | ... | |
| 410 | 416 |
this.concordance = this.editor.getConcordance(); |
| 411 | 417 |
this.corpus = concordance.getCorpus(); |
| 412 | 418 |
this.annotations = new ConcordanceAnnotations(this.editor.getConcordance()); |
| 419 |
//annotations.computeLines(this.editor.getConcordance().getLines()); // pre-compute the annotation lines ot avoid breaking the sort and co. |
|
| 413 | 420 |
this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus); |
| 414 | 421 |
|
| 415 | 422 |
TableViewer viewer = this.editor.getLineTableViewer(); |
| ... | ... | |
| 830 | 837 |
}); |
| 831 | 838 |
|
| 832 | 839 |
updateAnnotationWidgetStates(); |
| 840 |
|
|
| 833 | 841 |
editor.layout(true); |
| 842 |
|
|
| 834 | 843 |
// ext.getSaveButton().setEnabled(true); |
| 844 |
// viewer.refresh(); |
|
| 835 | 845 |
return true; |
| 836 | 846 |
} |
| 837 | 847 |
|
| ... | ... | |
| 856 | 866 |
annotations.setViewAnnotation(type); |
| 857 | 867 |
annotations.setAnnotationOverlap(true); |
| 858 | 868 |
try {
|
| 859 |
editor.refresh(false); |
|
| 869 |
notifyStartOfRefresh(); |
|
| 870 |
annotationColumnViewer.getViewer().refresh(); |
|
| 860 | 871 |
} |
| 861 | 872 |
catch (Exception e) {
|
| 862 | 873 |
// TODO Auto-generated catch block |
| ... | ... | |
| 997 | 1008 |
if (annotationArea.isDisposed()) return; |
| 998 | 1009 |
|
| 999 | 1010 |
List<Line> lines = concordance.getLines(concordance.getTopIndex(), concordance.getTopIndex() + concordance.getNLinePerPage()); |
| 1011 |
//List<Line> lines = concordance.getLines(); |
|
| 1000 | 1012 |
annotations.computeLines(lines); |
| 1001 | 1013 |
|
| 1002 | 1014 |
updateAnnotationWidgetStates(); |
| ... | ... | |
| 1010 | 1022 |
else {
|
| 1011 | 1023 |
annotationColumn.setWidth(0); |
| 1012 | 1024 |
} |
| 1025 |
|
|
| 1026 |
annotationColumnViewer.getViewer().refresh(); |
|
| 1013 | 1027 |
} |
| 1014 | 1028 |
|
| 1015 | 1029 |
@Override |
| TXM/trunk/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/ConcordanceAnnotations.java (revision 3534) | ||
|---|---|---|
| 3 | 3 |
import java.util.ArrayList; |
| 4 | 4 |
import java.util.Collections; |
| 5 | 5 |
import java.util.HashMap; |
| 6 |
import java.util.LinkedHashMap; |
|
| 6 | 7 |
import java.util.List; |
| 7 | 8 |
import java.util.TreeMap; |
| 8 | 9 |
|
| ... | ... | |
| 51 | 52 |
|
| 52 | 53 |
this.concordanceLines = concordanceLines; |
| 53 | 54 |
|
| 54 |
HashMap<Match, Line> matches = new HashMap<Match, Line>(); |
|
| 55 |
// HashMap<Match, Line> matches = new HashMap<Match, Line>(); |
|
| 56 |
// for (Line line : concordanceLines) {
|
|
| 57 |
// matches.put(line.getMatch(), line); |
|
| 58 |
// } |
|
| 59 |
// |
|
| 60 |
// ArrayList<Match> sorted_matches = new ArrayList<Match>(matches.keySet()); |
|
| 61 |
// Collections.sort(sorted_matches); |
|
| 62 |
// |
|
| 63 |
// List<Annotation> ann = getAnnotationForMatches(sorted_matches, overlapAnnotation); |
|
| 64 |
// lines = new HashMap<Line, AnnotationLine>(); |
|
| 65 |
// |
|
| 66 |
// for (int i = 0 ; i < ann.size() ; i++) {
|
|
| 67 |
// Annotation a = ann.get(i); |
|
| 68 |
// AnnotationLine aline = new AnnotationLine(a, getAnnotationTypedValue(a)); |
|
| 69 |
// lines.put(matches.get(sorted_matches.get(i)), aline); |
|
| 70 |
// } |
|
| 71 |
// |
|
| 72 |
// return lines; // TODO find a way to add with lazy method |
|
| 73 |
|
|
| 74 |
LinkedHashMap<Match, Line> matches = new LinkedHashMap<Match, Line>(); |
|
| 55 | 75 |
for (Line line : concordanceLines) {
|
| 56 | 76 |
matches.put(line.getMatch(), line); |
| 57 | 77 |
} |
| 78 |
|
|
| 58 | 79 |
ArrayList<Match> sorted_matches = new ArrayList<Match>(matches.keySet()); |
| 59 | 80 |
Collections.sort(sorted_matches); |
| 60 | 81 |
|
| ... | ... | |
| 208 | 229 |
|
| 209 | 230 |
public void setViewAnnotation(AnnotationType type) {
|
| 210 | 231 |
viewAnnotation = type; |
| 211 |
concordance.resetLines(); |
|
| 232 |
//concordance.resetLines();
|
|
| 212 | 233 |
} |
| 213 | 234 |
|
| 214 | 235 |
/** |
| TXM/trunk/org.txm.conllu.rcp/plugin.xml (revision 3534) | ||
|---|---|---|
| 25 | 25 |
<extension |
| 26 | 26 |
point="org.eclipse.ui.menus"> |
| 27 | 27 |
<menuContribution |
| 28 |
locationURI="menu:menu.file.import?before=menu.file.import.separator.software"> |
|
| 28 |
locationURI="menu:menu.file.import.corpus?before=menu.file.import.separator.software">
|
|
| 29 | 29 |
<command |
| 30 | 30 |
commandId="org.txm.rcp.handlers.scripts.ExecuteImportScript" |
| 31 | 31 |
icon="icons/functions/UD.png" |
| TXM/trunk/org.txm.imports.metopes/plugin.xml (revision 3534) | ||
|---|---|---|
| 4 | 4 |
<extension |
| 5 | 5 |
point="org.eclipse.ui.menus"> |
| 6 | 6 |
<menuContribution |
| 7 |
locationURI="menu:menu.file.import?before=menu.file.import.separator.software"> |
|
| 7 |
locationURI="menu:menu.file.import.corpus?before=menu.file.import.separator.software">
|
|
| 8 | 8 |
<command |
| 9 | 9 |
commandId="org.txm.rcp.handlers.scripts.ExecuteImportScript" |
| 10 | 10 |
label="XML-TEI Metopes" |
| TXM/trunk/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editor/AnnotationExtension.java (revision 3534) | ||
|---|---|---|
| 189 | 189 |
|
| 190 | 190 |
editor.getTopToolbar().setVisible(GROUP_NAME, true); |
| 191 | 191 |
annotationAreas.add(aa); |
| 192 |
editor.refresh(false); // refresh the concordance display |
|
| 192 |
|
|
| 193 |
aa.notifyStartOfCompute(); |
|
| 194 |
aa.notifyStartOfRefresh(); |
|
| 195 |
|
|
| 196 |
//editor.refresh(false); // refresh the concordance display |
|
| 193 | 197 |
} |
| 194 | 198 |
|
| 195 | 199 |
/** |
| TXM/trunk/org.txm.tigersearch.rcp/plugin.xml (revision 3534) | ||
|---|---|---|
| 74 | 74 |
</command> |
| 75 | 75 |
</menuContribution> |
| 76 | 76 |
<menuContribution |
| 77 |
locationURI="menu:menu.file.import?before=menu.file.import.separator.software"> |
|
| 77 |
locationURI="menu:menu.file.import.corpus?before=menu.file.import.separator.software">
|
|
| 78 | 78 |
<command |
| 79 | 79 |
commandId="org.txm.rcp.handlers.scripts.ExecuteImportScript" |
| 80 | 80 |
icon="icons/functions/TS.png" |
| TXM/trunk/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/storage/temporary/TemporaryAnnotationManager.java (revision 3534) | ||
|---|---|---|
| 2 | 2 |
|
| 3 | 3 |
import java.io.File; |
| 4 | 4 |
import java.util.ArrayList; |
| 5 |
import java.util.Collections; |
|
| 5 | 6 |
import java.util.HashMap; |
| 6 | 7 |
import java.util.List; |
| 7 | 8 |
import java.util.logging.Level; |
| ... | ... | |
| 403 | 404 |
return typedQuery.getResultList(); |
| 404 | 405 |
} |
| 405 | 406 |
|
| 406 |
public List<Annotation> getAnnotationsForMatches(List<Match> matches, List<Annotation> annotations, boolean overlap) {
|
|
| 407 |
public List<Annotation> getAnnotationsForMatches(List<Match> sortedMatches, List<Annotation> sortedAnnotations, boolean overlap) {
|
|
| 408 |
|
|
| 407 | 409 |
List<Annotation> annotsList = new ArrayList<>(); |
| 408 |
|
|
| 410 |
// matches = new ArrayList<>(matches); |
|
| 411 |
// Collections.sort(matches); |
|
| 409 | 412 |
int iMatch = 0; |
| 410 | 413 |
int iAnnotation = 0; |
| 411 |
int nMatch = matches.size();
|
|
| 412 |
int nAnnotations = annotations.size();
|
|
| 414 |
int nMatch = sortedMatches.size();
|
|
| 415 |
int nAnnotations = sortedAnnotations.size();
|
|
| 413 | 416 |
|
| 414 | 417 |
Match match = null; |
| 415 | 418 |
Annotation annotation = null; |
| 416 | 419 |
while (iMatch < nMatch && iAnnotation < nAnnotations) {
|
| 417 |
match = matches.get(iMatch); |
|
| 420 |
|
|
| 421 |
match = sortedMatches.get(iMatch); |
|
| 418 | 422 |
int start, end; |
| 419 | 423 |
if (match.getTarget() >= 0) {
|
| 420 | 424 |
start = end = match.getTarget(); |
| ... | ... | |
| 424 | 428 |
end = match.getEnd(); |
| 425 | 429 |
} |
| 426 | 430 |
|
| 427 |
annotation = annotations.get(iAnnotation);
|
|
| 431 |
annotation = sortedAnnotations.get(iAnnotation);
|
|
| 428 | 432 |
int astart = annotation.getStart(), aend = annotation.getEnd(); |
| 429 | 433 |
|
| 430 | 434 |
if (overlap) {
|
| ... | ... | |
| 460 | 464 |
} |
| 461 | 465 |
} |
| 462 | 466 |
|
| 463 |
while (annotsList.size() < matches.size())
|
|
| 467 |
while (annotsList.size() < sortedMatches.size())
|
|
| 464 | 468 |
annotsList.add(null); // fill matches that were not process due to no more annotations |
| 465 | 469 |
|
| 466 | 470 |
return annotsList; |
| TXM/trunk/org.txm.ca.core/src/org/txm/ca/core/functions/CA.java (revision 3534) | ||
|---|---|---|
| 1128 | 1128 |
|
| 1129 | 1129 |
@Override |
| 1130 | 1130 |
public LexicalTable getParent() {
|
| 1131 |
|
|
| 1132 |
return (LexicalTable) this.parent;
|
|
| 1131 |
if (parent instanceof LexicalTable) return (LexicalTable) this.parent; |
|
| 1132 |
return null;
|
|
| 1133 | 1133 |
} |
| 1134 | 1134 |
|
| 1135 | 1135 |
// // FIXME: SJ: fix to save the eigenvalues when the CA is saved |
| TXM/trunk/org.txm.rcp/plugin.xml (revision 3534) | ||
|---|---|---|
| 351 | 351 |
icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/import_wiz.png" |
| 352 | 352 |
id="menu.file.import" |
| 353 | 353 |
label="%menu.label.0"> |
| 354 |
<command |
|
| 354 |
<menu |
|
| 355 |
icon="icons/objects/corpus.png" |
|
| 356 |
id="menu.file.import.corpus" |
|
| 357 |
label="Corpus"> |
|
| 358 |
<command |
|
| 355 | 359 |
commandId="org.txm.rcp.commands.ImportClipboardText" |
| 356 | 360 |
label="%command.label.60" |
| 357 | 361 |
style="push" |
| ... | ... | |
| 523 | 527 |
name="menu.file.import.separator.end" |
| 524 | 528 |
visible="true"> |
| 525 | 529 |
</separator> |
| 530 |
</menu> |
|
| 526 | 531 |
<menu |
| 527 | 532 |
id="menu.file.import.properties" |
| 528 | 533 |
label="%menu.label.17"> |
| ... | ... | |
| 542 | 547 |
id="menu.file.import.annotations" |
| 543 | 548 |
label="%menu.label.15"> |
| 544 | 549 |
</menu> |
| 550 |
<command |
|
| 551 |
commandId="org.txm.rcp.handlers.export.ImportResultParameters" |
|
| 552 |
icon="icons/functions/import_parameters.png" |
|
| 553 |
label="Results..." |
|
| 554 |
style="push"> |
|
| 555 |
<visibleWhen |
|
| 556 |
checkEnabled="false"> |
|
| 557 |
<and> |
|
| 558 |
<reference |
|
| 559 |
definitionId="OneTXMResultSelected"> |
|
| 560 |
</reference> |
|
| 561 |
</and> |
|
| 562 |
</visibleWhen> |
|
| 563 |
</command> |
|
| 545 | 564 |
</menu> |
| 546 | 565 |
<menu |
| 547 | 566 |
id="menu.file.load" |
| ... | ... | |
| 630 | 649 |
</and> |
| 631 | 650 |
</visibleWhen> |
| 632 | 651 |
</command> |
| 652 |
<command |
|
| 653 |
commandId="org.txm.rcp.handlers.export.ExportResultParameters" |
|
| 654 |
icon="icons/functions/export_parameters.png" |
|
| 655 |
label="Results..." |
|
| 656 |
style="push"> |
|
| 657 |
<visibleWhen |
|
| 658 |
checkEnabled="false"> |
|
| 659 |
<and> |
|
| 660 |
<reference |
|
| 661 |
definitionId="OneTXMResultSelected"> |
|
| 662 |
</reference> |
|
| 663 |
<not> |
|
| 664 |
<reference |
|
| 665 |
definitionId="OneMainCorpusSelected"> |
|
| 666 |
</reference> |
|
| 667 |
</not> |
|
| 668 |
</and> |
|
| 669 |
</visibleWhen> |
|
| 670 |
</command> |
|
| 633 | 671 |
</menu> |
| 634 | 672 |
<separator |
| 635 | 673 |
name="menu.file.separator.file" |
| ... | ... | |
| 1489 | 1527 |
<toolbar |
| 1490 | 1528 |
id="org.txm.rcp.toolbars.result"> |
| 1491 | 1529 |
<command |
| 1530 |
commandId="org.txm.rcp.handlers.export.ImportResultParameters" |
|
| 1531 |
icon="icons/functions/import_parameters.png" |
|
| 1532 |
label="Import results" |
|
| 1533 |
style="push"> |
|
| 1534 |
<visibleWhen |
|
| 1535 |
checkEnabled="false"> |
|
| 1536 |
<and> |
|
| 1537 |
<reference |
|
| 1538 |
definitionId="OneTXMResultSelected"> |
|
| 1539 |
</reference> |
|
| 1540 |
</and> |
|
| 1541 |
</visibleWhen> |
|
| 1542 |
</command> |
|
| 1543 |
<command |
|
| 1492 | 1544 |
commandId="org.txm.rcp.commands.function.ExportResult" |
| 1493 | 1545 |
icon="icons/functions/export_data.png" |
| 1494 | 1546 |
label="%command.label.51" |
| ... | ... | |
| 1512 | 1564 |
</and> |
| 1513 | 1565 |
</visibleWhen> |
| 1514 | 1566 |
</command> |
| 1567 |
<command |
|
| 1568 |
commandId="org.txm.rcp.handlers.export.ExportResultParameters" |
|
| 1569 |
icon="icons/functions/export_parameters.png" |
|
| 1570 |
label="Export results..." |
|
| 1571 |
style="push"> |
|
| 1572 |
<visibleWhen |
|
| 1573 |
checkEnabled="false"> |
|
| 1574 |
<and> |
|
| 1575 |
<reference |
|
| 1576 |
definitionId="OneTXMResultSelected"> |
|
| 1577 |
</reference> |
|
| 1578 |
<not> |
|
| 1579 |
<reference |
|
| 1580 |
definitionId="OneMainCorpusSelected"> |
|
| 1581 |
</reference> |
|
| 1582 |
</not> |
|
| 1583 |
</and> |
|
| 1584 |
</visibleWhen> |
|
| 1585 |
</command> |
|
| 1515 | 1586 |
</toolbar> |
| 1516 | 1587 |
<separator |
| 1517 | 1588 |
name="org.txm.rcp.toolbar.separator1" |
| ... | ... | |
| 2055 | 2126 |
</and> |
| 2056 | 2127 |
</visibleWhen> |
| 2057 | 2128 |
</command> |
| 2129 |
<command |
|
| 2130 |
commandId="org.txm.rcp.handlers.export.ExportResultParameters" |
|
| 2131 |
icon="icons/functions/export_parameters.png" |
|
| 2132 |
label="Results..." |
|
| 2133 |
style="push"> |
|
| 2134 |
<visibleWhen |
|
| 2135 |
checkEnabled="false"> |
|
| 2136 |
<and> |
|
| 2137 |
<reference |
|
| 2138 |
definitionId="OneTXMResultSelected"> |
|
| 2139 |
</reference> |
|
| 2140 |
<not> |
|
| 2141 |
<reference |
|
| 2142 |
definitionId="OneMainCorpusSelected"> |
|
| 2143 |
</reference> |
|
| 2144 |
</not> |
|
| 2145 |
</and> |
|
| 2146 |
</visibleWhen> |
|
| 2147 |
</command> |
|
| 2058 | 2148 |
</menu> |
| 2149 |
<command |
|
| 2150 |
commandId="org.txm.rcp.handlers.export.ImportResultParameters" |
|
| 2151 |
icon="icons/functions/import_parameters.png" |
|
| 2152 |
label="Import results" |
|
| 2153 |
style="push"> |
|
| 2154 |
<visibleWhen |
|
| 2155 |
checkEnabled="false"> |
|
| 2156 |
<and> |
|
| 2157 |
<reference |
|
| 2158 |
definitionId="OneTXMResultSelected"> |
|
| 2159 |
</reference> |
|
| 2160 |
</and> |
|
| 2161 |
</visibleWhen> |
|
| 2162 |
</command> |
|
| 2059 | 2163 |
|
| 2060 | 2164 |
<separator |
| 2061 | 2165 |
name="org.txm.rcp.corporaview.corpus" |
| ... | ... | |
| 2117 | 2221 |
</and> |
| 2118 | 2222 |
</visibleWhen> |
| 2119 | 2223 |
</command> |
| 2120 |
<command |
|
| 2121 |
commandId="org.txm.rcp.commands.function.RenameResult" |
|
| 2122 |
label="%command.label.26" |
|
| 2123 |
style="push"> |
|
| 2124 |
<visibleWhen |
|
| 2125 |
checkEnabled="false"> |
|
| 2126 |
<reference |
|
| 2127 |
definitionId="OneTXMResultSelected"> |
|
| 2128 |
</reference> |
|
| 2129 |
</visibleWhen> |
|
| 2130 |
</command> |
|
| 2131 | 2224 |
|
| 2132 | 2225 |
<command |
| 2133 | 2226 |
commandId="org.txm.rcp.handlers.results.DeleteObject" |
| ... | ... | |
| 2143 | 2236 |
</visibleWhen> |
| 2144 | 2237 |
</command> |
| 2145 | 2238 |
<command |
| 2239 |
commandId="org.txm.rcp.commands.function.RenameResult" |
|
| 2240 |
label="%command.label.26" |
|
| 2241 |
style="push"> |
|
| 2242 |
<visibleWhen |
|
| 2243 |
checkEnabled="false"> |
|
| 2244 |
<reference |
|
| 2245 |
definitionId="OneTXMResultSelected"> |
|
| 2246 |
</reference> |
|
| 2247 |
</visibleWhen> |
|
| 2248 |
</command> |
|
| 2249 |
<command |
|
| 2146 | 2250 |
commandId="org.txm.rcp.handlers.results.CloneTXMResult" |
| 2147 | 2251 |
label="%command.label.372" |
| 2148 | 2252 |
style="push"> |
| TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultParameters.java (revision 3534) | ||
|---|---|---|
| 29 | 29 |
|
| 30 | 30 |
import java.io.File; |
| 31 | 31 |
import java.io.IOException; |
| 32 |
import java.util.ArrayList; |
|
| 33 |
import java.util.Calendar; |
|
| 32 | 34 |
|
| 33 | 35 |
import org.eclipse.core.commands.AbstractHandler; |
| 34 | 36 |
import org.eclipse.core.commands.ExecutionEvent; |
| ... | ... | |
| 43 | 45 |
import org.eclipse.swt.widgets.FileDialog; |
| 44 | 46 |
import org.eclipse.swt.widgets.Shell; |
| 45 | 47 |
import org.eclipse.ui.handlers.HandlerUtil; |
| 48 |
import org.txm.Toolbox; |
|
| 46 | 49 |
import org.txm.core.preferences.TBXPreferences; |
| 47 | 50 |
import org.txm.core.preferences.TXMPreferences; |
| 48 | 51 |
import org.txm.core.results.TXMResult; |
| ... | ... | |
| 52 | 55 |
import org.txm.rcp.messages.TXMUIMessages; |
| 53 | 56 |
import org.txm.rcp.swt.dialog.LastOpened; |
| 54 | 57 |
import org.txm.rcp.utils.JobHandler; |
| 58 |
import org.txm.utils.DeleteDir; |
|
| 59 |
import org.txm.utils.zip.Zip; |
|
| 55 | 60 |
|
| 56 | 61 |
// TODO: Auto-generated Javadoc |
| 57 | 62 |
/** |
| ... | ... | |
| 72 | 77 |
@Override |
| 73 | 78 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
| 74 | 79 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
| 75 |
final Object s = selection.getFirstElement(); |
|
| 76 |
if (!(s instanceof TXMResult)) {
|
|
| 77 |
return null; |
|
| 78 |
} |
|
| 80 |
|
|
| 79 | 81 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
| 80 | 82 |
|
| 81 | 83 |
// String txmhome = Toolbox.getTxmHomePath(); |
| 82 | 84 |
FileDialog dialog = new FileDialog(shell, SWT.SAVE); |
| 83 | 85 |
|
| 84 |
String extensions[] = { "*.parameters" }; //$NON-NLS-1$
|
|
| 86 |
String extensions[] = { "*.txmresults" }; //$NON-NLS-1$
|
|
| 85 | 87 |
dialog.setFilterExtensions(extensions); |
| 86 |
dialog.setFileName(((TXMResult) s).getValidFileName() + ".parameters"); //$NON-NLS-1$
|
|
| 88 |
dialog.setFileName("results_"+Toolbox.dateformat.format(Calendar.getInstance().getTime()) +".txmresults"); //$NON-NLS-1$
|
|
| 87 | 89 |
if (LastOpened.getFile(ID) != null) {
|
| 88 | 90 |
dialog.setFilterPath(LastOpened.getFolder(ID)); |
| 89 | 91 |
} |
| 90 | 92 |
|
| 91 | 93 |
if (dialog.open() != null) {
|
| 92 | 94 |
StatusLine.setMessage(TXMUIMessages.exportingResults); |
| 93 |
String filepath = dialog.getFilterPath() |
|
| 94 |
+ "/" + dialog.getFileName(); //$NON-NLS-1$ |
|
| 95 |
if (!(filepath.endsWith(extensions[0].substring(1)))) |
|
| 95 |
String filepath = dialog.getFilterPath() + "/" + dialog.getFileName(); //$NON-NLS-1$ |
|
| 96 |
if (!(filepath.endsWith(extensions[0].substring(1)))) {
|
|
| 96 | 97 |
filepath += extensions[0].substring(1); |
| 97 |
|
|
| 98 |
final File outfile = new File(filepath); |
|
| 99 |
LastOpened.set(ID, outfile.getParent(), outfile.getName()); |
|
| 100 |
try {
|
|
| 101 |
outfile.createNewFile(); |
|
| 102 | 98 |
} |
| 103 |
catch (IOException e1) {
|
|
| 104 |
System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1)); |
|
| 105 |
} |
|
| 106 |
if (!outfile.canWrite()) {
|
|
| 107 |
System.out.println(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile)); |
|
| 108 |
return null; |
|
| 109 |
} |
|
| 110 |
if (!outfile.isFile()) {
|
|
| 111 |
System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 112 |
return null; |
|
| 113 |
} |
|
| 114 | 99 |
|
| 100 |
final File zipfile = new File(filepath+".tmp"); |
|
| 101 |
final File zipfiledir = new File(filepath); // temporary directory to setup the archive |
|
| 102 |
LastOpened.set(ID, zipfiledir.getParent(), zipfiledir.getName()); |
|
| 103 |
zipfiledir.delete(); |
|
| 104 |
zipfiledir.mkdirs(); |
|
| 105 |
|
|
| 115 | 106 |
JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
|
| 116 | 107 |
|
| 117 | 108 |
@Override |
| ... | ... | |
| 119 | 110 |
|
| 120 | 111 |
// convert the monitor into sub-monitor |
| 121 | 112 |
SubMonitor subMonitor = SubMonitor.convert(monitor, TXMUIMessages.exporting, 100); |
| 113 |
this.runInit(subMonitor); |
|
| 122 | 114 |
|
| 123 | 115 |
try {
|
| 124 | 116 |
|
| 125 |
this.runInit(subMonitor); |
|
| 126 |
|
|
| 127 |
TXMResult r = (TXMResult) s; |
|
| 128 |
if (r.isAltered()) {
|
|
| 129 |
System.out.println(TXMUIMessages.ExportResultParameters_WarningOnlyTheParametersAreExportedManualChangesAreNotTransfered); |
|
| 117 |
ArrayList<TXMResult> toExport = new ArrayList<TXMResult>(); |
|
| 118 |
for (Object o : selection.toList()) {
|
|
| 119 |
if (!(o instanceof TXMResult)) continue; |
|
| 120 |
TXMResult r = (TXMResult)o; |
|
| 121 |
toExport.add(r); |
|
| 122 |
TXMResult parent = ((TXMResult)o).getParent(); |
|
| 123 |
|
|
| 124 |
while(parent != null && !parent.isVisible()) { // insivisble parent must be added to the exported results
|
|
| 125 |
|
|
| 126 |
toExport.add(parent); |
|
| 127 |
parent = parent.getParent(); |
|
| 128 |
} |
|
| 130 | 129 |
} |
| 131 |
else {
|
|
| 132 |
r.compute(subMonitor); // refresh result |
|
| 133 |
} |
|
| 134 |
if (r.toParametersFile(outfile)) {
|
|
| 135 |
System.out.println(NLS.bind(TXMUIMessages.ExportResultParameters_ParametersExportedToTheP0File, outfile)); |
|
| 136 |
} |
|
| 137 | 130 |
|
| 138 |
if (outfile.exists()) {
|
|
| 139 |
// Open internal editor in the UI thread |
|
| 140 |
if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW)) {
|
|
| 141 |
this.syncExec(new Runnable() {
|
|
| 142 |
|
|
| 143 |
@Override |
|
| 144 |
public void run() {
|
|
| 145 |
EditFile.openfile(outfile.getAbsolutePath()); |
|
| 146 |
} |
|
| 147 |
}); |
|
| 131 |
ArrayList<File> files = new ArrayList<>(); |
|
| 132 |
for (TXMResult r : toExport) {
|
|
| 133 |
|
|
| 134 |
if (r.isAltered()) {
|
|
| 135 |
System.out.println(TXMUIMessages.ExportResultParameters_WarningOnlyTheParametersAreExportedManualChangesAreNotTransfered); |
|
| 148 | 136 |
} |
| 137 |
else {
|
|
| 138 |
r.compute(subMonitor); // refresh result |
|
| 139 |
} |
|
| 149 | 140 |
|
| 150 |
System.out.println(NLS.bind("", outfile.getAbsolutePath())); //$NON-NLS-1$
|
|
| 141 |
File outfile = new File(zipfiledir, (TXMPreferences.getNode(r.getParametersNodePath()).name()+".parameters")); |
|
| 142 |
if (r.toParametersFile(outfile)) {
|
|
| 143 |
files.add(outfile); |
|
| 144 |
} |
|
| 151 | 145 |
} |
| 152 |
else {
|
|
| 153 |
System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath())); |
|
| 154 |
} |
|
| 146 |
|
|
| 147 |
System.out.println(NLS.bind(TXMUIMessages.ExportResultParameters_ParametersExportedToTheP0File, zipfiledir)); |
|
| 148 |
Zip.compress(files.toArray(new File[files.size()]), zipfile, Zip.DEFAULT_LEVEL_COMPRESSION, null, null); |
|
| 149 |
DeleteDir.deleteDirectory(zipfiledir); |
|
| 150 |
zipfile.renameTo(zipfiledir); |
|
| 155 | 151 |
} |
| 156 | 152 |
catch (ThreadDeath td) {
|
| 157 |
if (s instanceof TXMResult) {
|
|
| 158 |
((TXMResult) s).clean(); |
|
| 159 |
} |
|
| 153 |
|
|
| 160 | 154 |
return Status.CANCEL_STATUS; |
| 161 | 155 |
} |
| 162 | 156 |
catch (Exception e) {
|
| 163 |
System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e)); |
|
| 157 |
System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, selection.toList(), e));
|
|
| 164 | 158 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 165 | 159 |
return Status.CANCEL_STATUS; |
| 166 | 160 |
} |
| TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ImportResultParameters.java (revision 3534) | ||
|---|---|---|
| 27 | 27 |
// |
| 28 | 28 |
package org.txm.rcp.handlers.export; |
| 29 | 29 |
|
| 30 |
import java.io.BufferedReader; |
|
| 30 | 31 |
import java.io.File; |
| 31 | 32 |
import java.io.IOException; |
| 33 |
import java.lang.reflect.Constructor; |
|
| 34 |
import java.nio.file.FileSystem; |
|
| 35 |
import java.nio.file.FileSystems; |
|
| 36 |
import java.nio.file.Files; |
|
| 37 |
import java.util.Arrays; |
|
| 38 |
import java.util.Collections; |
|
| 39 |
import java.util.HashMap; |
|
| 40 |
import java.util.LinkedHashMap; |
|
| 41 |
import java.util.Properties; |
|
| 32 | 42 |
|
| 33 | 43 |
import org.eclipse.core.commands.AbstractHandler; |
| 34 | 44 |
import org.eclipse.core.commands.ExecutionEvent; |
| 35 | 45 |
import org.eclipse.core.commands.ExecutionException; |
| 36 | 46 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 37 | 47 |
import org.eclipse.core.runtime.IStatus; |
| 48 |
import org.eclipse.core.runtime.Platform; |
|
| 38 | 49 |
import org.eclipse.core.runtime.Status; |
| 39 | 50 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 40 | 51 |
import org.eclipse.osgi.util.NLS; |
| ... | ... | |
| 42 | 53 |
import org.eclipse.swt.widgets.FileDialog; |
| 43 | 54 |
import org.eclipse.swt.widgets.Shell; |
| 44 | 55 |
import org.eclipse.ui.handlers.HandlerUtil; |
| 45 |
import org.txm.core.preferences.TBXPreferences; |
|
| 56 |
import org.osgi.framework.Bundle; |
|
| 57 |
import org.txm.Toolbox; |
|
| 46 | 58 |
import org.txm.core.preferences.TXMPreferences; |
| 47 | 59 |
import org.txm.core.results.TXMResult; |
| 48 | 60 |
import org.txm.rcp.JobsTimer; |
| 49 | 61 |
import org.txm.rcp.StatusLine; |
| 50 |
import org.txm.rcp.editors.TXMEditor; |
|
| 51 |
import org.txm.rcp.handlers.files.EditFile; |
|
| 52 | 62 |
import org.txm.rcp.messages.TXMUIMessages; |
| 53 | 63 |
import org.txm.rcp.swt.dialog.LastOpened; |
| 54 | 64 |
import org.txm.rcp.utils.JobHandler; |
| 55 | 65 |
import org.txm.rcp.utils.SWTEditorsUtils; |
| 56 | 66 |
import org.txm.rcp.views.corpora.CorporaView; |
| 67 |
import org.txm.utils.DeleteDir; |
|
| 68 |
import org.txm.utils.io.IOUtils; |
|
| 69 |
import org.txm.utils.logger.Log; |
|
| 70 |
import org.txm.utils.zip.Zip; |
|
| 57 | 71 |
|
| 58 | 72 |
// TODO: Auto-generated Javadoc |
| 59 | 73 |
/** |
| ... | ... | |
| 83 | 97 |
// String txmhome = Toolbox.getTxmHomePath(); |
| 84 | 98 |
FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
| 85 | 99 |
|
| 86 |
String extensions[] = { "*.parameters" }; //$NON-NLS-1$
|
|
| 100 |
String extensions[] = { "*.txmresults" }; //$NON-NLS-1$
|
|
| 87 | 101 |
dialog.setFilterExtensions(extensions); |
| 88 | 102 |
|
| 89 | 103 |
if (LastOpened.getFile(ID) != null) {
|
| 90 | 104 |
dialog.setFilterPath(LastOpened.getFolder(ID)); |
| 91 | 105 |
} |
| 92 |
|
|
| 93 |
if (dialog.open() != null) {
|
|
| 94 |
StatusLine.setMessage(TXMUIMessages.exportingResults); |
|
| 95 |
String filepath = dialog.getFilterPath() |
|
| 96 |
+ "/" + dialog.getFileName(); //$NON-NLS-1$ |
|
| 97 |
if (!(filepath.endsWith(extensions[0].substring(1)))) |
|
| 98 |
filepath += extensions[0].substring(1); |
|
| 99 |
|
|
| 100 |
final File outfile = new File(filepath); |
|
| 101 |
LastOpened.set(ID, outfile.getParent(), outfile.getName()); |
|
| 102 |
try {
|
|
| 103 |
outfile.createNewFile(); |
|
| 104 |
} |
|
| 105 |
catch (IOException e1) {
|
|
| 106 |
System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1)); |
|
| 107 |
} |
|
| 108 |
if (!outfile.canWrite()) {
|
|
| 109 |
System.out.println(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile)); |
|
| 110 |
return null; |
|
| 111 |
} |
|
| 112 |
if (!outfile.isFile()) {
|
|
| 113 |
System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 114 |
return null; |
|
| 115 |
} |
|
| 116 |
|
|
| 117 |
JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
|
|
| 106 |
try {
|
|
| 107 |
if (dialog.open() != null) {
|
|
| 108 |
StatusLine.setMessage(TXMUIMessages.exportingResults); |
|
| 109 |
String filepath = dialog.getFilterPath()+ "/" + dialog.getFileName(); //$NON-NLS-1$ |
|
| 118 | 110 |
|
| 119 |
@Override |
|
| 120 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 121 |
try {
|
|
| 122 |
this.runInit(monitor); |
|
| 123 |
monitor.beginTask(TXMUIMessages.exporting, 100); |
|
| 111 |
final File zipfile = new File(filepath); |
|
| 112 |
File outdir = new File(Toolbox.getTxmHomePath(), "results/import"); |
|
| 113 |
DeleteDir.deleteDirectory(outdir); |
|
| 114 |
|
|
| 115 |
Zip.decompress(zipfile, outdir, false); |
|
| 116 |
|
|
| 117 |
LinkedHashMap<File, Properties> fileToProperties = new LinkedHashMap<>(); // to retrieve a new result from its old uuid |
|
| 118 |
HashMap<String, File> oldUUIDToPropertiesFile = new HashMap<>(); // to retrieve a new result from its old uuid |
|
| 119 |
HashMap<String, String> oldUUIDToNewUUID = new HashMap<>(); // to retrieve a new result from its old uuid |
|
| 120 |
HashMap<String, String> UUIDDependencies = new HashMap<>(); // to -> from, if from is null use the selected TXMResult as parent |
|
| 121 |
|
|
| 122 |
File[] files = outdir.listFiles(); |
|
| 123 |
Arrays.sort(files); |
|
| 124 |
|
|
| 125 |
for (File parametersFile : files) {
|
|
| 126 |
if (!parametersFile.getName().endsWith(".parameters")) continue;
|
|
| 127 |
|
|
| 128 |
Properties props = new Properties(); |
|
| 129 |
BufferedReader r = IOUtils.getReader(parametersFile); |
|
| 130 |
props.load(r); |
|
| 131 |
r.close(); |
|
| 132 |
|
|
| 133 |
fileToProperties.put(parametersFile, props); |
|
| 134 |
String UUID = props.getProperty(TXMPreferences.RESULT_PARAMETERS_NODE_PATH); |
|
| 135 |
oldUUIDToPropertiesFile.put(UUID, parametersFile); |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
for (File parametersFile : outdir.listFiles()) {
|
|
| 139 |
// if (TXMPreferences.PARENT_PARAMETERS_NODE_PATH.equals(ps)) continue; |
|
| 140 |
//if (TXMPreferences.RESULT_PARAMETERS_NODE_PATH.equals(ps)) continue; |
|
| 141 |
Properties props = fileToProperties.get(parametersFile); |
|
| 142 |
String UUID = props.getProperty(TXMPreferences.RESULT_PARAMETERS_NODE_PATH); |
|
| 143 |
String parentUUID = props.getProperty(TXMPreferences.PARENT_PARAMETERS_NODE_PATH); |
|
| 144 |
if (!oldUUIDToPropertiesFile.containsKey(parentUUID)) {
|
|
| 145 |
UUIDDependencies.put(UUID, null); |
|
| 146 |
} else {
|
|
| 147 |
UUIDDependencies.put(UUID, parentUUID); |
|
| 148 |
} |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
JobHandler jobhandler = new JobHandler(TXMUIMessages.importStarted) {
|
|
| 152 |
|
|
| 153 |
@Override |
|
| 154 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 124 | 155 |
|
| 125 |
TXMResult r = (TXMResult) s; |
|
| 126 |
if (r.importParameters(outfile)) {
|
|
| 127 |
CorporaView.refreshObject(r); |
|
| 128 |
System.out.println(NLS.bind("Parameter imported from the {0} file.", outfile)); //$NON-NLS-1$
|
|
| 129 |
SWTEditorsUtils.refreshEditors(r); |
|
| 156 |
for (File parametersFile: fileToProperties.keySet()) {
|
|
| 157 |
TXMResult importedResult = null; |
|
| 158 |
try {
|
|
| 159 |
this.runInit(monitor); |
|
| 160 |
monitor.beginTask(TXMUIMessages.exporting, 100); |
|
| 161 |
|
|
| 162 |
TXMResult defaultParentResult = (TXMResult) s; |
|
| 163 |
|
|
| 164 |
Properties props = fileToProperties.get(parametersFile); |
|
| 165 |
String UUID = props.getProperty(TXMPreferences.RESULT_PARAMETERS_NODE_PATH); |
|
| 166 |
|
|
| 167 |
String className = props.getProperty(TXMPreferences.CLASS, ""); //$NON-NLS-1$ //$NON-NLS-2$ |
|
| 168 |
if (className == null || className.length() == 0) {
|
|
| 169 |
Log.warning(NLS.bind("Warning: can not import object with no class name set with path={0}.", parametersFile)); //$NON-NLS-1$
|
|
| 170 |
continue; |
|
| 171 |
} |
|
| 172 |
String bundleId = props.getProperty(TXMPreferences.BUNDLE_ID, ""); //$NON-NLS-1$ |
|
| 173 |
if (bundleId == null || bundleId.length() == 0) {
|
|
| 174 |
Log.warning(NLS.bind("Warning: can not import {0} object with no bundle id set.", parametersFile)); //$NON-NLS-1$
|
|
| 175 |
continue; |
|
| 176 |
} |
|
| 177 |
Bundle bundle = Platform.getBundle(bundleId); |
|
| 178 |
if (bundle == null) {
|
|
| 179 |
Log.warning(NLS.bind("Warning: can not import {0} object with bundle id={1}.", className, parametersFile)); //$NON-NLS-1$
|
|
| 180 |
continue; |
|
| 181 |
} |
|
| 182 |
|
|
| 183 |
Class<?> cl = bundle.loadClass(className); |
|
| 184 |
|
|
| 185 |
String resultNodePath = defaultParentResult.getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_" + cl.getSimpleName(); |
|
| 186 |
Log.info("Importing a "+cl.getSimpleName()+" from "+resultNodePath);
|
|
| 187 |
TXMResult parent = defaultParentResult; |
|
| 188 |
if (UUIDDependencies.get(UUID) != null) {
|
|
| 189 |
parent = TXMResult.getResult(oldUUIDToNewUUID.get(UUIDDependencies.get(UUID))); |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
Constructor<?> cons = cl.getConstructor(String.class); |
|
| 195 |
|
|
| 196 |
// fill the preference node with the right parameter **and then** parent right parent node path |
|
| 197 |
for (Object p : props.keySet()) {
|
|
| 198 |
String ps = p.toString(); |
|
| 199 |
TXMPreferences.put(resultNodePath, ps, props.getProperty(ps, "")); |
|
| 200 |
} |
|
| 201 |
TXMPreferences.put(resultNodePath, TXMPreferences.PARENT_PARAMETERS_NODE_PATH, parent.getParametersNodePath()); |
|
| 202 |
|
|
| 203 |
// this should create the right TXMResult, parameters string values are set |
|
| 204 |
importedResult = (TXMResult) cons.newInstance(resultNodePath); |
|
| 205 |
importedResult.autoLoadParametersFromAnnotations(); // update java parameters |
|
| 206 |
importedResult.loadParameters(); |
|
| 207 |
|
|
| 208 |
oldUUIDToNewUUID.put(UUID, resultNodePath); |
|
| 209 |
|
|
| 210 |
// if (r.importParameters(outfile)) {
|
|
| 211 |
// CorporaView.refreshObject(r); |
|
| 212 |
// System.out.println(NLS.bind("Parameter imported from the {0} file.", outfile)); //$NON-NLS-1$
|
|
| 213 |
// |
|
| 214 |
// this.syncExec(new Runnable() {
|
|
| 215 |
// |
|
| 216 |
// @Override |
|
| 217 |
// public void run() {
|
|
| 218 |
// SWTEditorsUtils.refreshEditors(r); |
|
| 219 |
// } |
|
| 220 |
// }); |
|
| 221 |
// } |
|
| 222 |
} |
|
| 223 |
catch (ThreadDeath td) {
|
|
| 224 |
if (importedResult != null) {
|
|
| 225 |
importedResult.delete(); |
|
| 226 |
} |
|
| 227 |
return Status.CANCEL_STATUS; |
|
| 228 |
} |
|
| 229 |
catch (Exception e) {
|
|
| 230 |
Log.info(NLS.bind("Error while loading result {0}: {1}", s, e));
|
|
| 231 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
| 232 |
if (importedResult != null) {
|
|
| 233 |
importedResult.delete(); |
|
| 234 |
} |
|
| 235 |
//return Status.CANCEL_STATUS; |
|
| 236 |
} |
|
| 237 |
|
|
| 130 | 238 |
} |
| 131 |
} |
|
| 132 |
catch (ThreadDeath td) {
|
|
| 133 |
return Status.CANCEL_STATUS; |
|
| 134 |
} |
|
| 135 |
catch (Exception e) {
|
|
| 136 |
System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e)); |
|
| 137 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
| 138 |
return Status.CANCEL_STATUS; |
|
| 139 |
} |
|
| 140 |
finally {
|
|
| 141 | 239 |
monitor.done(); |
| 142 | 240 |
JobsTimer.stopAndPrint(); |
| 241 |
|
|
| 242 |
this.syncExec(new Runnable() {
|
|
| 243 |
|
|
| 244 |
@Override |
|
| 245 |
public void run() {
|
|
| 246 |
|
|
| 247 |
CorporaView.refresh(); |
|
| 248 |
} |
|
| 249 |
}); |
|
| 250 |
return Status.OK_STATUS; |
|
| 143 | 251 |
} |
| 144 |
return Status.OK_STATUS; |
|
| 145 |
} |
|
| 146 |
}; |
|
| 252 |
}; |
|
| 253 |
|
|
| 254 |
jobhandler.startJob(); |
|
| 255 |
} |
|
| 147 | 256 |
|
| 148 |
jobhandler.startJob(); |
|
| 149 | 257 |
} |
| 258 |
catch (Exception e1) {
|
|
| 259 |
// TODO Auto-generated catch block |
|
| 260 |
e1.printStackTrace(); |
|
| 261 |
return null; |
|
| 262 |
} |
|
| 150 | 263 |
return null; |
| 151 | 264 |
} |
| 152 | 265 |
} |
Formats disponibles : Unified diff