X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=legacy%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcommands%2FFetch.java;fp=legacy%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcommands%2FFetch.java;h=39a9274d8babe2d3f265d890abee5a9a05c52ff8;hb=6fc94d69efe089414ac9e63bde3efab1cbf7b7ca;hp=0000000000000000000000000000000000000000;hpb=b36c62642bd0db11b3133b369cc026fd4b7a1ec6;p=gpl%2Fargeo-slc.git diff --git a/legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/Fetch.java b/legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/Fetch.java new file mode 100644 index 000000000..39a9274d8 --- /dev/null +++ b/legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/Fetch.java @@ -0,0 +1,80 @@ +package org.argeo.slc.client.ui.dist.commands; + +import javax.jcr.Node; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.RepositoryFactory; +import javax.jcr.Session; + +import org.argeo.api.security.Keyring; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.client.ui.dist.DistPlugin; +import org.argeo.slc.client.ui.dist.utils.CommandHelpers; +import org.argeo.slc.client.ui.dist.wizards.FetchWizard; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Wrap a {@code RepoSync} as an Eclipse command. Open a wizard that enable + * definition of the fetch process parameters + */ +public class Fetch extends AbstractHandler { + // private final static Log log = LogFactory.getLog(Fetch.class); + + public final static String ID = DistPlugin.PLUGIN_ID + ".fetch"; + public final static String DEFAULT_LABEL = "Fetch..."; + public final static ImageDescriptor DEFAULT_ICON = DistPlugin + .getImageDescriptor("icons/fetchRepo.png"); + + public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath"; + + // DEPENDENCY INJECTION + private Keyring keyring; + private RepositoryFactory repositoryFactory; + private Repository nodeRepository; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + Session currSession = null; + try { + // Target Repository + String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH); + currSession = nodeRepository.login(); + Node targetRepoNode = currSession.getNode(targetRepoPath); + + FetchWizard wizard = new FetchWizard(keyring, repositoryFactory, + nodeRepository); + wizard.setTargetRepoNode(targetRepoNode); + WizardDialog dialog = new WizardDialog( + HandlerUtil.getActiveShell(event), wizard); + + int result = dialog.open(); + if (result == Dialog.OK) + CommandHelpers.callCommand(RefreshDistributionsView.ID); + return null; + } catch (RepositoryException e) { + throw new SlcException("Unable te retrieve repo node from path", e); + } finally { + JcrUtils.logoutQuietly(currSession); + } + } + + // DEPENDENCY INJECTION + public void setRepositoryFactory(RepositoryFactory repositoryFactory) { + this.repositoryFactory = repositoryFactory; + } + + public void setKeyring(Keyring keyring) { + this.keyring = keyring; + } + + public void setNodeRepository(Repository repository) { + this.nodeRepository = repository; + } +} \ No newline at end of file