diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/plugin.xml b/bundles/org.eclipse.emf.emfstore.client.ui/plugin.xml index 6fb2b9c4c..e78e26367 100644 --- a/bundles/org.eclipse.emf.emfstore.client.ui/plugin.xml +++ b/bundles/org.eclipse.emf.emfstore.client.ui/plugin.xml @@ -6,6 +6,7 @@ + + + + + + + + + + + + + @@ -729,6 +752,11 @@ id="org.eclipse.emf.emfstore.client.ui.historybrowserview.checkout" name="CheckoutRevision"> + + + + + + + + + + Enable lazy loading of change packages in the History Browser View. If enabled the initial list will only show history info (commit message, date, ...) but no change details. Change details can be loaded via context menu on the history info for one or more history infos. + +Per default lazy loading is disabled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.9.0 + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + + + + + Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.<br/> + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/epl-v10.html + + + + diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/LoadChangePackagesHandler.java b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/LoadChangePackagesHandler.java new file mode 100644 index 000000000..138752199 --- /dev/null +++ b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/LoadChangePackagesHandler.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2016 Metus GmbH + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * mbarchfe + ******************************************************************************/ +package org.eclipse.emf.emfstore.internal.client.ui.handlers; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.emfstore.internal.client.model.ESWorkspaceProviderImpl; +import org.eclipse.emf.emfstore.internal.client.model.ProjectSpace; +import org.eclipse.emf.emfstore.internal.client.model.connectionmanager.ConnectionManager; +import org.eclipse.emf.emfstore.internal.client.ui.views.historybrowserview.HistoryBrowserView; +import org.eclipse.emf.emfstore.internal.common.model.util.ModelUtil; +import org.eclipse.emf.emfstore.internal.server.model.ProjectId; +import org.eclipse.emf.emfstore.internal.server.model.SessionId; +import org.eclipse.emf.emfstore.internal.server.model.versioning.AbstractChangePackage; +import org.eclipse.emf.emfstore.internal.server.model.versioning.HistoryInfo; +import org.eclipse.emf.emfstore.internal.server.model.versioning.PrimaryVersionSpec; +import org.eclipse.emf.emfstore.server.exceptions.ESException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Handler for getting a list of change packages for given {@link HistoryInfo}s . + * + * @author mbarchfe + * + */ +public class LoadChangePackagesHandler extends AbstractEMFStoreHandler { + + /** + * Gets the selection from an {@link ExecutionEvent}. Only elements which are instances of the given class will be + * returned. + * + * @param event the event + * @param clazz the type + * @return the selection + * + * @param the type + */ + @SuppressWarnings("unchecked") + public static List getSelection(ExecutionEvent event, Class clazz) { + final List result = new ArrayList(); + ISelection sel = HandlerUtil.getCurrentSelection(event); + if (sel == null) { + sel = HandlerUtil.getActiveMenuSelection(event); + } + if (sel instanceof IStructuredSelection) { + final IStructuredSelection structuredSelection = (IStructuredSelection) sel; + @SuppressWarnings("rawtypes") + final Iterator it = structuredSelection.iterator(); + while (it.hasNext()) { + final Object selectedElement = it.next(); + if (clazz.isInstance(selectedElement)) { + result.add((T) selectedElement); + } + } + } + return result; + } + + @Override + public void handle() { + + final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); + if (activePage == null) { + return; + } + + if (!(activePage.getActivePart() instanceof HistoryBrowserView)) { + return; + } + + final HistoryBrowserView view = (HistoryBrowserView) activePage.getActivePart(); + final ProjectSpace projectSpace = view.getProjectSpace(); + final ESWorkspaceProviderImpl esWorkspaceProviderImpl = ESWorkspaceProviderImpl.getInstance(); + + final ConnectionManager connectionManager = esWorkspaceProviderImpl.getConnectionManager(); + + final ProjectId projectId = projectSpace.getProjectId(); + final SessionId sessionId = projectSpace.getUsersession().getSessionId(); + + final List historyInfos = getSelection(getEvent(), HistoryInfo.class); + for (final HistoryInfo historyInfo : historyInfos) { + final PrimaryVersionSpec fromSpec = ModelUtil.clone(historyInfo.getPreviousSpec()); + final PrimaryVersionSpec toSpec = ModelUtil.clone(historyInfo.getPrimarySpec()); + // e.g. local change would be invalid to send to server + if (!isValid(fromSpec) || !isValid(toSpec)) { + continue; + } + + try { + final List changes = connectionManager.getChanges(sessionId, projectId, + fromSpec, + toSpec); + // the result should be one change package, if there were more or none this would be suprising + if (changes.size() != 1) { + ModelUtil.log( + MessageFormat.format("Expected to retrieve one change package but got {0}", changes.size()), //$NON-NLS-1$ + null, IStatus.ERROR); + } else { + historyInfo.setChangePackage(changes.get(0)); + } + } catch (final ESException ex) { + ModelUtil.log( + MessageFormat.format("Could not load changes for history info {0}", historyInfo), //$NON-NLS-1$ + ex, IStatus.ERROR); + } + view.refresh(historyInfo); + } + + } + + private boolean isValid(PrimaryVersionSpec spec) { + return spec != null && spec.getIdentifier() > -1; + } + +} diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/historybrowserview/HistoryBrowserView.java b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/historybrowserview/HistoryBrowserView.java index bedac2ab7..d83ead1c4 100644 --- a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/historybrowserview/HistoryBrowserView.java +++ b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/historybrowserview/HistoryBrowserView.java @@ -26,6 +26,8 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; import org.eclipse.emf.emfstore.client.ESLocalProject; import org.eclipse.emf.emfstore.client.util.ESVoidCallable; +import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPoint; +import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPointException; import org.eclipse.emf.emfstore.internal.client.common.UnknownEMFStoreWorkloadCommand; import org.eclipse.emf.emfstore.internal.client.model.ESWorkspaceProviderImpl; import org.eclipse.emf.emfstore.internal.client.model.ProjectSpace; @@ -149,6 +151,25 @@ public class HistoryBrowserView extends ViewPart implements ProjectSpaceContaine private boolean isUnlinkedFromNavigator; private Action showAllBranches; + // changes can be transferred with historyInfos. However, this must be avoided if the server sends + // FileBasedChangePackages which the client can not open + private final static Boolean isLazyLoadingChanges; + private static final String ENABLE_LAZY_LOADING_OF_CHANGE_PACKAGES_EXTENSION_POINT = "org.eclipse.emf.emfstore.client.ui.enableLazyLoadingOfChangePackages"; //$NON-NLS-1$ + + static { + Boolean result; + try { + result = new ESExtensionPoint(ENABLE_LAZY_LOADING_OF_CHANGE_PACKAGES_EXTENSION_POINT, true) + .getBoolean("enabled", false); //$NON-NLS-1$ + // set system property to be in sync with extension point and to be queryable for menu point enablement + System.setProperty(ENABLE_LAZY_LOADING_OF_CHANGE_PACKAGES_EXTENSION_POINT, result.toString()); // $NON-NLS-1$ + } catch (final ESExtensionPointException e) { + // if no extension is available, check for system property + result = Boolean.getBoolean(ENABLE_LAZY_LOADING_OF_CHANGE_PACKAGES_EXTENSION_POINT); // $NON-NLS-1$ + } + isLazyLoadingChanges = result; + } + /** * {@inheritDoc} */ @@ -158,6 +179,7 @@ public ProjectSpace getProjectSpace() { @Override public void createPartControl(Composite parent) { + GridLayoutFactory.fillDefaults().applyTo(parent); initNoProjectHint(parent); @@ -288,6 +310,15 @@ public void run() { viewer.setInput(infos); } + /** + * Refresh a history info. Useful if a change package has been loaded lazily. + * + * @param historyInfo the {@link HistoryInfo} to refresh + */ + public void refresh(HistoryInfo historyInfo) { + viewer.refresh(historyInfo); + } + private void addBaseVersionTag(List infos) { final HistoryInfo historyInfo = getHistoryInfo(projectSpace.getBaseVersion()); if (historyInfo != null) { @@ -373,7 +404,7 @@ private List modelElementQuery() throws ESException { UPPER_LIMIT, LOWER_LIMIT, showAllVersions, - true); + !isLazyLoadingChanges); // TODO: proivde util method final ESHistoryQuery api = query.toAPI(); final List infos = projectSpace.toAPI().getHistoryInfos(api, new NullProgressMonitor()); @@ -386,7 +417,7 @@ private List rangeQuery() throws ESException { centerVersion, UPPER_LIMIT, LOWER_LIMIT, - showAllVersions, true, true, true); + showAllVersions, true, true, !isLazyLoadingChanges); final List infos = projectSpace.toAPI().getHistoryInfos( rangeQuery.toAPI(), new NullProgressMonitor()); diff --git a/releng/_target/emfstore.target b/releng/_target/emfstore.target index 16910a196..259e35af8 100644 --- a/releng/_target/emfstore.target +++ b/releng/_target/emfstore.target @@ -1,78 +1,61 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - + + - - - + + + - + @@ -85,9 +68,35 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +