/** Performs the necessary initialization. */ protected void init() { if (debug) { DebugTrace.print(this, "init"); // $NON-NLS-1$ } LibraryPlugin.getDefault() .getPreferenceStore() .addPropertyChangeListener(preferenceStoreChangeListener); // Create the adapter factory. List factories = new ArrayList(); factories.add(new ResourceItemProviderAdapterFactory()); factories.add(new ReflectiveItemProviderAdapterFactory()); ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(factories); // Create the command stack. BasicCommandStack commandStack = new BasicCommandStack(); // Create the resource set. ILibraryResourceSet resourceSet = createResourceSet(); resourceSet.addRefreshListener(refreshListener); RefreshJob.getInstance().setResourceSet(resourceSet); // Initialize the library save options. saveOptions = resourceSet.getDefaultSaveOptions(); saveOptions.put( MultiFileXMISaveImpl.DISCARD_UNRESOLVED_REFERENCES, LibraryPreferences.getDiscardUnresolvedReferences()); // Create the editing domain. editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet); // Register the editing domain. registerEditingDomain(editingDomain); }
/** Performs the import. */ public void performImport(final IProgressMonitor monitor) { // need to disable the workspace refreshing boolean refresh = RefreshJob.getInstance().isEnabled(); if (refresh) { // disable resource refreshing during import // RefreshJob.getInstance().setEnabled(false); } try { if (monitor != null) { monitor.setTaskName(ImportResources.ConfigurationImportService_MSG3); } if (isSpecsOnly()) { specsMgr.doImport(data.specs); } else { LibraryImportManager importingMgr = new LibraryImportManager(diffMgr, data.importList); importingMgr.doMerge(data.replaceExisting, monitor); } // refresh library files in workspace // MethodLibrary lib = LibraryService.getInstance().getCurrentMethodLibrary(); ResourceUtil.refreshResources(lib, monitor); } catch (Exception e) { ImportPlugin.getDefault().getLogger().logError(e); } finally { if (refresh) { // re-enable resource refreshing // RefreshJob.getInstance().setEnabled(true); } if (upGradeInfo != null) { upGradeInfo.removeCopiedLibrary(); upGradeInfo = null; } } try { postImportOperation(monitor); } catch (Exception e) { ImportPlugin.getDefault().getLogger().logError(e); } }
/** * Closes the managed method library. * * @return a method library * @throw <code>LibraryServiceException</code> if an error occurs while performing the operation */ public void closeMethodLibrary() throws LibraryServiceException { if (debug) { String msg = "library=" + library + ", memory on entry=" //$NON-NLS-1$ //$NON-NLS-2$ + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); DebugTrace.print(this, "closeMethodLibrary", msg); // $NON-NLS-1$ } // String libPath = LibraryService.getInstance() // .getCurrentMethodLibraryPath(); File libFile = new File(library.eResource().getURI().toFileString()); String libPath = libFile.getParentFile().getAbsolutePath(); // remove the configuration managers associated with this library LibraryService.getInstance().removeConfigurationManagers(library); removeResourceChangedListeners(); // Clear the temp layout resources. LayoutResources.clear(); Suppression.clearCachedSuppressions(); TngUtil.umaItemProviderAdapterFactory.dispose(); ILibraryResourceSet resourceSet = (ILibraryResourceSet) editingDomain.getResourceSet(); resourceSet.unload(); try { // Close the method library project file. MethodLibraryProject.closeProject(libPath, null); } catch (Exception e) { throw new LibraryServiceException(e); } RefreshJob.getInstance().reset(); // Activates the garbage collector. Runtime.getRuntime().gc(); if (debug) { String msg = "library=" + library + ", memory on exit=" //$NON-NLS-1$ //$NON-NLS-2$ + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); DebugTrace.print(this, "closeMethodLibrary", msg); // $NON-NLS-1$ } }