/** * Core constructor, init Model instances * * @param debugMode Show additional information for debugging purposes * @note Call startup() to init Swing */ public Core(CoreWorkspaceImpl coreWorkspace, boolean debugMode, LoadingFrame splashScreen) throws InvocationTargetException, InterruptedException { ProgressMonitor parentProgress = splashScreen.getProgressMonitor(); ProgressMonitor progressInfo = parentProgress.startTask(I18N.tr("Loading Workspace.."), 100); MainContext.initConsoleLogger(debugMode); // Declare empty main frame mainFrame = new MainFrame(); // Set the main frame position and size mainFrame.setSize(MAIN_VIEW_SIZE); // Try to set the frame at the center of the default screen try { GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); Rectangle screenBounds = device.getDefaultConfiguration().getBounds(); mainFrame.setLocation( screenBounds.x + screenBounds.width / 2 - MAIN_VIEW_SIZE.width / 2, screenBounds.y + screenBounds.height / 2 - MAIN_VIEW_SIZE.height / 2); } catch (Throwable ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } UIFactory.setMainFrame(mainFrame); initMainContext(debugMode, coreWorkspace, splashScreen); progressInfo.progressTo(10); this.viewWorkspace = new ViewWorkspace(this.mainContext.getCoreWorkspace()); Services.registerService( ViewWorkspace.class, I18N.tr("Contains view folders path"), viewWorkspace); progressInfo.setTaskName(I18N.tr("Register GUI Sql functions..")); addSQLFunctions(); progressInfo.progressTo(11); // Load plugin host progressInfo.setTaskName(I18N.tr("Load the plugin framework..")); startPluginHost(); progressInfo.progressTo(18); progressInfo.setTaskName(I18N.tr("Connecting to the database..")); // Init database try { mainContext.initDataBase( coreWorkspace.getDataBaseUser(), coreWorkspace.getDataBasePassword()); } catch (SQLException ex) { throw new RuntimeException(ex.getLocalizedMessage(), ex); } initSIF(); progressInfo.progressTo(20); }
/** Find the workspace folder or addDockingPanel a dialog to select one */ private void initMainContext( boolean debugMode, CoreWorkspaceImpl coreWorkspace, LoadingFrame splashScreen) throws InterruptedException, InvocationTargetException, RuntimeException { String workspaceFolder = coreWorkspace.getWorkspaceFolder(); if (workspaceFolder == null) { File defaultWorkspace = coreWorkspace.readDefaultWorkspacePath(); if (defaultWorkspace == null || !ViewWorkspace.isWorkspaceValid(defaultWorkspace)) { try { PromptUserForSelectingWorkspace dial = new PromptUserForSelectingWorkspace(coreWorkspace, splashScreen); SwingUtilities.invokeAndWait(dial); if (!dial.isOk()) { throw new InterruptedException("Canceled by user."); } } catch (InvocationTargetException ex) { mainFrame.dispose(); throw ex; } } else { coreWorkspace.setWorkspaceFolder(defaultWorkspace.getAbsolutePath()); } } this.mainContext = new MainContext(debugMode, coreWorkspace, true); }