3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
13 import java
.io
.FileWriter
;
14 import java
.io
.IOException
;
16 import org
.eclipse
.jface
.dialogs
.Dialog
;
17 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.custom
.StyledText
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.graphics
.Point
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.FileDialog
;
29 import org
.eclipse
.swt
.widgets
.MessageBox
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
37 public class ReportTextDialog
extends Dialog
{
39 private String reportText
= "";
40 private String title
= "";
45 public ReportTextDialog(Shell parentShell
) {
50 * Create contents of the dialog.
54 protected Control
createDialogArea(final Composite parent
) {
55 Composite container
= (Composite
) super.createDialogArea(parent
);
56 GridLayout gridLayout
= (GridLayout
) container
.getLayout();
57 gridLayout
.numColumns
= 2;
59 StyledText styledText
= new StyledText(container
, SWT
.BORDER
| SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.BORDER
);
60 styledText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
61 styledText
.setText(reportText
);
63 Button btnSave
= new Button(container
, SWT
.NONE
);
64 btnSave
.addSelectionListener(new SelectionAdapter() {
66 public void widgetSelected(SelectionEvent e
) {
67 FileDialog fileDialog
= new FileDialog(parent
.getShell(), SWT
.SAVE
);
68 // Set filter on .txt files
69 fileDialog
.setFilterExtensions(new String
[] { "*.txt" });
70 // Put in a readable name for the filter
71 fileDialog
.setFilterNames(new String
[] { "Textfiles(*.txt)" });
72 String fileName
= fileDialog
.open();
73 System
.out
.println("File Name : " + fileName
);
74 if(fileName
!= null) {
75 File file
= new File(fileName
);
77 MessageBox mb
= new MessageBox(fileDialog
.getParent(), SWT
.ICON_WARNING
79 mb
.setMessage(fileName
+ " already exists. Do you want to replace it?");
80 boolean override
= mb
.open() == SWT
.YES
;
86 FileWriter fileWriter
= new FileWriter(fileName
, false);
87 fileWriter
.write(getReportText());
89 } catch (IOException ioe
) {
90 throw new IllegalStateException(ioe
);
95 btnSave
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false, false, 1, 1));
96 btnSave
.setText("save");
102 * Create contents of the button bar.
106 protected void createButtonsForButtonBar(Composite parent
) {
107 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
, true);
111 protected void configureShell(Shell shell
) {
112 super.configureShell(shell
);
113 shell
.setText(title
);
116 * Return the initial size of the dialog.
119 protected Point
getInitialSize() {
120 return new Point(669, 501);
123 public void setReportText(String text
) {
124 this.reportText
= text
;
127 public String
getReportText() {
131 public void setTitle(String title
) {