@@ -0,0 +1,2623 @@
+/*******************************************************************************%0A * Mission Control Technologies, Copyright (c) 2009-2012, United States Government%0A * as represented by the Administrator of the National Aeronautics and Space %0A * Administration. All rights reserved.%0A *%0A * The MCT platform is licensed under the Apache License, Version 2.0 (the %0A * %22License%22); you may not use this file except in compliance with the License. %0A * You may obtain a copy of the License at %0A * http://www.apache.org/licenses/LICENSE-2.0.%0A *%0A * Unless required by applicable law or agreed to in writing, software %0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT %0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the %0A * License for the specific language governing permissions and limitations under %0A * the License.%0A *%0A * MCT includes source code licensed under additional open source licenses. See %0A * the MCT Open Source Licenses file included with this distribution or the About %0A * MCT Licenses dialog available at runtime from the MCT Help menu for additional %0A * information. %0A *******************************************************************************/%0Apackage gov.nasa.arc.mct.scenario.actions;%0A%0Aimport gov.nasa.arc.mct.components.AbstractComponent;%0A%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.io.Writer;%0Aimport java.util.Collection;%0A%0Aimport javax.swing.SwingWorker;%0A%0Apublic class CSVExportWorker extends SwingWorker%3CBoolean, Void%3E %7B%0A%09private Collection%3CAbstractComponent%3E components;%0A%09private File file;%0A%09private IOException ioe;%0A%09%0A%09public CSVExportWorker(Collection%3CAbstractComponent%3E components, File file) %7B%0A%09%09super();%0A%09%09this.components = components;%0A%09%09this.file = file;%0A%09%09%0A%09%09if (components == null %7C%7C file == null %7C%7C components.isEmpty()) %7B%0A%09%09%09throw new IllegalArgumentException();%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09protected Boolean doInBackground() throws Exception %7B%0A%09%09setProgress(0);%0A%09%09%0A%09%09CSVRenderer r = new CSVRenderer(components);%0A%09%09%0A%09%09int rowCount = r.getRowCount();%0A%09%09%0A%09%09Writer w = null;%0A%09%09boolean success = true;%0A%09%09try %7B%0A%09%09%09w = new FileWriter(file);%0A%09%09%09w.write(r.renderHeaders());%0A%09%09%09for (int i = 0; i %3C rowCount; i++) %7B%0A%09%09%09%09setProgress((i * 100) / rowCount);%0A%09%09%09%09w.write(r.renderRow(i));%0A%09%09%09%7D%0A%09%09%7D catch (IOException ioe) %7B%0A%09%09%09success = false;%0A%09%09%09this.ioe = ioe;%09%09%0A%09%09%7D finally %7B%0A%09%09%09if (w != null) %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09w.close();%0A%09%09%09%09%7D catch (IOException ioe) %7B%0A%09%09%09%09%09success = false;%0A%09%09%09%09%09this.ioe = ioe;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09setProgress(100);%0A%09%09%0A%09%09return success;%0A%09%7D%0A%0A%09public IOException getException() %7B%0A%09%09return ioe;%0A%09%7D%0A%7D%0A

Add worker to export CSV in background