Issue #2088 Changes for non-blocking PrintTextReportDlg and TextReportDlg.
Change-Id: I0f999c8334aefb3f2d0e27d91bdea419a96d65e6 Former-commit-id:edb32da7ce
[formerly 648aa82a0d6b10a92a44df55eb278b6cc4c9bc1b] Former-commit-id:6f6da35020
This commit is contained in:
parent
5884bb5692
commit
1dbcb165df
4 changed files with 165 additions and 71 deletions
|
@ -22,6 +22,9 @@
|
|||
*/
|
||||
package com.raytheon.viz.hydro.textreport;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
@ -30,6 +33,7 @@ import org.eclipse.ui.PlatformUI;
|
|||
|
||||
import com.raytheon.viz.hydrocommon.HydroDisplayManager;
|
||||
import com.raytheon.viz.hydrocommon.textreport.TextReportDlg;
|
||||
import com.raytheon.viz.ui.dialogs.ICloseCallback;
|
||||
|
||||
/**
|
||||
* Action for unimplemented features. To be used temporarily until final
|
||||
|
@ -42,6 +46,7 @@ import com.raytheon.viz.hydrocommon.textreport.TextReportDlg;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* 6/27/06 lvenable Initial Creation.
|
||||
* 7/15/2013 2088 rferrel Changes for non-blocking TextReportDlg.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -49,19 +54,36 @@ import com.raytheon.viz.hydrocommon.textreport.TextReportDlg;
|
|||
*
|
||||
*/
|
||||
public class TextReportAction extends AbstractHandler {
|
||||
private final Map<String, TextReportDlg> dataSourcesDlgMap = new HashMap<String, TextReportDlg>();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getShell();
|
||||
|
||||
|
||||
/* Check for selected lid */
|
||||
if (HydroDisplayManager.getInstance().isCurrentLidSelected(shell)) {
|
||||
|
||||
|
||||
/* If site selected get lid and launch the dialog */
|
||||
String lid = HydroDisplayManager.getInstance().getCurrentLid();
|
||||
TextReportDlg dataSourcesDlg = new TextReportDlg(shell, lid);
|
||||
dataSourcesDlg.open();
|
||||
TextReportDlg dataSourcesDlg = dataSourcesDlgMap.get(lid);
|
||||
if (dataSourcesDlg == null || dataSourcesDlg.isDisposed()) {
|
||||
dataSourcesDlg = new TextReportDlg(shell, lid);
|
||||
dataSourcesDlg.setCloseCallback(new ICloseCallback() {
|
||||
|
||||
@Override
|
||||
public void dialogClosed(Object returnValue) {
|
||||
if (returnValue instanceof String) {
|
||||
String lid = returnValue.toString();
|
||||
dataSourcesDlgMap.remove(lid);
|
||||
}
|
||||
}
|
||||
});
|
||||
dataSourcesDlg.open();
|
||||
dataSourcesDlgMap.put(lid, dataSourcesDlg);
|
||||
} else {
|
||||
dataSourcesDlg.bringToTop();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -166,6 +166,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
|
|||
* Changes for non-blocking ImpactStatementDlg.
|
||||
* Changes for non-blocking LowWaterStatementDlg.
|
||||
* Changes for non-blocking RatingCurveDlg.
|
||||
* Changes for non-blocking TextReportDlg.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -358,6 +359,11 @@ public class HydroBaseDlg extends CaveSWTDialog implements IGetSortType,
|
|||
*/
|
||||
private final Map<String, RatingCurveDlg> ratingCurveDlgMap = new HashMap<String, RatingCurveDlg>();
|
||||
|
||||
/**
|
||||
* Allow one instance per station.
|
||||
*/
|
||||
private final Map<String, TextReportDlg> textReportDlgMap = new HashMap<String, TextReportDlg>();
|
||||
|
||||
/**
|
||||
* Flood category menu item.
|
||||
*/
|
||||
|
@ -1422,15 +1428,36 @@ public class HydroBaseDlg extends CaveSWTDialog implements IGetSortType,
|
|||
textReportsMI.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
String lid = dataList.getItem(dataList.getSelectionIndex())
|
||||
.trim();
|
||||
TextReportDlg textReportDlg = new TextReportDlg(shell, lid
|
||||
.substring(0, lid.indexOf(" ")));
|
||||
textReportDlg.open();
|
||||
handleTextReportDlg();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Text report dialog for the selected station.
|
||||
*/
|
||||
private void handleTextReportDlg() {
|
||||
String lid = getStationLid();
|
||||
TextReportDlg textReportDlg = textReportDlgMap.get(lid);
|
||||
if (textReportDlg == null || textReportDlg.isDisposed()) {
|
||||
textReportDlg = new TextReportDlg(shell, lid);
|
||||
textReportDlg.setCloseCallback(new ICloseCallback() {
|
||||
|
||||
@Override
|
||||
public void dialogClosed(Object returnValue) {
|
||||
if (returnValue instanceof String) {
|
||||
String lid = returnValue.toString();
|
||||
textReportDlgMap.remove(lid);
|
||||
}
|
||||
}
|
||||
});
|
||||
textReportDlg.open();
|
||||
textReportDlgMap.put(lid, textReportDlg);
|
||||
} else {
|
||||
textReportDlg.bringToTop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Setup menu.
|
||||
*
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
**/
|
||||
package com.raytheon.viz.hydrocommon.textreport;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
|
@ -38,6 +42,7 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
||||
|
||||
/**
|
||||
* generic print menu for reports.
|
||||
*
|
||||
|
@ -47,6 +52,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 11, 2012 13781 wkwock Initial creation
|
||||
* Jul 16, 2013 2088 rferrel Make dialog non-blocking.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -58,7 +64,6 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
/**
|
||||
* Text viewer.
|
||||
*/
|
||||
|
||||
protected TextReport report;
|
||||
|
||||
/* Vars used in the printing methods */
|
||||
|
@ -80,21 +85,34 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
|
||||
private int index, end;
|
||||
|
||||
private StringBuffer wordBuffer;
|
||||
private final StringBuilder wordBuffer = new StringBuilder();
|
||||
|
||||
private GC gc;
|
||||
|
||||
|
||||
protected PrintTextReportDlg(Shell parentShell,TextReport report) {
|
||||
super(parentShell);
|
||||
this.report=report;
|
||||
}
|
||||
/**
|
||||
* A non-blocking modal constructor so user cannot change report while
|
||||
* dialog is open.
|
||||
*
|
||||
* @param parentShell
|
||||
* @param report
|
||||
*/
|
||||
protected PrintTextReportDlg(Shell parentShell, TextReport report) {
|
||||
super(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL,
|
||||
CAVE.DO_NOT_BLOCK);
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeComponents(Shell shell) {
|
||||
// TODO Auto-generated method stub
|
||||
createBottomButtons();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org
|
||||
* .eclipse.swt.widgets.Shell)
|
||||
*/
|
||||
@Override
|
||||
protected void initializeComponents(Shell shell) {
|
||||
createBottomButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the text to the printer
|
||||
|
@ -109,20 +127,17 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
Rectangle clientArea = printer.getClientArea();
|
||||
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
|
||||
Point dpi = printer.getDPI();
|
||||
leftMargin = dpi.x + trim.x; // one inch from left side of paper
|
||||
// one inch from left side of paper
|
||||
leftMargin = dpi.x + trim.x;
|
||||
// one inch from right side of paper
|
||||
rightMargin = clientArea.width - dpi.x + trim.x + trim.width;
|
||||
topMargin = dpi.y + trim.y; // one inch from top edge of paper
|
||||
// one inch from top edge of paper
|
||||
topMargin = dpi.y + trim.y;
|
||||
// one inch from bottom edge of paper
|
||||
bottomMargin = clientArea.height - dpi.y + trim.y + trim.height;
|
||||
|
||||
/* Create a buffer for computing tab width. */
|
||||
int tabSize = 4; // is tab width a user setting in your UI?
|
||||
StringBuffer tabBuffer = new StringBuffer(tabSize);
|
||||
for (int i = 0; i < tabSize; i++) {
|
||||
tabBuffer.append(' ');
|
||||
}
|
||||
String tabs = tabBuffer.toString();
|
||||
// Create a buffer for computing tab with width of 4.
|
||||
String tabs = " ";
|
||||
|
||||
/*
|
||||
* Create printer GC, and create and set the printer font &
|
||||
|
@ -163,7 +178,7 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
*/
|
||||
private void printText(String text) {
|
||||
printer.startPage();
|
||||
wordBuffer = new StringBuffer();
|
||||
wordBuffer.setLength(0);
|
||||
x = leftMargin;
|
||||
y = topMargin;
|
||||
index = 0;
|
||||
|
@ -196,6 +211,7 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
printer.endPage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Word buffer for formating lines on the printed page
|
||||
*/
|
||||
|
@ -209,7 +225,7 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
}
|
||||
gc.drawString(word, x, y, false);
|
||||
x += wordWidth;
|
||||
wordBuffer = new StringBuffer();
|
||||
wordBuffer.setLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,15 +243,16 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get data for selected contents for printing
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getPrintData () {
|
||||
return "";
|
||||
protected String getPrintData() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the buttons at the bottom of the display.
|
||||
*/
|
||||
|
@ -254,7 +271,7 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
closeBtn.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
shell.dispose();
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -282,15 +299,18 @@ public class PrintTextReportDlg extends CaveSWTDialog {
|
|||
* Do the printing in a background thread so that spooling
|
||||
* does not freeze the UI.
|
||||
*/
|
||||
Thread printingThread = new Thread("PrintTable") {
|
||||
Job job = new Job("PrintTable") {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
print(printer, text);
|
||||
printer.dispose();
|
||||
printer = null;
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
printingThread.start();
|
||||
|
||||
};
|
||||
job.schedule();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -59,6 +59,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
|||
* Dec 16, 2008 1787 askripsk Started report generation.
|
||||
* Sep 23, 2009 2260 mpduff Finished the dialog,
|
||||
* Aug 20, 2012 13781 wkwock Added print menu for 6 text reports
|
||||
* Jul 16, 2013 2088 rferrel Make dialog non-blocking.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -102,7 +103,7 @@ public class TextReportDlg extends CaveSWTDialog {
|
|||
private TextReport report;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Non-blocking Constructor.
|
||||
*
|
||||
* @param parent
|
||||
* Parent shell.
|
||||
|
@ -110,19 +111,31 @@ public class TextReportDlg extends CaveSWTDialog {
|
|||
* Station ID.
|
||||
*/
|
||||
public TextReportDlg(Shell parent, String stationId) {
|
||||
super(parent);
|
||||
super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK);
|
||||
|
||||
this.stationId = stationId;
|
||||
setReturnValue(stationId);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed()
|
||||
*/
|
||||
@Override
|
||||
protected void disposed() {
|
||||
controlFont.dispose();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org
|
||||
* .eclipse.swt.widgets.Shell)
|
||||
*/
|
||||
@Override
|
||||
protected void initializeComponents(Shell shell) {
|
||||
setReturnValue(false);
|
||||
controlFont = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL);
|
||||
|
||||
// Initialize all of the controls and layouts
|
||||
|
@ -277,7 +290,7 @@ public class TextReportDlg extends CaveSWTDialog {
|
|||
closeBtn.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
shell.dispose();
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -370,31 +383,43 @@ public class TextReportDlg extends CaveSWTDialog {
|
|||
Button printBtn = new Button(btnComp, SWT.PUSH);
|
||||
printBtn.setText("Print");
|
||||
printBtn.setLayoutData(gd);
|
||||
final TextReportDlg txtRptDlg=this;
|
||||
final TextReportDlg txtRptDlg = this;
|
||||
printBtn.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if (report.getClass().getName().equals(E19Report.class.getName())){
|
||||
PrintE19TextReportDlg ptr = new PrintE19TextReportDlg(shell,(E19Report)report);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName().equals(E19AReport.class.getName())) {
|
||||
PrintE19ATextReportDlg ptr = new PrintE19ATextReportDlg(shell,(E19AReport)report);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName().equals(B44AReport.class.getName())) {
|
||||
PrintB44ATextReportDlg ptr = new PrintB44ATextReportDlg(shell,(B44AReport)report);
|
||||
ptr.open();
|
||||
}else if (report.getClass().getName().equals(ServiceBackupReport.class.getName())) {
|
||||
PrintSvcBkTextReportDlg ptr = new PrintSvcBkTextReportDlg(shell,(ServiceBackupReport)report);
|
||||
ptr.setTextReportDlg(txtRptDlg);
|
||||
ptr.open();
|
||||
}else if (report.getClass().getName().equals(StationClassReport.class.getName())) {
|
||||
PrintStnClassTextReportDlg ptr = new PrintStnClassTextReportDlg(shell,(StationClassReport)report);
|
||||
ptr.open();
|
||||
}else if (report.getClass().getName().equals(StationListReport.class.getName())) {
|
||||
PrintSortedStnTextReportDlg ptr = new PrintSortedStnTextReportDlg(shell,(StationListReport)report);
|
||||
ptr.setTextReportDlg(txtRptDlg);
|
||||
ptr.open();
|
||||
}
|
||||
if (report.getClass().getName()
|
||||
.equals(E19Report.class.getName())) {
|
||||
PrintE19TextReportDlg ptr = new PrintE19TextReportDlg(
|
||||
shell, (E19Report) report);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName()
|
||||
.equals(E19AReport.class.getName())) {
|
||||
PrintE19ATextReportDlg ptr = new PrintE19ATextReportDlg(
|
||||
shell, (E19AReport) report);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName()
|
||||
.equals(B44AReport.class.getName())) {
|
||||
PrintB44ATextReportDlg ptr = new PrintB44ATextReportDlg(
|
||||
shell, (B44AReport) report);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName()
|
||||
.equals(ServiceBackupReport.class.getName())) {
|
||||
PrintSvcBkTextReportDlg ptr = new PrintSvcBkTextReportDlg(
|
||||
shell, (ServiceBackupReport) report);
|
||||
ptr.setTextReportDlg(txtRptDlg);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName()
|
||||
.equals(StationClassReport.class.getName())) {
|
||||
PrintStnClassTextReportDlg ptr = new PrintStnClassTextReportDlg(
|
||||
shell, (StationClassReport) report);
|
||||
ptr.open();
|
||||
} else if (report.getClass().getName()
|
||||
.equals(StationListReport.class.getName())) {
|
||||
PrintSortedStnTextReportDlg ptr = new PrintSortedStnTextReportDlg(
|
||||
shell, (StationListReport) report);
|
||||
ptr.setTextReportDlg(txtRptDlg);
|
||||
ptr.open();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -411,12 +436,12 @@ public class TextReportDlg extends CaveSWTDialog {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* The index for page.
|
||||
*/
|
||||
public int getPageSelectionIndex () {
|
||||
return this.pageCbo.getSelectionIndex();
|
||||
public int getPageSelectionIndex() {
|
||||
return this.pageCbo.getSelectionIndex();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Event handler for Report combobox. This populates the page combobox and
|
||||
* displays the report
|
||||
|
|
Loading…
Add table
Reference in a new issue