X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcommands%2FRepoSyncCommand.java;h=e780cdf43d175a39e05af1c2fdacee5ac393a045;hb=5187ffaff5610275cf3dbc5fb913f59126576da8;hp=c9ff452a36d803f5a136295d71346cc3e4e82028;hpb=ea38a0fb11dcbbf094046dbf09222d4e8d5b0eac;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RepoSyncCommand.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RepoSyncCommand.java index c9ff452a3..e780cdf43 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RepoSyncCommand.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RepoSyncCommand.java @@ -1,34 +1,73 @@ 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.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.argeo.slc.repo.RepoSync; +import org.argeo.util.security.Keyring; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.handlers.HandlerUtil; /** Wraps a {@link RepoSync} as an Eclipse command. */ public class RepoSyncCommand extends AbstractHandler { - public final static String ID = DistPlugin.ID + ".repoSync"; - public final static String PARAM_SOURCE_REPO = "sourceRepo"; - public final static String PARAM_TARGET_REPO = "targetRepo"; - public final static String DEFAULT_LABEL = "Repo sync"; + // private final static Log log = LogFactory.getLog(RepoSyncCommand.class); + + public final static String ID = DistPlugin.ID + ".repoSyncCommand"; + public final static String PARAM_TARGET_REPO = "targetRepoPath"; + public final static String DEFAULT_LABEL = "Fetch ..."; public final static String DEFAULT_ICON_PATH = "icons/addItem.gif"; - + + // DEPENDENCY INJECTION + private Keyring keyring; private RepositoryFactory repositoryFactory; + private Repository nodeRepository; + + private Session currSession; public Object execute(ExecutionEvent event) throws ExecutionException { - RepoSync repoSync = new RepoSync(); - repoSync.setRepositoryFactory(repositoryFactory); - repoSync.setSourceRepo(event.getParameter(PARAM_SOURCE_REPO)); - repoSync.setTargetRepo(event.getParameter(PARAM_TARGET_REPO)); - repoSync.run(); - return null; + try { + currSession = nodeRepository.login(); + // Target Repository + String targetRepoPath = event.getParameter(PARAM_TARGET_REPO); + Node targetRepoNode = currSession.getNode(targetRepoPath); + + FetchWizard wizard = new FetchWizard(keyring, repositoryFactory, + nodeRepository); + wizard.setTargetRepoNode(targetRepoNode); + + WizardDialog dialog = new WizardDialog( + HandlerUtil.getActiveShell(event), wizard); + dialog.open(); + CommandHelpers.callCommand(RefreshDistributionsView.ID); + return null; + } catch (RepositoryException e) { + throw new SlcException("Unexpected error while fetching data", 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