Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog.

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:com.mansfield.pde.api.tools.internal.ui.preferencepages.TargetBaselinePreferencePage.java

License:Open Source License

private void internalReloadTargetDefinition(final ITargetDefinition target) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText(PDEUIMessages.TargetPlatformPreferencePage2_12);
        }/*from   www. j  a  v a  2 s. c o m*/
    };
    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                // Resolve the target
                target.resolve(monitor);
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
            }
        });
    } catch (InvocationTargetException e) {
        PDEPlugin.log(e);
        setErrorMessage(e.getMessage());
    } catch (InterruptedException e) {
        // Do nothing, resolve will happen when user presses ok
    }

    if (target.isResolved()) {
        // Check if the bundle resolution has errors
        IStatus bundleStatus = target.getStatus();
        if (bundleStatus.getSeverity() == IStatus.ERROR) {
            ErrorDialog.openError(getShell(), PDEUIMessages.TargetPlatformPreferencePage2_14,
                    PDEUIMessages.TargetPlatformPreferencePage2_15, bundleStatus, IStatus.ERROR);
        }
    }
    fTableViewer.refresh(true);
}

From source file:com.mentor.nucleus.bp.core.common.ComponentResourceListener.java

License:Open Source License

private static void parseAllInDialog(final NonRootModelElement rootME) {
    if (CorePlugin.getDefault().getParseAllOnResourceChange()) {
        ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(null);
        try {/*from  ww w .  j ava  2s. c  om*/
            monitorDialog.run(false, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    Domain_c dom = Domain_c.DomainInstance(rootME.getModelRoot());
                    CorePlugin.parseAll(dom, monitor);
                }
            });
        } catch (InvocationTargetException e) {
            CorePlugin.logError("Could not parse newly loaded component data", e);
        } catch (InterruptedException e) {
            CorePlugin.logError("Could not parse newly loaded component data", e);
        }
    }
}

From source file:com.mentor.nucleus.bp.core.common.Transaction.java

License:Open Source License

/**
 * Wrapper method to create a progress dialog if necessary, that is if the
 * amount of deltas is over a certain size
 *
 * @param transactionType/*from   w  ww  . jav  a  2 s . co  m*/
 */
void revert(final boolean inMemoryOnly) {
    int deltaCount = getDeltaCount();
    if (deltaCount > 200) {
        ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(
                PlatformUI.getWorkbench().getDisplay().getActiveShell());
        try {
            pmDialog.run(false, false, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    revert(monitor, inMemoryOnly);
                }

            });
        } catch (InvocationTargetException e) {
            CorePlugin.logError("Unable to invoke undo of the last transaction.", e);
        } catch (InterruptedException e) {
            CorePlugin.logError("The undo of the last transaction was interrupted.", e);
        }
    } else {
        revert(new NullProgressMonitor(), inMemoryOnly);
    }
}

From source file:com.mentor.nucleus.bp.core.ui.NewDomainWizard.java

License:Open Source License

public boolean createDomain(IWizardContainer container, ProgressMonitorDialog dialog) {
    IProject project = (IProject) m_sys.getAdapter(IProject.class);
    String domainName = PersistenceManager.getDefaultInstance()
            .getUniqueNameOfParent(m_sys.getPersistableComponent(), m_domainName, null);
    final String id = Ooaofooa.createModelRootId(project, domainName, true);
    final Ooaofooa modelRoot = Ooaofooa.getInstance(id, false);
    String message = "";//$NON-NLS-1$
    if (container != null && dialog == null)
        dialog = new ProgressMonitorDialog(getShell());

    if (!m_useTemplate) {
        final CorePlugin plugin = CorePlugin.getDefault();
        URL installURL = plugin.getBundle().getEntry("/");//$NON-NLS-1$
        try {//w  w  w .j  a  v a 2 s. com
            URL url = new URL(installURL, Ooaofooa.MODELS_DIRNAME + "/default." + Ooaofooa.MODELS_EXT); //$NON-NLS-1$
            final InputStream inStream = url.openStream();
            ImportStreamStatus iss = new ImportStreamStatus(id, inStream);
            if (container == null) {
                iss.run(new NullProgressMonitor());
            } else {
                dialog.run(true, false, iss);
            }
            message = iss.getMessage();
            try {
                inStream.close();
            } catch (IOException e2) {
                /* do nothing */ }
        } catch (IOException e1) {
            CorePlugin.logError("Internal error: failed to open default." + Ooaofooa.MODELS_EXT, e1);//$NON-NLS-1$
            return false;
        } catch (InterruptedException e) {
            CorePlugin.logError("Internal error: import was interrupted", e); //$NON-NLS-1$
            return false;
        } catch (InvocationTargetException e) {
            CorePlugin.logError("Internal error: plugin.doLoad not found", e); //$NON-NLS-1$
            return false;
        }
    } else {
        String templateFileName = m_templateFile;
        final IPath templatePath = new Path(templateFileName);
        // import the domain file into the model root with the id of the full path of the domain file
        if (templatePath.getFileExtension().equals(Ooaofooa.MODELS_EXT)) {
            final InputStream inStream;
            try {
                inStream = new FileInputStream(templatePath.toFile());
            } catch (FileNotFoundException e) {
                CorePlugin.logError("Internal error: failed to open " + templateFileName, e);
                return false;
            }
            try {
                ImportStreamStatus iss = new ImportStreamStatus(id, inStream);
                if (container == null) {
                    // for unit tests to prevent displaying progress dialogs
                    iss.run(new NullProgressMonitor());
                } else {
                    dialog.run(true, false, iss);
                }
                message = iss.getMessage();
                inStream.close();
            } catch (InterruptedException e) {
                CorePlugin.logError("Internal error: import was interrupted", e); //$NON-NLS-1$
                return false;
            } catch (InvocationTargetException e) {
                CorePlugin.logError("Internal error: plugin.doLoad not found", e); //$NON-NLS-1$
                return false;
            } catch (IOException e) {
                CorePlugin.logError("Unable to close stream to import file.", e); //$NON-NLS-1$
                /* do nothing */
            }
        } else {
            try {
                ImportFileStatus ifs = new ImportFileStatus(id, templatePath.toFile());
                if (container == null) {
                    // For unit tests.
                    ifs.run(new NullProgressMonitor());
                } else {
                    dialog.run(true, false, ifs);
                }
                message = ifs.getMessage();
            } catch (InterruptedException e) {
                CorePlugin.logError("Internal error: import was interrupted", e); //$NON-NLS-1$
                return false;
            } catch (InvocationTargetException e) {
                CorePlugin.logError("Internal error: plugin.doLoad not found", e); //$NON-NLS-1$
                return false;
            }
        }
        if (!message.equals("")) {
            CorePlugin.showImportErrorMessage(true, message);
            return true;
        }
    }
    // set the just loaded Domain instance name to the name specified by the user
    final Domain_c dom = Domain_c.DomainInstance(modelRoot, null, false);
    if (dom == null) {
        // There was a load error, already logged
        return false;
    }
    dom.setName(Ooaofooa.Getuniqueinitialname(modelRoot, m_domainName, dom.Converttoinstance()));
    IDConvertor.getInstance().recreateUUID(dom);

    // Create a PMC for the new domain
    try {
        if (dom.getPersistableComponent() == null) {
            PersistenceManager.getDefaultInstance().registerModel(dom, project);
        }
        IRunnableWithProgress persistenceRunnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Persisting newly created model...", getComponentCount(dom));
                    persistSelfAndChildren(dom, monitor);
                    displayDuplicateDialog();
                    monitor.done();
                } catch (CoreException e) {
                    CorePlugin.logError("Unable to persist newly created model.", e);
                } finally {
                    duplicateNames.clear();
                }
            }

        };
        if (m_parseOnImport) {
            try {
                if (container == null) {
                    // For unit tests.
                    CorePlugin.parseAll(dom, new NullProgressMonitor());
                } else {
                    dialog.run(false, false, new IRunnableWithProgress() {

                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            CorePlugin.parseAll(dom, monitor);
                        }

                    });
                }
            } catch (InvocationTargetException e) {
                CorePlugin.logError("Unable to parse model", e);
            } catch (InterruptedException e) {
                CorePlugin.logError("Unable to parse model", e);
            }
        }

        OALPersistenceUtil.persistOAL(modelRoot);

        if (container == null) {
            persistenceRunnable.run(new NullProgressMonitor());
        } else {
            dialog.run(false, false, persistenceRunnable);
        }
    } catch (CoreException e) {
        CorePlugin.logError("Unable to register model", e);
    } catch (InvocationTargetException e) {
        CorePlugin.logError("Unable to persist newly created model.", e);
    } catch (InterruptedException e) {
        CorePlugin.logError("Unable to persist newly created model.", e);
    }
    return true;
}

From source file:com.mentor.nucleus.bp.core.ui.PasteAction.java

License:Open Source License

public void run() {
    // clear the processor map
    processorMap.clear();// w ww .  ja v  a 2  s  .c  o  m
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            TransactionManager manager = getTransactionManager();
            Transaction transaction = null;
            List<NonRootModelElement> destinations = getDestinations();
            try {
                transaction = manager.startTransaction("Paste", //$NON-NLS-1$
                        new ModelRoot[] { Ooaofooa.getDefaultInstance(),
                                (ModelRoot) OoaofgraphicsUtil.getGraphicsRoot(
                                        Ooaofooa.DEFAULT_WORKING_MODELSPACE,
                                        OoaofgraphicsUtil.getGraphicsClass()) });
                for (NonRootModelElement destination : destinations) {
                    ModelStreamProcessor processor = new ModelStreamProcessor();
                    processorMap.put(destination, processor);
                    processor.setDestinationElement(destination);
                    Object contents = CorePlugin.getSystemClipboard().getContents(TextTransfer.getInstance());
                    if (contents instanceof String) {
                        String clipboardContents = (String) contents;
                        processor.setContents(clipboardContents);
                        String modelContents = clipboardContents.substring(clipboardContents.indexOf("\n") + 1);
                        ByteArrayInputStream in = new ByteArrayInputStream(modelContents.getBytes());
                        IModelImport importer = CorePlugin.getStreamImportFactory().create(in,
                                Ooaofooa.getInstance(Ooaofooa.CLIPBOARD_MODEL_ROOT_NAME), true,
                                destination.getPersistableComponent().getFile().getFullPath());
                        processor.runImporter(importer, monitor);
                        processor.processFirstStep(monitor);
                        runSubtypeProcessing(destination);
                        processor.processSecondStep(monitor);
                    }
                }
            } catch (Exception e) {
                CorePlugin.logError("Unable to start Paste transaction.", e); //$NON-NLS-1$
                if (transaction != null && manager != null && manager.getActiveTransaction() == transaction) {
                    manager.cancelTransaction(transaction, e);
                    transaction = null;
                }
            } finally {
                if (transaction != null)
                    manager.endTransaction(transaction);
            }
            if (transaction != null) {
                // only perform finishing work if the transaction
                // was successful
                boolean result = displayProblemDialog(manager, transaction, monitor);
                if (!result) {
                    // return as the user has cancelled the paste
                    return;
                }
                transaction = null;
                for (NonRootModelElement destination : destinations) {
                    ModelStreamProcessor processor = processorMap.get(destination);
                    processor.runParseOnImportedElements(manager, monitor);
                }
                // gather all of the loaded instances, including graphical
                for (NonRootModelElement destination : destinations) {
                    ModelStreamProcessor processor = processorMap.get(destination);
                    NonRootModelElement[] loadedInstances = processor.getImporter().getLoadedInstances();
                    NonRootModelElement[] loadedGraphicalInstances = processor.getImporter()
                            .getLoadedGraphicalInstances();
                    List<NonRootModelElement> instances = new ArrayList<NonRootModelElement>();
                    instances.addAll(Arrays.asList(loadedInstances));
                    instances.addAll(Arrays.asList(loadedGraphicalInstances));
                    for (IPasteListener listener : CorePlugin.getPasteListeners()) {
                        listener.pasteCompleted(destination, instances);
                    }
                }
            }
        }

    };
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
    try {
        dialog.run(false, false, runnable);
    } catch (InvocationTargetException e) {
        CorePlugin.logError("Unable to import contents from clipboard.", e); //$NON-NLS-1$
    } catch (InterruptedException e) {
        CorePlugin.logError("Unable to import contents from clipboard.", e); //$NON-NLS-1$
    }
}

From source file:com.mentor.nucleus.bp.io.core.CoreExport.java

License:Open Source License

/**
 * Parse the specified element.  //from   ww w.  j  av a2 s .c o m
 * 
 * @arg The element to parse.  Currently this routine can only parse elements
 *      of type Domain_c or Component_c
 */
private void parseOneElement(final NonRootModelElement selectedElement, final IProgressMonitor monitor,
        Shell dialogShell) throws InvocationTargetException, InterruptedException {

    final String className = selectedElement.getClass().getName();
    final String instanceName = selectedElement.getName();

    errorLoggedDuringParse = false;

    // This does mean that if the element passed-in is not one we know
    // how to parse this routine returns success
    if ((selectedElement instanceof Domain_c) || (selectedElement instanceof Component_c)
            || (selectedElement instanceof Package_c) || (selectedElement instanceof Subsystem_c)
            || (selectedElement instanceof FunctionPackage_c)
            || (selectedElement instanceof ExternalEntityPackage_c)) {
        final NonRootModelElement nrme = selectedElement;
        IRunnableWithProgress rwp = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                if (monitor != null) {
                    monitor.subTask("Parsing " + instanceName);
                }

                ParserAllActivityModifier aam = null;
                boolean workBenchIsRunning = PlatformUI.isWorkbenchRunning();
                if (nrme instanceof Domain_c) {
                    if (workBenchIsRunning) {
                        aam = new AllActivityModifier((Domain_c) nrme, monitor);
                    } else {
                        aam = new ParserAllActivityModifier((Domain_c) nrme, monitor);
                    }
                } else if (nrme instanceof Component_c) {
                    if (workBenchIsRunning) {
                        aam = new AllActivityModifier((Component_c) nrme, monitor);
                    } else {
                        aam = new ParserAllActivityModifier((Component_c) nrme, monitor);
                    }
                } else if (nrme instanceof Package_c) {
                    if (workBenchIsRunning) {
                        aam = new AllActivityModifier((Package_c) nrme, monitor);
                    } else {
                        aam = new ParserAllActivityModifier((Package_c) nrme, monitor);
                    }
                } else if (nrme instanceof Subsystem_c) {
                    if (workBenchIsRunning) {
                        aam = new AllActivityModifier((Subsystem_c) nrme, monitor);
                    } else {
                        aam = new ParserAllActivityModifier((Subsystem_c) nrme, monitor);
                    }
                } else if (nrme instanceof FunctionPackage_c) {
                    if (workBenchIsRunning) {
                        aam = new AllActivityModifier((FunctionPackage_c) nrme, monitor);
                    } else {
                        aam = new ParserAllActivityModifier((FunctionPackage_c) nrme, monitor);
                    }
                } else if (nrme instanceof ExternalEntityPackage_c) {
                    if (workBenchIsRunning) {
                        aam = new AllActivityModifier((ExternalEntityPackage_c) nrme, monitor);
                    } else {
                        aam = new ParserAllActivityModifier((ExternalEntityPackage_c) nrme, monitor);
                    }
                }

                if (aam != null) {
                    aam.processAllActivities(ParserAllActivityModifier.PARSE, false);
                }

                if (monitor != null) {
                    monitor.done();
                }
            }
        };

        // parse the element
        if (dialogShell == null) {
            if (monitor == null) {
                rwp.run(new NullProgressMonitor());
            } else {
                rwp.run(monitor);
            }
        } else {
            new ProgressMonitorDialog(dialogShell).run(true, false, rwp);
        }

    } else {
        // Log a warning that we received an element type that this
        // routine will not parse.  This really shouldn't happen.  If it
        // does it means something is being exported that may include OAL
        // that is not being persisted in the export.
        String message = "Warning: CoreExport.parseOneElement() received an element that will not be parsed.  ";
        message += "Class: " + className + "  Instance: " + instanceName;
        CorePlugin.logError(message, null);
    }

    if (!CoreUtil.IsRunningHeadless) {
        // Make sure that all events in the asynchronous event queue
        // are dispatched. This is here is help assure that parse errors
        // are detected by the ILogListener
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
            public void run() {
                // do nothing
            }
        });
    }

    if (errorLoggedDuringParse) {
        String message = "Warning: Parse errors encountered prior to model export.  ";
        message += "Class: " + className + "  Instance: " + instanceName;
        CorePlugin.logError(message, null);
    }
}

From source file:com.mentor.nucleus.bp.io.mdl.test.ParseOnImportTests.java

License:Open Source License

private void importModel() {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask("Loading test model: " + testModel.getName().replaceAll(".xtuml", ""), 1);
            NewDomainWizard ndw = new NewDomainWizard();
            Selection sel = Selection.getInstance();
            sel.clear();/*from w  ww. j a  v a 2 s. co  m*/
            sel.addToSelection(m_sys);
            ndw.init(null, sel.getStructuredSelection());
            ndw.addPages();
            WizardDialog dialog = new WizardDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ndw);
            dialog.create();
            WizardNewDomainCreationPage wndcp = (WizardNewDomainCreationPage) ndw.getStartingPage();
            wndcp.setDomainNameFieldValue(testModel.getName().replaceAll("." + Ooaofooa.MODELS_EXT, ""));
            wndcp.setTemplateLocationFieldValue(testModel.getAbsolutePath());
            wndcp.setParseOnImport(true);
            ndw.setContainer(null);
            ndw.performFinish();

            monitor.worked(1);
        }

    };
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getDisplay().getActiveShell());
    try {
        dialog.run(false, false, runnable);
    } catch (InvocationTargetException e) {
        fail("Unable to initialize test models.");
    } catch (InterruptedException e) {
        fail("Initialization of test models was interrupted.");
    }
}

From source file:com.mentor.nucleus.bp.io.mdl.wizards.ModelExportWizard.java

License:Open Source License

/**
 * //from w w  w.j  a  va  2  s  . c  o  m
 * @return true is the export was created with the prefernece to enable
 *              export of executable oal instance and false if not.
 *              
 * @throws FileNotFoundException
 * @throws InterruptedException
 * @throws InvocationTargetException
 */
private boolean createExportProcessor()
        throws FileNotFoundException, InterruptedException, InvocationTargetException {
    // we need to add the GD_GE instances for those elements
    // selected
    List<NonRootModelElement> elements = new ArrayList<NonRootModelElement>();
    final NonRootModelElement[] selectedElements = Selection.getInstance().getSelectedNonRootModelElements();

    IRunnableWithProgress runnableLoader = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            // here we force load the selected elements to
            // prevent outputting null ids (which can happen
            // in certain circumstances) issue 3303 may
            // fix this at which point this code can be
            // removed
            for (int i = 0; i < selectedElements.length; i++) {
                PersistableModelComponent component = selectedElements[i].getPersistableComponent();
                component.loadComponentAndChildren(monitor);
            }
        }
    };

    if (getContainer() == null) {
        runnableLoader.run(new NullProgressMonitor());
    } else {
        new ProgressMonitorDialog(getContainer().getShell()).run(true, false, runnableLoader);
    }

    for (int i = 0; i < selectedElements.length; i++) {
        elements.add(selectedElements[i]);
    }
    addGraphicalElementsFor(selectedElements, elements);
    outStream = new ByteArrayOutputStream();
    exporter = com.mentor.nucleus.bp.core.CorePlugin.getStreamExportFactory().create(outStream,
            elements.toArray(new NonRootModelElement[elements.size()]), true, true);
    boolean exportOALInstances = false;
    if (exporter instanceof CoreExport) {

        ((CoreExport) exporter).setExportGraphics(CoreExport.USER_PREFERENCE);
        // Check the license.  This tests the license without checking it out.  If there is
        // no availble license this will return false.
        exportOALInstances = ((CoreExport) exporter).setExportOAL(CoreExport.USER_PREFERENCE);
    }
    return exportOALInstances;
}

From source file:com.mentor.nucleus.bp.io.mdl.wizards.ModelExportWizard.java

License:Open Source License

public boolean performFinish() {
    boolean successfulExport = false;
    String errorMsg = "Unable to export to destination file.";
    FileOutputStream fos;//from   w  w  w.  ja va  2 s .  co m
    try {
        m_outputFile = new File(fExportPage.getDestinationFilePath());
        if (!m_outputFile.exists()) {
            m_outputFile.createNewFile();
        } else {
            if (getExportPage().getOverwriteWarning()) {
                boolean replaceFile = successfulExport = UIUtil.openQuestion(getShell(), "Confirm Replace",
                        "The file '" + getExportPage().getDestinationFilePath()
                                + "' already exists. Do you want to overwrite it?",
                        true);
                if (!replaceFile) {
                    // If the user doesn't want to overwrite the file return
                    // but leave the dialog so they can choose another name
                    // if they want to
                    return successfulExport;
                }
            }
        }
        createExportProcessor();
        boolean exportOALIsSelected = false;
        NonRootModelElement[] selectedElements = null;
        if (exporter instanceof CoreExport) {
            exportOALIsSelected = ((CoreExport) exporter).exportOAL();
            if (exportOALIsSelected) {
                selectedElements = Selection.getInstance().getSelectedNonRootModelElements();
                ((CoreExport) exporter).parseAllForExport(selectedElements, getContainer().getShell());
            }

        }
        // Perform the export
        if (getContainer() == null) {
            exporter.run(new NullProgressMonitor());
        } else {
            new ProgressMonitorDialog(getContainer().getShell()).run(true, false, exporter);
        }
        fos = new FileOutputStream(m_outputFile);
        fos.write(outStream.toByteArray());
        fos.close();
        successfulExport = true;

        // Destroy the OAL instances
        if (selectedElements != null) {
            for (int i = 0; i < selectedElements.length; i++) {
                AllActivityModifier.disposeAllBodies(selectedElements[i].getModelRoot());
            }
        }
    } catch (FileNotFoundException e) {
        CorePlugin.logError(errorMsg, e);
    } catch (IOException e) {
        CorePlugin.logError(errorMsg, e);
    } catch (InvocationTargetException e) {
        CorePlugin.logError(errorMsg, e);
    } catch (InterruptedException e) {
        CorePlugin.logError(errorMsg, e);
    }
    if (!successfulExport) {
        Shell parent = getShell();
        if (getContainer() != null) {
            parent = getContainer().getShell();
        }

        UIUtil.openError(parent, "Export Failed", errorMsg);

        if (m_outputFile.exists()) {
            m_outputFile.delete();
        }
    }

    return successfulExport;
}

From source file:com.mentor.nucleus.bp.io.mdl.wizards.ModelImportWizard.java

License:Open Source License

public boolean importModel(SystemModel_c system) {
    fSystem = system;/* w  w w .  jav  a 2s .  co  m*/
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    String templateFileName = fImportPage.getSourceFilePath();
    final IPath templatePath = new Path(templateFileName);
    // import the domain file into the model root with the id of the full
    // path of the domain file
    if (templatePath.getFileExtension().equals(Ooaofooa.MODELS_EXT)) {
        final InputStream inStream;
        try {
            inStream = new FileInputStream(templatePath.toFile());
        } catch (FileNotFoundException e) {
            CorePlugin.logError("Internal error: failed to open " + templateFileName, e);
            return false;
        }
        try {
            // turn off model change listeners
            ModelRoot.disableChangeNotification();
            // below we create an importer simply to
            // discover if we are importing an old BP
            // domain file, if so we call NewDomainWizard
            // to handle the import. Otherwise we need
            // to create an import stream.
            String domainName = new Path(fImportPage.getSourceFilePath()).removeFileExtension().lastSegment();
            String rootId = Ooaofooa.createModelRootId((IProject) fSystem.getAdapter(IProject.class),
                    domainName, true);
            Ooaofooa domainRoot = Ooaofooa.getInstance(rootId);
            fImporter = CorePlugin.getModelImportFactory().create(inStream, domainRoot, fSystem, false, true,
                    true, false);
            if (fImporter.getHeader().getModelComponentType().equalsIgnoreCase("Domain")) { //$NON-NLS-1$
                // close the above input stream as it was only used
                // to determine if we are importing an old domain
                inStream.close();
                DomainCreationRunnable runnable = new DomainCreationRunnable(domainName, dialog);
                if (getContainer() != null) {
                    dialog.run(false, false, runnable);
                } else {
                    runnable.run(new NullProgressMonitor());
                }
                return runnable.result;
            }
            ImportStreamStatus iss = new ImportStreamStatus(inStream);
            if (getContainer() == null) {
                // for unit tests to prevent displaying progress dialogs
                iss.run(new NullProgressMonitor());
            } else {
                dialog.run(true, false, iss);
            }
        } catch (InterruptedException e) {
            com.mentor.nucleus.bp.io.core.CorePlugin.logError("Internal error: import was interrupted", e); //$NON-NLS-1$
            return false;
        } catch (InvocationTargetException e) {
            com.mentor.nucleus.bp.io.core.CorePlugin.logError("Internal error: plugin.doLoad not found", e); //$NON-NLS-1$
            return false;
        } catch (IOException e) {
            com.mentor.nucleus.bp.io.core.CorePlugin.logError("Unable to import chosen model file.", e); //$NON-NLS-1$
        } finally {
            ModelRoot.enableChangeNotification();
        }
    }
    return true;
}