public static void updateRepositoryUsingElements( final ProvisioningUI ui, final MetadataRepositoryElement[] elements) { ui.signalRepositoryOperationStart(); IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ui.getSession()); IArtifactRepositoryManager artManager = ProvUI.getArtifactRepositoryManager(ui.getSession()); try { int visibilityFlags = ui.getRepositoryTracker().getMetadataRepositoryFlags(); URI[] currentlyEnabled = metaManager.getKnownRepositories(visibilityFlags); URI[] currentlyDisabled = metaManager.getKnownRepositories( IRepositoryManager.REPOSITORIES_DISABLED | visibilityFlags); for (int i = 0; i < elements.length; i++) { URI location = elements[i].getLocation(); if (elements[i].isEnabled()) { if (containsURI(currentlyDisabled, location)) // It should be enabled and is not currently setColocatedRepositoryEnablement(ui, location, true); else if (!containsURI(currentlyEnabled, location)) { // It is not known as enabled or disabled. Add it. metaManager.addRepository(location); artManager.addRepository(location); } } else { if (containsURI(currentlyEnabled, location)) // It should be disabled, and is currently enabled setColocatedRepositoryEnablement(ui, location, false); else if (!containsURI(currentlyDisabled, location)) { // It is not known as enabled or disabled. Add it and then disable it. metaManager.addRepository(location); artManager.addRepository(location); setColocatedRepositoryEnablement(ui, location, false); } } String name = elements[i].getName(); if (name != null && name.length() > 0) { metaManager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name); artManager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name); } } // Are there any elements that need to be deleted? Go over the original state // and remove any elements that weren't in the elements we were given Set<String> nowKnown = new HashSet<String>(); for (int i = 0; i < elements.length; i++) nowKnown.add(URIUtil.toUnencodedString(elements[i].getLocation())); for (int i = 0; i < currentlyEnabled.length; i++) { if (!nowKnown.contains(URIUtil.toUnencodedString(currentlyEnabled[i]))) { metaManager.removeRepository(currentlyEnabled[i]); artManager.removeRepository(currentlyEnabled[i]); } } for (int i = 0; i < currentlyDisabled.length; i++) { if (!nowKnown.contains(URIUtil.toUnencodedString(currentlyDisabled[i]))) { metaManager.removeRepository(currentlyDisabled[i]); artManager.removeRepository(currentlyDisabled[i]); } } } finally { ui.signalRepositoryOperationComplete(null, true); } }
public static List<IInstallableUnit> elementsToIUs(Object[] elements) { ArrayList<IInstallableUnit> theIUs = new ArrayList<IInstallableUnit>(elements.length); for (int i = 0; i < elements.length; i++) { IInstallableUnit iu = ProvUI.getAdapter(elements[i], IInstallableUnit.class); if (iu != null) theIUs.add(iu); } return theIUs; }
public static IInstallableUnit getIU(Object element) { if (element instanceof IInstallableUnit) return (IInstallableUnit) element; if (element instanceof IIUElement) return ((IIUElement) element).getIU(); return ProvUI.getAdapter(element, IInstallableUnit.class); }
private static void setColocatedRepositoryEnablement( ProvisioningUI ui, URI location, boolean enable) { ProvUI.getArtifactRepositoryManager(ui.getSession()).setEnabled(location, enable); ProvUI.getMetadataRepositoryManager(ui.getSession()).setEnabled(location, enable); }
public static IInstallableUnit elementToIU(Object selectedElement) { return ProvUI.getAdapter(selectedElement, IInstallableUnit.class); }
@Override protected boolean contains(URI location, ProvisioningSession session) { return ProvUI.getMetadataRepositoryManager(session).contains(location); }
IArtifactRepositoryManager getArtifactRepositoryManager() { return ProvUI.getArtifactRepositoryManager(ui.getSession()); }
IMetadataRepositoryManager getMetadataRepositoryManager() { return ProvUI.getMetadataRepositoryManager(ui.getSession()); }
public void reportLoadFailure(final URI location, ProvisionException e) { int code = e.getStatus().getCode(); // If the user doesn't have a way to manage repositories, then don't report failures. if (!ui.getPolicy().getRepositoriesVisible()) { super.reportLoadFailure(location, e); return; } // Special handling when the location is bad (not found, etc.) vs. a failure // associated with a known repo. if (code == ProvisionException.REPOSITORY_NOT_FOUND || code == ProvisionException.REPOSITORY_INVALID_LOCATION) { if (!hasNotFoundStatusBeenReported(location)) { addNotFound(location); ProvUI.getDefaultParentShell() .getDisplay() .asyncExec( new Runnable() { public void run() { // IWorkbench workbench = PlatformUI.getWorkbench(); // if (workbench.isClosing()) // return; Shell shell = ProvUI.getDefaultParentShell(); if (MessageDialog.openQuestion( shell, ProvUIMessages.ColocatedRepositoryTracker_SiteNotFoundTitle, NLS.bind( ProvUIMessages.ColocatedRepositoryTracker_PromptForSiteLocationEdit, URIUtil.toUnencodedString(location)))) { RepositoryNameAndLocationDialog dialog = new RepositoryNameAndLocationDialog(shell, ui) { protected String getInitialLocationText() { return URIUtil.toUnencodedString(location); } protected String getInitialNameText() { String nickname = getMetadataRepositoryManager() .getRepositoryProperty(location, IRepository.PROP_NICKNAME); return nickname == null ? "" : nickname; // $NON-NLS-1$ } }; int ret = dialog.open(); if (ret == Window.OK) { URI correctedLocation = dialog.getLocation(); if (correctedLocation != null) { ui.signalRepositoryOperationStart(); try { removeRepositories(new URI[] {location}, ui.getSession()); addRepository(correctedLocation, dialog.getName(), ui.getSession()); } finally { ui.signalRepositoryOperationComplete(null, true); } } } } } }); } } else { ProvUI.handleException(e, null, StatusManager.SHOW | StatusManager.LOG); } }
public IProvisioningEventBus getProvisioningEventBus() { return ProvUI.getProvisioningEventBus(getSession()); }