Revision 68061e15
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java | ||
---|---|---|
45 | 45 |
import org.eclipse.core.runtime.SubProgressMonitor; |
46 | 46 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
47 | 47 |
import org.eclipse.core.runtime.jobs.Job; |
48 |
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
|
48 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
|
49 | 49 |
import org.eclipse.jface.action.IStatusLineManager; |
50 | 50 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
51 | 51 |
import org.eclipse.jface.resource.ColorRegistry; |
... | ... | |
56 | 56 |
import org.eclipse.swt.graphics.Font; |
57 | 57 |
import org.eclipse.swt.widgets.Display; |
58 | 58 |
import org.eclipse.swt.widgets.Shell; |
59 |
import org.eclipse.ui.IEditorPart; |
|
60 | 59 |
import org.eclipse.ui.IViewPart; |
61 | 60 |
import org.eclipse.ui.IViewReference; |
62 | 61 |
import org.eclipse.ui.IWorkbench; |
63 | 62 |
import org.eclipse.ui.IWorkbenchPage; |
64 |
import org.eclipse.ui.IWorkbenchPart; |
|
65 | 63 |
import org.eclipse.ui.IWorkbenchWindow; |
66 | 64 |
import org.eclipse.ui.PartInitException; |
67 | 65 |
import org.eclipse.ui.PlatformUI; |
... | ... | |
81 | 79 |
import eu.etaxonomy.cdm.io.common.ExportResult; |
82 | 80 |
import eu.etaxonomy.cdm.io.common.ExportResultType; |
83 | 81 |
import eu.etaxonomy.cdm.io.common.ExportType; |
84 |
import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator; |
|
85 | 82 |
import eu.etaxonomy.cdm.model.common.IEnumTerm; |
83 |
import eu.etaxonomy.taxeditor.event.EventUtility; |
|
86 | 84 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
87 | 85 |
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator; |
88 | 86 |
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled; |
... | ... | |
95 | 93 |
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer; |
96 | 94 |
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart; |
97 | 95 |
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart; |
98 |
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
|
96 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
|
99 | 97 |
|
100 | 98 |
/** |
101 | 99 |
* |
... | ... | |
112 | 110 |
/** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */ |
113 | 111 |
public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm"; |
114 | 112 |
|
113 |
public static MPart getActivePart() { |
|
114 |
return EventUtility.getActivePart(); |
|
115 |
} |
|
116 |
|
|
115 | 117 |
public static boolean closeAll() { |
116 | 118 |
if(getActivePage()!=null){ |
117 | 119 |
return getActivePage().closeAllEditors(true); |
... | ... | |
145 | 147 |
} |
146 | 148 |
} |
147 | 149 |
|
148 |
public static IWorkbenchPart getActiveWorkbenchPart() { |
|
149 |
IWorkbenchPage activePage = getActivePage(); |
|
150 |
if(activePage!=null){ |
|
151 |
IWorkbenchPart activePart = activePage.getActivePart(); |
|
152 |
if(activePart!=null){ |
|
153 |
return activePart; |
|
154 |
} |
|
155 |
} |
|
156 |
return null; |
|
157 |
} |
|
158 |
|
|
159 | 150 |
public static Object getActiveE4Part() { |
160 |
IWorkbenchPage activePage = getActivePage(); |
|
161 |
if(activePage!=null){ |
|
162 |
IWorkbenchPart activePart = activePage.getActivePart(); |
|
163 |
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart); |
|
164 |
return e4WrappedPart!=null?e4WrappedPart:activePart; |
|
165 |
} |
|
166 |
return null; |
|
151 |
//TODO merge with getActivePart() |
|
152 |
return getActivePart(); |
|
167 | 153 |
} |
168 | 154 |
|
169 | 155 |
public static IWorkbench getWorkbench() { |
... | ... | |
409 | 395 |
final StringBuilder reportSb = new StringBuilder(); |
410 | 396 |
if (remotingMonitor.getResult() instanceof ExportResult){ |
411 | 397 |
ExportResult result = (ExportResult)remotingMonitor.getResult(); |
412 |
|
|
398 |
|
|
413 | 399 |
reportSb.append(result.createReport()); |
414 |
|
|
400 |
|
|
415 | 401 |
if(!StringUtils.isBlank(reportSb.toString())) { |
416 | 402 |
Display.getDefault().asyncExec(new Runnable() { |
417 | 403 |
@Override |
... | ... | |
424 | 410 |
} |
425 | 411 |
}); |
426 | 412 |
} |
427 |
|
|
413 |
|
|
428 | 414 |
if (urlString != null){ |
429 | 415 |
ExportDataWrapper data = result.getExportData(); |
430 | 416 |
try{ |
... | ... | |
446 | 432 |
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); |
447 | 433 |
Calendar cal = Calendar.getInstance(); |
448 | 434 |
String fileEnding = ".csv"; |
449 |
|
|
450 |
if (createZip){
|
|
451 |
File file = new File(urlString+File.separator + sdf.format(cal.getTime())+ ".zip");
|
|
435 |
|
|
436 |
if (createZip){ |
|
437 |
File file = new File(urlString+File.separator + sdf.format(cal.getTime())+ ".zip"); |
|
452 | 438 |
FileOutputStream stream = new FileOutputStream(file); |
453 | 439 |
ZipOutputStream zos = new ZipOutputStream(stream); |
454 | 440 |
for (String key: keySet){ |
455 | 441 |
byte[] fileData = resultMap.get(key); |
456 |
ZipEntry entry = new ZipEntry( key + fileEnding);
|
|
442 |
ZipEntry entry = new ZipEntry( key + fileEnding); |
|
457 | 443 |
zos.putNextEntry(entry); |
458 | 444 |
zos.write(fileData); |
459 | 445 |
zos.closeEntry(); |
... | ... | |
461 | 447 |
zos.close(); |
462 | 448 |
}else{ |
463 | 449 |
if(result.getExportType().equals(ExportType.DWCA)){ |
464 |
|
|
465 |
File file = new File(urlString);
|
|
450 |
|
|
451 |
File file = new File(urlString); |
|
466 | 452 |
FileOutputStream stream = new FileOutputStream(file); |
467 | 453 |
ZipOutputStream zos = new ZipOutputStream(stream); |
468 | 454 |
for (String key: keySet){ |
469 | 455 |
byte[] fileData = resultMap.get(key); |
470 |
ZipEntry entry = new ZipEntry( key + fileEnding);
|
|
456 |
ZipEntry entry = new ZipEntry( key + fileEnding); |
|
471 | 457 |
zos.putNextEntry(entry); |
472 | 458 |
zos.write(fileData); |
473 | 459 |
zos.closeEntry(); |
... | ... | |
649 | 635 |
return "eu.taxeditor"; |
650 | 636 |
} |
651 | 637 |
|
652 |
public static IEditorPart getActiveEditor() { |
|
653 |
return getActivePage() != null ? getActivePage().getActiveEditor() |
|
654 |
: null; |
|
655 |
} |
|
656 |
|
|
657 | 638 |
public static Object getActiveE4Editor() { |
658 |
//FIXME E4 this can be simplified/removed when fully migrated |
|
659 |
if(getActivePage()!=null){ |
|
660 |
IEditorPart activeEditor = getActivePage().getActiveEditor(); |
|
661 |
Object activePart = getActivePage().getActivePart(); |
|
662 |
if(activeEditor==null){ |
|
663 |
activePart = TaxeditorStorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class).getActivePart(); |
|
664 |
} |
|
665 |
Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart); |
|
666 |
return wrappedPart!=null?wrappedPart:activeEditor; |
|
639 |
MPart activePart = EventUtility.getActivePart(); |
|
640 |
if(activePart!=null && activePart.getObject()!=null |
|
641 |
&& activePart.getObject() instanceof IE4SavablePart){ |
|
642 |
return activePart.getObject(); |
|
667 | 643 |
} |
668 | 644 |
return null; |
669 | 645 |
} |
... | ... | |
899 | 875 |
final boolean cancelable, |
900 | 876 |
final IPostMoniteredOperationEnabled postOp, |
901 | 877 |
final IFeedbackGenerator feedbackGenerator) { |
902 |
|
|
878 |
|
|
903 | 879 |
try{ |
904 | 880 |
// get the remoting monitor the first time to make sure that the |
905 | 881 |
// operation is valid |
Also available in: Unified diff
ref #6925 Set active part in utility class