Search in sources :

Example 11 with MessageDialogFactory

use of com.att.aro.ui.commonui.MessageDialogFactory in project VideoOptimzer by attdevsupport.

the class DataDump method showSaveChooser.

/**
 * Initiates the save chooser options and creates a file.
 */
private boolean showSaveChooser() {
    final String fileExtention = ResourceBundleHelper.getMessageString(MessageItem.fileChooser_contentType_json);
    JFileChooser chooser = new JFileChooser(userPreferences.getLastExportDirectory());
    FileNameExtensionFilter ff;
    ff = new FileNameExtensionFilter(ResourceBundleHelper.getMessageString(MessageItem.fileChooser_desc_json), fileExtention);
    chooser.addChoosableFileFilter(ff);
    chooser.setFileFilter(ff);
    chooser.setDialogTitle(ResourceBundleHelper.getMessageString(MessageItem.fileChooser_Title));
    chooser.setApproveButtonText(ResourceBundleHelper.getMessageString(MessageItem.fileChooser_Save));
    chooser.setMultiSelectionEnabled(false);
    if (chooser.showSaveDialog(MSG_WINDOW) != JFileChooser.APPROVE_OPTION) {
        return false;
    }
    fileToSave = chooser.getSelectedFile();
    if (fileToSave.getName().length() >= FILE_NAME_MAX_LENGTH) {
        new MessageDialogFactory().showErrorDialog(MSG_WINDOW, ResourceBundleHelper.getMessageString(MessageItem.exportall_errorLongFileName));
        return false;
    }
    if (!chooser.getFileFilter().accept(fileToSave)) {
        fileToSave = new File(fileToSave.getAbsolutePath() + "." + fileExtention);
    }
    String message = MessageFormat.format(ResourceBundleHelper.getMessageString(MessageItem.fileChooser_fileExists), fileToSave.getAbsolutePath());
    if (fileToSave.exists()) {
        int option = new MessageDialogFactory().showConfirmDialog(MSG_WINDOW, message, JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.NO_OPTION) {
            return false;
        }
    }
    return true;
}
Also used : JFileChooser(javax.swing.JFileChooser) MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 12 with MessageDialogFactory

use of com.att.aro.ui.commonui.MessageDialogFactory in project VideoOptimzer by attdevsupport.

the class DataDump method getValidFolderList.

/**
 * Collects valid trace folders.
 *
 * @param traceFolders
 *            - List of available folder names.
 * @param validFolderList
 *            - List of valid trace folder names.
 */
private void getValidFolderList(List<File> traceFolders, List<File> validFolderList) {
    for (File traceDirectory : traceFolders) {
        // Check if it is a valid trace folder or not
        if (new File(traceDirectory, ResourceBundleHelper.getMessageString(MessageItem.datadump_trafficFile)).exists()) {
            validFolderList.add(traceDirectory);
        }
        // Check if it has sub-folders or not
        List<File> allFolders = null;
        if (traceDirectory == null) {
            allFolders = new ArrayList<File>();
        } else {
            File[] folders = traceDirectory.listFiles(new java.io.FileFilter() {

                @Override
                public boolean accept(File arg0) {
                    return arg0.isDirectory();
                }
            });
            if (folders == null) {
                allFolders = new ArrayList<File>();
            } else {
                allFolders = Arrays.asList(folders);
            }
        }
        if (subfolderAccess && allFolders.size() > 0) {
            if (!userConfirmation && new MessageDialogFactory().showConfirmDialog(MSG_WINDOW, ResourceBundleHelper.getMessageString(MessageItem.datadump_subfolder), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
                subfolderAccess = false;
                continue;
            }
            userConfirmation = true;
            getValidFolderList(allFolders, validFolderList);
        }
    }
}
Also used : MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory) File(java.io.File)

Example 13 with MessageDialogFactory

use of com.att.aro.ui.commonui.MessageDialogFactory in project VideoOptimzer by attdevsupport.

the class DataDump method startDataDump.

/**
 * Starts dumping data in CSV file for the provided trace files.
 *
 * @param traceFolders
 *            - List of trace folder names.
 * @return A FileWriter object.
 * @throws IOException
 */
private FileWriter startDataDump(List<File> traceFolders) throws IOException, ProfileException {
    FileWriter writer = new FileWriter(fileToSave);
    try {
        List<File> validFolderList = new ArrayList<File>();
        Set<AROTraceData> analysis = new LinkedHashSet<AROTraceData>();
        getValidFolderList(traceFolders, validFolderList);
        for (File traceDirectory : validFolderList) {
            try {
                analysis.add(controller.runAnalyzer(traceDirectory.getAbsolutePath(), controller.getTheModel().getAnalyzerResult().getProfile(), null));
            } catch (Exception e) {
                LOG.warn("Unable to run analysis on folder: " + traceDirectory, e);
            }
        }
        try {
            new ObjectMapper().writeValue(fileToSave, analysis);
        } catch (JsonGenerationException e) {
            LOG.error(e.getMessage());
            new MessageDialogFactory().showUnexpectedExceptionDialog(MSG_WINDOW, e);
        } catch (JsonMappingException e) {
            LOG.error(e.getMessage());
            new MessageDialogFactory().showUnexpectedExceptionDialog(MSG_WINDOW, e);
        } catch (IOException e) {
            LOG.error(e.getMessage());
            new MessageDialogFactory().showUnexpectedExceptionDialog(MSG_WINDOW, e);
        }
        userPreferences.setLastTraceDirectory(traceDir);
    } finally {
        writer.close();
    }
    return writer;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AROTraceData(com.att.aro.core.pojo.AROTraceData) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ProfileException(com.att.aro.ui.view.menu.profiles.ProfileException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with MessageDialogFactory

use of com.att.aro.ui.commonui.MessageDialogFactory in project VideoOptimzer by attdevsupport.

the class AROFileMenu method openTraceFolder.

/**
 * Choose a trace folder for direct analysis
 *
 * @param aEvent
 * @param isRecent
 * @return
 */
private void openTraceFolder(ActionEvent aEvent, boolean isRecent) {
    File traceFolder = null;
    Object event = aEvent.getSource();
    if (event instanceof JMenuItem) {
        if ((traceFolder = selectTraceFolder(aEvent, isRecent)) != null) {
            File trj;
            TimeRange timeRange = null;
            if ((trj = new File(traceFolder, "time-range.json")).exists()) {
                try {
                    String jsonData = fileManager.readAllData(trj.getPath());
                    if (!jsonData.contains("\"timeRangeType\" : \"DEFAULT\",")) {
                        JDialog splash = new TransitionDialog(parent.getFrame(), "Time-Range file detected\n", "Preparing to open in Time-Range chooser/editor dialog");
                        TimeRangeEditorDialog dialog;
                        try {
                            if ((dialog = displayTimeRangeEditor(traceFolder, true, splash)) != null && dialog.isContinueWithAnalyze()) {
                                timeRange = dialog.getTimeRange();
                            } else {
                                LOG.debug("Time-Range, Selection cancelled by user");
                                splash.dispose();
                                return;
                            }
                        } catch (Exception e) {
                            LOG.error("Exception in TimeRangeDialog:", e);
                            new MessageDialogFactory().showErrorDialog(null, "Exception in TimeRangeDialog:" + e.getMessage());
                            return;
                        }
                    } else {
                        TraceTimeRange traceTimeRange;
                        if ((traceTimeRange = timeRangeReadWrite.readData(traceFolder)) != null) {
                            if (traceTimeRange.getTimeRangeList().stream().filter(a -> a.getTimeRangeType().equals(TimeRangeType.DEFAULT)).count() > 1) {
                                LOG.error("Too many TimeRanges set to AUTO");
                                MessageDialogFactory.getInstance().showErrorDialog(parent.getFrame(), "Too many TimeRanges set to AUTO, please fix the selections");
                                return;
                            }
                            Optional<TimeRange> optionalTimeRange = traceTimeRange.getTimeRangeList().stream().filter(p -> p.getTimeRangeType().equals(TimeRange.TimeRangeType.DEFAULT)).findFirst();
                            if (optionalTimeRange.isPresent()) {
                                timeRange = optionalTimeRange.get();
                            }
                        }
                    }
                } catch (IOException e) {
                    LOG.error("Problem reading time-range.json", e);
                }
            }
            if (timeRange != null) {
                launchTraceFolderAnalysis(traceFolder, timeRange);
            } else {
                launchTraceFolderAnalysis(traceFolder);
            }
        } else {
            LOG.error("Invalid trace folder selected, no traffic file");
        }
    }
}
Also used : JDialog(javax.swing.JDialog) IFileManager(com.att.aro.core.fileio.IFileManager) TabPanels(com.att.aro.ui.view.SharedAttributesProcesses.TabPanels) ITimeRangeReadWrite(com.att.aro.core.peripheral.ITimeRangeReadWrite) TabPanelCommon(com.att.aro.ui.commonui.TabPanelCommon) IAROPrintable(com.att.aro.ui.commonui.IAROPrintable) PrinterJob(java.awt.print.PrinterJob) Logger(org.apache.log4j.Logger) AROUIIllegalStateException(com.att.aro.ui.exception.AROUIIllegalStateException) TimeRangeType(com.att.aro.core.packetanalysis.pojo.TimeRange.TimeRangeType) GoogleAnalyticsUtil(com.att.aro.core.util.GoogleAnalyticsUtil) AROMenuAdder(com.att.aro.ui.commonui.AROMenuAdder) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) JFileChooser(javax.swing.JFileChooser) UserPreferences(com.att.aro.core.preferences.UserPreferences) ToolTipManager(javax.swing.ToolTipManager) TimeRange(com.att.aro.core.packetanalysis.pojo.TimeRange) Set(java.util.Set) JMenu(javax.swing.JMenu) KeyEvent(java.awt.event.KeyEvent) MenuListener(javax.swing.event.MenuListener) MissingTraceFiles(com.att.aro.ui.view.menu.file.MissingTraceFiles) PreferencesDialog(com.att.aro.ui.view.menu.file.PreferencesDialog) PrinterException(java.awt.print.PrinterException) MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory) Optional(java.util.Optional) TimeRangeEditorDialog(com.att.aro.ui.view.menu.file.TimeRangeEditorDialog) ActionListener(java.awt.event.ActionListener) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ModalityType(java.awt.Dialog.ModalityType) AROPrintablePanel(com.att.aro.ui.commonui.AROPrintablePanel) MessageFormat(java.text.MessageFormat) LinkedHashMap(java.util.LinkedHashMap) OpenPcapFileDialog(com.att.aro.ui.view.menu.file.OpenPcapFileDialog) ADBPathDialog(com.att.aro.ui.view.menu.file.ADBPathDialog) JMenuItem(javax.swing.JMenuItem) UserPreferencesFactory(com.att.aro.core.preferences.UserPreferencesFactory) ResourceBundleHelper(com.att.aro.ui.utils.ResourceBundleHelper) TimeRangeReadWrite(com.att.aro.core.peripheral.impl.TimeRangeReadWrite) JComponent(javax.swing.JComponent) TraceTimeRange(com.att.aro.core.peripheral.pojo.TraceTimeRange) Iterator(java.util.Iterator) Files(java.nio.file.Files) Util(com.att.aro.core.util.Util) TraceDataConst(com.att.aro.core.packetanalysis.pojo.TraceDataConst) SpringContextUtil(com.att.aro.core.SpringContextUtil) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) ApplicationContext(org.springframework.context.ApplicationContext) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) SharedAttributesProcesses(com.att.aro.ui.view.SharedAttributesProcesses) Paths(java.nio.file.Paths) CrashHandler(com.att.aro.core.util.CrashHandler) MenuEvent(javax.swing.event.MenuEvent) LogManager(org.apache.log4j.LogManager) TimeRangeEditorDialog(com.att.aro.ui.view.menu.file.TimeRangeEditorDialog) IOException(java.io.IOException) AROUIIllegalStateException(com.att.aro.ui.exception.AROUIIllegalStateException) PrinterException(java.awt.print.PrinterException) IOException(java.io.IOException) TraceTimeRange(com.att.aro.core.peripheral.pojo.TraceTimeRange) TimeRange(com.att.aro.core.packetanalysis.pojo.TimeRange) TraceTimeRange(com.att.aro.core.peripheral.pojo.TraceTimeRange) MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory) JMenuItem(javax.swing.JMenuItem) File(java.io.File) JDialog(javax.swing.JDialog)

Example 15 with MessageDialogFactory

use of com.att.aro.ui.commonui.MessageDialogFactory in project VideoOptimzer by attdevsupport.

the class ADBPathDialog method onOk.

private void onOk() {
    if (txtFile.getText().length() < 3) {
        new MessageDialogFactory().showErrorDialog(null, "Please provide location of ADB to continue.");
    } else {
        settings.setAndSaveAttribute("adb", txtFile.getText());
        System.setProperty("ANDROID_ADB", txtFile.getText());
        dispose();
    }
}
Also used : MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory)

Aggregations

MessageDialogFactory (com.att.aro.ui.commonui.MessageDialogFactory)18 IOException (java.io.IOException)10 File (java.io.File)9 Profile (com.att.aro.core.configuration.pojo.Profile)3 CrashHandler (com.att.aro.core.util.CrashHandler)3 AROUIIllegalStateException (com.att.aro.ui.exception.AROUIIllegalStateException)3 JFileChooser (javax.swing.JFileChooser)3 AROPrintablePanel (com.att.aro.ui.commonui.AROPrintablePanel)2 IAROPrintable (com.att.aro.ui.commonui.IAROPrintable)2 DataTablePopupMenu (com.att.aro.ui.model.DataTablePopupMenu)2 MainFrame (com.att.aro.ui.view.MainFrame)2 TimeRangeEditorDialog (com.att.aro.ui.view.menu.file.TimeRangeEditorDialog)2 PrinterException (java.awt.print.PrinterException)2 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)2 TableCellEditor (javax.swing.table.TableCellEditor)2 SpringContextUtil (com.att.aro.core.SpringContextUtil)1 IExternalProcessRunner (com.att.aro.core.commandline.IExternalProcessRunner)1 ExternalProcessRunnerImpl (com.att.aro.core.commandline.impl.ExternalProcessRunnerImpl)1 IDataCollector (com.att.aro.core.datacollector.IDataCollector)1 IFileManager (com.att.aro.core.fileio.IFileManager)1