2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
12 import java
.io
.FileWriter
;
13 import java
.io
.IOException
;
15 import org
.eclipse
.jface
.dialogs
.Dialog
;
16 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.custom
.StyledText
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.graphics
.Point
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Button
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Control
;
27 import org
.eclipse
.swt
.widgets
.FileDialog
;
28 import org
.eclipse
.swt
.widgets
.MessageBox
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
36 public class ReportTextDialog
extends Dialog
{
38 private String reportText
= "";
39 private String title
= "";
44 public ReportTextDialog(Shell parentShell
) {
49 * Create contents of the dialog.
53 protected Control
createDialogArea(final Composite parent
) {
54 Composite container
= (Composite
) super.createDialogArea(parent
);
55 GridLayout gridLayout
= (GridLayout
) container
.getLayout();
56 gridLayout
.numColumns
= 2;
58 StyledText styledText
= new StyledText(container
, SWT
.BORDER
| SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.BORDER
);
59 styledText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
60 styledText
.setText(reportText
);
62 Button btnSave
= new Button(container
, SWT
.NONE
);
63 btnSave
.addSelectionListener(new SelectionAdapter() {
65 public void widgetSelected(SelectionEvent e
) {
66 FileDialog fileDialog
= new FileDialog(parent
.getShell(), SWT
.SAVE
);
67 // Set filter on .txt files
68 fileDialog
.setFilterExtensions(new String
[] { "*.txt" });
69 // Put in a readable name for the filter
70 fileDialog
.setFilterNames(new String
[] { "Textfiles(*.txt)" });
71 String fileName
= fileDialog
.open();
72 if(fileName
!= null) {
73 File file
= new File(fileName
);
75 MessageBox mb
= new MessageBox(fileDialog
.getParent(), SWT
.ICON_WARNING
77 mb
.setMessage(fileName
+ " already exists. Do you want to replace it?");
78 boolean override
= mb
.open() == SWT
.YES
;
84 FileWriter fileWriter
= new FileWriter(fileName
, false);
85 fileWriter
.write(getReportText());
87 } catch (IOException ioe
) {
88 throw new IllegalStateException(ioe
);
93 btnSave
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false, false, 1, 1));
94 btnSave
.setText("save");
100 * Create contents of the button bar.
104 protected void createButtonsForButtonBar(Composite parent
) {
105 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
, true);
109 protected void configureShell(Shell shell
) {
110 super.configureShell(shell
);
111 shell
.setText(title
);
114 * Return the initial size of the dialog.
117 protected Point
getInitialSize() {
118 return new Point(669, 501);
121 public void setReportText(String text
) {
122 this.reportText
= text
;
125 public String
getReportText() {
129 public void setTitle(String title
) {