001 //This file is part of the Attempto Java Packages. 002 //Copyright 2008-2009, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). 003 004 //The Attempto Java Packages is free software: you can redistribute it and/or modify it under the 005 //terms of the GNU Lesser General Public License as published by the Free Software Foundation, 006 //either version 3 of the License, or (at your option) any later version. 007 008 //The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY 009 //WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 //PURPOSE. See the GNU Lesser General Public License for more details. 011 012 //You should have received a copy of the GNU Lesser General Public License along with the Attempto 013 //Java Packages. If not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.acewiki.gui; 016 017 import java.io.IOException; 018 import java.io.OutputStream; 019 020 import nextapp.echo2.app.Alignment; 021 import nextapp.echo2.app.Column; 022 import nextapp.echo2.app.Extent; 023 import nextapp.echo2.app.Font; 024 import nextapp.echo2.app.Grid; 025 import nextapp.echo2.app.Insets; 026 import nextapp.echo2.app.ListBox; 027 import nextapp.echo2.app.Row; 028 import nextapp.echo2.app.event.ActionEvent; 029 import nextapp.echo2.app.event.ActionListener; 030 import nextapp.echo2.app.event.WindowPaneEvent; 031 import nextapp.echo2.app.event.WindowPaneListener; 032 import nextapp.echo2.app.filetransfer.Download; 033 import nextapp.echo2.app.filetransfer.DownloadProvider; 034 import nextapp.echo2.app.layout.GridLayoutData; 035 import ch.uzh.ifi.attempto.acewiki.Wiki; 036 import ch.uzh.ifi.attempto.echocomp.GeneralButton; 037 import ch.uzh.ifi.attempto.echocomp.Label; 038 import ch.uzh.ifi.attempto.echocomp.Style; 039 import ch.uzh.ifi.attempto.echocomp.VSpace; 040 import ch.uzh.ifi.attempto.echocomp.WindowPane; 041 042 /** 043 * This is a window that allows the user to choose from different kinds of file types for 044 * exporting the current knowledge base. 045 * 046 * @author Tobias Kuhn 047 */ 048 public class ExportWindow extends WindowPane implements ActionListener { 049 050 private static final long serialVersionUID = -8594954833738936914L; 051 052 private Wiki wiki; 053 054 private ListBox listBox; 055 056 /** 057 * Creates a new export window. 058 * 059 * @param wiki The wiki instance. 060 */ 061 public ExportWindow(Wiki wiki) { 062 this.wiki = wiki; 063 setTitle("Export"); 064 setTitleFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13))); 065 setModal(true); 066 setWidth(new Extent(420)); 067 setHeight(new Extent(200)); 068 setResizable(false); 069 setMovable(true); 070 setTitleBackground(Style.windowTitleBackground); 071 setStyleName("Default"); 072 073 addWindowPaneListener(new WindowPaneListener() { 074 075 private static final long serialVersionUID = -3897741327122083261L; 076 077 public void windowPaneClosing(WindowPaneEvent e) { 078 actionPerformed(new ActionEvent(ExportWindow.this, "Close")); 079 } 080 081 }); 082 083 Grid grid = new Grid(1); 084 grid.setInsets(new Insets(10, 10, 10, 0)); 085 grid.setColumnWidth(0, new Extent(400)); 086 grid.setRowHeight(0, new Extent(110)); 087 088 Column messageColumn = new Column(); 089 GridLayoutData layout1 = new GridLayoutData(); 090 layout1.setAlignment(new Alignment(Alignment.LEFT, Alignment.TOP)); 091 messageColumn.setLayoutData(layout1); 092 093 Label label = new Label("Choose the type of export from the list:"); 094 label.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13))); 095 messageColumn.add(label); 096 messageColumn.add(new VSpace()); 097 098 listBox = new ListBox(new String[] { 099 "Consistent ACE Text (.ace.txt)", 100 "Full ACE Text (.ace.txt)", 101 "ACE Lexicon (.lex.pl)", 102 "Consistent OWL Ontology (.owl)", 103 "Full OWL Ontology (.owl)" 104 }); 105 listBox.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(11))); 106 listBox.setBackground(Style.lightBackground); 107 listBox.setHeight(new Extent(70)); 108 listBox.setSelectedIndex(0); 109 messageColumn.add(listBox); 110 111 grid.add(messageColumn); 112 113 Row buttonBar = new Row(); 114 buttonBar.setCellSpacing(new Extent(10)); 115 buttonBar.setInsets(new Insets(0, 0, 0, 10)); 116 buttonBar.add(new GeneralButton("Export", 80, this)); 117 buttonBar.add(new GeneralButton("Cancel", 80, this)); 118 GridLayoutData layout2 = new GridLayoutData(); 119 layout2.setAlignment(new Alignment(Alignment.CENTER, Alignment.BOTTOM)); 120 buttonBar.setLayoutData(layout2); 121 grid.add(buttonBar); 122 123 add(grid); 124 } 125 126 public void actionPerformed(ActionEvent e) { 127 setVisible(false); 128 if (e.getActionCommand().equals("Export")) { 129 final String ending; 130 final String content; 131 final String contenttype; 132 String export = listBox.getSelectedValue().toString(); 133 if (export.startsWith("Consistent OWL Ontology")) { 134 ending = ".owl"; 135 contenttype = "application/owl+xml"; 136 content = wiki.getOntology().getOWLOntologyAsXML(true); 137 } else if (export.startsWith("Full OWL Ontology")) { 138 ending = ".owl"; 139 contenttype = "application/owl+xml"; 140 content = wiki.getOntology().getOWLOntologyAsXML(false); 141 } else if (export.startsWith("Consistent ACE Text")) { 142 ending = ".ace.txt"; 143 contenttype = "text/plain"; 144 content = wiki.getOntology().getACEText(true); 145 } else if (export.startsWith("Full ACE Text")) { 146 ending = ".ace.txt"; 147 contenttype = "text/plain"; 148 content = wiki.getOntology().getACEText(false); 149 } else if (export.startsWith("ACE Lexicon")) { 150 ending = ".lex.pl"; 151 contenttype = "text/plain"; 152 content = wiki.getOntology().getLexiconDef(); 153 } else { 154 return; 155 } 156 157 DownloadProvider provider = new DownloadProvider() { 158 159 public String getContentType() { 160 return contenttype; 161 } 162 163 public String getFileName() { 164 return wiki.getOntology().getName() + ending; 165 } 166 167 public int getSize() { 168 return content.length(); 169 } 170 171 public void writeFile(OutputStream out) throws IOException { 172 out.write(content.getBytes()); 173 out.close(); 174 } 175 176 }; 177 178 wiki.getApplication().enqueueCommand(new Download(provider, true)); 179 } 180 } 181 182 }