Révision 1650
| tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/CQPSearchEngine.java (revision 1650) | ||
|---|---|---|
| 356 | 356 |
Log.severe("Error while closing CQP: "+e.getLocalizedMessage());
|
| 357 | 357 |
return false; |
| 358 | 358 |
} |
| 359 |
return true;
|
|
| 359 |
return !state;
|
|
| 360 | 360 |
} |
| 361 | 361 |
|
| 362 | 362 |
/** |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/utils/SWTEditorsUtils.java (revision 1650) | ||
|---|---|---|
| 4 | 4 |
package org.txm.rcp.utils; |
| 5 | 5 |
|
| 6 | 6 |
import java.util.ArrayList; |
| 7 |
import java.util.HashSet; |
|
| 7 | 8 |
|
| 8 | 9 |
import org.eclipse.core.commands.ExecutionEvent; |
| 9 | 10 |
import org.eclipse.e4.ui.model.application.ui.MUIElement; |
| ... | ... | |
| 65 | 66 |
* @return all opened editors if there is at least one otherwise returns an empty list |
| 66 | 67 |
*/ |
| 67 | 68 |
public static ArrayList<TXMEditor> getEditors() {
|
| 68 |
return getEditors(null); |
|
| 69 |
ArrayList<TXMEditor> editors = new ArrayList<TXMEditor>(); |
|
| 70 |
|
|
| 71 |
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); |
|
| 72 |
for (IWorkbenchWindow window : windows) {
|
|
| 73 |
IWorkbenchPage[] pages = window.getPages(); |
|
| 74 |
for (IWorkbenchPage page : pages) {
|
|
| 75 |
for (IEditorReference reference : page.getEditorReferences()) {
|
|
| 76 |
IEditorPart tmpEditor = reference.getEditor(false); |
|
| 77 |
|
|
| 78 |
if(tmpEditor instanceof TXMEditor) {
|
|
| 79 |
editors.add((TXMEditor) tmpEditor); |
|
| 80 |
} |
|
| 81 |
else if(tmpEditor instanceof TXMMultiPageEditor) {
|
|
| 82 |
TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor)tmpEditor); |
|
| 83 |
for (int i = 0; i < txmMultipageEditor.getEditors().size(); i++) {
|
|
| 84 |
if(txmMultipageEditor.getEditors().get(i) instanceof TXMEditor) {
|
|
| 85 |
TXMEditor txmEditor = ((TXMEditor)txmMultipageEditor.getEditors().get(i)); |
|
| 86 |
editors.add(txmEditor); |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
} |
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
return editors; |
|
| 69 | 94 |
} |
| 70 | 95 |
|
| 96 |
|
|
| 71 | 97 |
/** |
| 72 | 98 |
* Gets all opened editors for the specified result. |
| 73 | 99 |
* @param result |
| 74 | 100 |
* @return all opened editors for the specified result if there is at least one otherwise returns an empty list |
| 75 | 101 |
*/ |
| 102 |
public static ArrayList<TXMEditor> getEditors(HashSet<TXMResult> results) {
|
|
| 103 |
|
|
| 104 |
ArrayList<TXMEditor> editors = new ArrayList<TXMEditor>(); |
|
| 105 |
|
|
| 106 |
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); |
|
| 107 |
for (IWorkbenchWindow window : windows) {
|
|
| 108 |
IWorkbenchPage[] pages = window.getPages(); |
|
| 109 |
for (IWorkbenchPage page : pages) {
|
|
| 110 |
for (IEditorReference reference : page.getEditorReferences()) {
|
|
| 111 |
IEditorPart tmpEditor = reference.getEditor(false); |
|
| 112 |
|
|
| 113 |
if(tmpEditor instanceof TXMEditor && results.contains(((TXMEditor)tmpEditor).getResult())) {
|
|
| 114 |
editors.add((TXMEditor) tmpEditor); |
|
| 115 |
} |
|
| 116 |
else if(tmpEditor instanceof TXMMultiPageEditor) {
|
|
| 117 |
TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor)tmpEditor); |
|
| 118 |
for (int i = 0; i < txmMultipageEditor.getEditors().size(); i++) {
|
|
| 119 |
if(txmMultipageEditor.getEditors().get(i) instanceof TXMEditor) {
|
|
| 120 |
TXMEditor txmEditor = ((TXMEditor)txmMultipageEditor.getEditors().get(i)); |
|
| 121 |
if(results.contains(((TXMEditor)tmpEditor).getResult())) {
|
|
| 122 |
editors.add(txmEditor); |
|
| 123 |
} |
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
} |
|
| 127 |
} |
|
| 128 |
} |
|
| 129 |
} |
|
| 130 |
|
|
| 131 |
return editors; |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
/** |
|
| 135 |
* Gets all opened editors for the specified result. |
|
| 136 |
* @param result |
|
| 137 |
* @return all opened editors for the specified result if there is at least one otherwise returns an empty list |
|
| 138 |
*/ |
|
| 76 | 139 |
public static ArrayList<TXMEditor> getEditors(TXMResult result) {
|
| 77 | 140 |
|
| 78 | 141 |
ArrayList<TXMEditor> editors = new ArrayList<TXMEditor>(); |
| ... | ... | |
| 103 | 166 |
} |
| 104 | 167 |
|
| 105 | 168 |
return editors; |
| 106 |
|
|
| 107 | 169 |
} |
| 108 | 170 |
|
| 109 | 171 |
/** |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/results/DeleteObject.java (revision 1650) | ||
|---|---|---|
| 79 | 79 |
|
| 80 | 80 |
private static boolean continueToDelete = true; |
| 81 | 81 |
|
| 82 |
|
|
| 82 |
|
|
| 83 | 83 |
/* (non-Javadoc) |
| 84 | 84 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
| 85 | 85 |
*/ |
| ... | ... | |
| 87 | 87 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
| 88 | 88 |
|
| 89 | 89 |
final IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
| 90 |
|
|
| 90 |
|
|
| 91 | 91 |
if (!askContinueToDelete(selection)) {
|
| 92 | 92 |
return null; |
| 93 | 93 |
} |
| 94 |
|
|
| 94 |
|
|
| 95 | 95 |
JobHandler job = new JobHandler("Deleting", true) {
|
| 96 | 96 |
@Override |
| 97 | 97 |
protected IStatus run(IProgressMonitor monitor) {
|
| ... | ... | |
| 116 | 116 |
*/ |
| 117 | 117 |
public static synchronized boolean askContinueToDelete(final IStructuredSelection selection) {
|
| 118 | 118 |
continueToDelete = true; |
| 119 |
|
|
| 119 |
|
|
| 120 | 120 |
boolean showAlert = !RCPPreferences.getInstance().getBoolean(RCPPreferences.USER_ALERT_DELETE); |
| 121 |
|
|
| 121 |
|
|
| 122 | 122 |
if (showAlert) {
|
| 123 | 123 |
Display.getDefault().syncExec(new Runnable() {
|
| 124 | 124 |
@Override |
| ... | ... | |
| 135 | 135 |
} |
| 136 | 136 |
return continueToDelete; |
| 137 | 137 |
} |
| 138 |
|
|
| 138 |
|
|
| 139 | 139 |
/** |
| 140 | 140 |
* Deletes. |
| 141 | 141 |
* |
| ... | ... | |
| 143 | 143 |
*/ |
| 144 | 144 |
public static HashSet<Object> delete(ISelection sel) {
|
| 145 | 145 |
IStructuredSelection selection = (IStructuredSelection) sel; |
| 146 |
|
|
| 146 |
|
|
| 147 | 147 |
if (selection.size() == 0) {
|
| 148 | 148 |
return new HashSet<Object>(); |
| 149 | 149 |
} |
| 150 |
|
|
| 150 |
|
|
| 151 | 151 |
HashSet<Object> objects = new HashSet<Object>(selection.toList()); |
| 152 | 152 |
HashSet<Object> hidden = new HashSet<Object>(); |
| 153 | 153 |
for (Object o : objects) {
|
| ... | ... | |
| 163 | 163 |
objects.addAll(hidden); |
| 164 | 164 |
return delete(new ArrayList<Object>(objects)); |
| 165 | 165 |
} |
| 166 |
|
|
| 167 | 166 |
|
| 167 |
|
|
| 168 | 168 |
/** |
| 169 | 169 |
* Deletes. |
| 170 | 170 |
* |
| ... | ... | |
| 175 | 175 |
*/ |
| 176 | 176 |
public synchronized static HashSet<Object> delete(final List<Object> objects) {
|
| 177 | 177 |
StatusLine.setMessage(NLS.bind(TXMUIMessages.deletingP0, objects)); |
| 178 |
|
|
| 178 |
|
|
| 179 | 179 |
final HashSet<Object> allObjectDeleted = new HashSet<Object>(); |
| 180 | 180 |
shouldRestartToolbox = false; |
| 181 | 181 |
while (objects.size() > 0) {
|
| ... | ... | |
| 196 | 196 |
return new HashSet<Object>(); |
| 197 | 197 |
} |
| 198 | 198 |
} |
| 199 |
|
|
| 199 |
|
|
| 200 | 200 |
if (allObjectDeleted.size() > 0) {
|
| 201 |
|
|
| 201 |
|
|
| 202 | 202 |
if (shouldRestartToolbox) {
|
| 203 |
// org.txm.Toolbox.restartWorkspace(null); |
|
| 203 |
// org.txm.Toolbox.restartWorkspace(null);
|
|
| 204 | 204 |
Toolbox.getEngineManager(EngineType.SEARCH).restartEngines(); |
| 205 |
|
|
| 205 |
|
|
| 206 | 206 |
Log.info(TXMUIMessages.info_txmIsReady); |
| 207 | 207 |
StatusLine.setMessage(TXMUIMessages.info_txmIsReady); |
| 208 | 208 |
} |
| 209 |
|
|
| 209 |
|
|
| 210 | 210 |
Display.getDefault().syncExec(new Runnable() {
|
| 211 | 211 |
@Override |
| 212 | 212 |
public void run() {
|
| 213 | 213 |
try {
|
| 214 | 214 |
// FIXME: why this is commented? became useless? I needed to add the line below for the refresh CorporaView.refresh(); |
| 215 |
// RestartTXM.reloadViews(); |
|
| 216 |
|
|
| 215 |
// RestartTXM.reloadViews();
|
|
| 216 |
|
|
| 217 | 217 |
CorporaView.refresh(); |
| 218 |
|
|
| 218 |
|
|
| 219 | 219 |
//close corresponding editors |
| 220 | 220 |
for(Object obj : allObjectDeleted) {
|
| 221 | 221 |
closeEditorOfSelection(obj); |
| ... | ... | |
| 241 | 241 |
// FIXME: when TXMResult will be implemented, remove all unused code |
| 242 | 242 |
public static List<Object> delete(Object o) {
|
| 243 | 243 |
ArrayList<Object> deleted = new ArrayList<Object>(); |
| 244 |
// if (o instanceof TXMResult) {
|
|
| 245 |
// Log.info(NLS.bind(TXMUIMessages.deletedColonP0, ((TXMResult) o).getName())); |
|
| 246 |
// |
|
| 247 |
// try {
|
|
| 248 |
// if (o instanceof CQPCorpus) {
|
|
| 249 |
// CQPCorpus c = (CQPCorpus)o; |
|
| 250 |
// if (o instanceof MainCorpus) {
|
|
| 251 |
// shouldRestartToolbox = true; |
|
| 252 |
// } |
|
| 253 |
// deleted.addAll(c.clearResults()); |
|
| 254 |
// deleted.addAll(c.getSubcorpora()); |
|
| 255 |
// deleted.addAll(c.getPartitions()); |
|
| 256 |
// |
|
| 257 |
// if (!((TXMResult) o).delete()) {
|
|
| 258 |
// Log.info(TXMUIMessages.errorColonDeleteReturnedFalse); |
|
| 259 |
// return new ArrayList<Object>(0); |
|
| 260 |
// } |
|
| 261 |
// } else if (o instanceof Partition) {
|
|
| 262 |
// Partition p = (Partition)o; |
|
| 263 |
// for (int i = 0 ; i < p.getChildren().size() ; i++) {
|
|
| 264 |
// deleted.addAll(delete(p.getChildren().get(i))); |
|
| 265 |
// i--; |
|
| 266 |
// } |
|
| 267 |
// if (!((TXMResult) o).delete()) {
|
|
| 268 |
// Log.info(TXMUIMessages.errorColonDeleteReturnedFalse); |
|
| 269 |
// return new ArrayList<Object>(0); |
|
| 270 |
// } |
|
| 271 |
// } |
|
| 272 |
// } catch (Exception e) {
|
|
| 273 |
// org.txm.utils.logger.Log.printStackTrace(e); |
|
| 274 |
// } |
|
| 275 |
// } |
|
| 276 |
// // FIXME: when TXMResult will be implemented, only this code must be left |
|
| 244 |
// if (o instanceof TXMResult) {
|
|
| 245 |
// Log.info(NLS.bind(TXMUIMessages.deletedColonP0, ((TXMResult) o).getName()));
|
|
| 246 |
//
|
|
| 247 |
// try {
|
|
| 248 |
// if (o instanceof CQPCorpus) {
|
|
| 249 |
// CQPCorpus c = (CQPCorpus)o;
|
|
| 250 |
// if (o instanceof MainCorpus) {
|
|
| 251 |
// shouldRestartToolbox = true;
|
|
| 252 |
// }
|
|
| 253 |
// deleted.addAll(c.clearResults());
|
|
| 254 |
// deleted.addAll(c.getSubcorpora());
|
|
| 255 |
// deleted.addAll(c.getPartitions());
|
|
| 256 |
//
|
|
| 257 |
// if (!((TXMResult) o).delete()) {
|
|
| 258 |
// Log.info(TXMUIMessages.errorColonDeleteReturnedFalse);
|
|
| 259 |
// return new ArrayList<Object>(0);
|
|
| 260 |
// }
|
|
| 261 |
// } else if (o instanceof Partition) {
|
|
| 262 |
// Partition p = (Partition)o;
|
|
| 263 |
// for (int i = 0 ; i < p.getChildren().size() ; i++) {
|
|
| 264 |
// deleted.addAll(delete(p.getChildren().get(i)));
|
|
| 265 |
// i--;
|
|
| 266 |
// }
|
|
| 267 |
// if (!((TXMResult) o).delete()) {
|
|
| 268 |
// Log.info(TXMUIMessages.errorColonDeleteReturnedFalse);
|
|
| 269 |
// return new ArrayList<Object>(0);
|
|
| 270 |
// }
|
|
| 271 |
// }
|
|
| 272 |
// } catch (Exception e) {
|
|
| 273 |
// org.txm.utils.logger.Log.printStackTrace(e);
|
|
| 274 |
// }
|
|
| 275 |
// }
|
|
| 276 |
// // FIXME: when TXMResult will be implemented, only this code must be left
|
|
| 277 | 277 |
if (o instanceof TXMResult) {
|
| 278 | 278 |
TXMResult r = (TXMResult)o; |
| 279 | 279 |
if (r.isLocked()) return deleted; |
| 280 |
|
|
| 280 |
|
|
| 281 | 281 |
if (r instanceof MainCorpus) {
|
| 282 | 282 |
Project p = ((MainCorpus)o).getProject(); |
| 283 | 283 |
if (p != null) {
|
| ... | ... | |
| 294 | 294 |
else {
|
| 295 | 295 |
Log.severe(TXMCoreMessages.bind("Can not delete: {0}.", o));
|
| 296 | 296 |
} |
| 297 |
|
|
| 297 |
|
|
| 298 | 298 |
return deleted; |
| 299 | 299 |
} |
| 300 | 300 |
|
| ... | ... | |
| 304 | 304 |
* @param o the object used by an editor |
| 305 | 305 |
*/ |
| 306 | 306 |
public static void closeEditorOfSelection(Object o) {
|
| 307 |
for (IWorkbenchPage page : getPages()) {
|
|
| 308 |
for (IEditorReference editorref : page.getEditorReferences()) {
|
|
| 309 |
IEditorPart editor = editorref.getEditor(false); |
|
| 310 | 307 |
|
| 311 |
if(editor instanceof TXMEditor) {
|
|
| 312 |
if (o == ((TXMEditor)editor).getResult()) {
|
|
| 313 |
editor.getEditorSite().getPage().closeEditor(editor, true); |
|
| 308 |
TXMResult r = (TXMResult) o; |
|
| 309 |
List<TXMResult> all = r.getDeepChildren(); |
|
| 310 |
all.add(r); |
|
| 311 |
|
|
| 312 |
//FIXME use SWTEditorsUtils.getEditors() |
|
| 313 |
for (TXMResult tr : all) { // close editors of the result and its children
|
|
| 314 |
for (IWorkbenchPage page : getPages()) {
|
|
| 315 |
for (IEditorReference editorref : page.getEditorReferences()) {
|
|
| 316 |
IEditorPart editor = editorref.getEditor(false); |
|
| 317 |
|
|
| 318 |
if(editor instanceof TXMEditor && o instanceof TXMResult) {
|
|
| 319 |
|
|
| 320 |
if (tr == ((TXMEditor)editor).getResult()) {
|
|
| 321 |
editor.getEditorSite().getPage().closeEditor(editor, true); |
|
| 322 |
} |
|
| 314 | 323 |
} |
| 315 | 324 |
} |
| 316 |
|
|
| 317 | 325 |
} |
| 318 | 326 |
} |
| 319 | 327 |
} |
Formats disponibles : Unified diff