From 39354c367bba7df8b5c993b2462e495c4def1e28 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Sat, 21 Feb 2015 12:21:04 +0100 Subject: [458349] Consolidate UI Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349--- .../org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF | 10 + .../icons/full/obj16/branch.gif | Bin 0 -> 352 bytes plugins/org.eclipse.emf.cdo.ui/plugin.xml | 45 +++++ .../internal/ui/actions/CreateBranchAction.java | 106 +++------- .../delegates/CreateBranchActionDelegate.java | 81 ++++++++ .../org/eclipse/emf/cdo/internal/ui/bundle/OM.java | 29 +++ .../internal/ui/dialogs/CreateBranchDialog.java | 223 ++++++++++++++++++--- .../internal/ui/handlers/CreateBranchHandler.java | 107 ++++++++++ .../emf/cdo/internal/ui/views/CDOSessionsView.java | 21 ++ .../org/eclipse/emf/cdo/ui/CDOItemProvider.java | 3 +- .../src/org/eclipse/emf/cdo/ui/OverlayImage.java | 44 ++++ .../emf/cdo/ui/widgets/CommitHistoryComposite.java | 25 ++- .../cdo/ui/widgets/SelectTimeStampComposite.java | 8 +- 13 files changed, 585 insertions(+), 117 deletions(-) create mode 100644 plugins/org.eclipse.emf.cdo.ui/icons/full/obj16/branch.gif create mode 100644 plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/delegates/CreateBranchActionDelegate.java create mode 100644 plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/handlers/CreateBranchHandler.java create mode 100644 plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/OverlayImage.java (limited to 'plugins/org.eclipse.emf.cdo.ui') diff --git a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF index e0be83294a..88bb64549e 100644 --- a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF @@ -43,6 +43,16 @@ Export-Package: org.eclipse.emf.cdo.internal.ui;version="4.4.0"; org.eclipse.emf.cdo.explorer.ui, org.eclipse.emf.cdo.ui.team, org.eclipse.emf.cdo.ui.compare", + org.eclipse.emf.cdo.internal.ui.handlers;version="4.4.0"; + x-friends:="org.eclipse.emf.cdo.ui.defs, + org.eclipse.emf.cdo.ui.ide, + org.eclipse.emf.cdo.ui.location, + org.eclipse.emf.cdo.tests.ui, + org.eclipse.emf.cdo.dawn.ui, + org.eclipse.emf.cdo.explorer, + org.eclipse.emf.cdo.explorer.ui, + org.eclipse.emf.cdo.ui.team, + org.eclipse.emf.cdo.ui.compare", org.eclipse.emf.cdo.internal.ui.actions.delegates;version="4.4.0";x-internal:=true, org.eclipse.emf.cdo.internal.ui.bundle;version="4.4.0";x-internal:=true, org.eclipse.emf.cdo.internal.ui.dialogs;version="4.4.0"; diff --git a/plugins/org.eclipse.emf.cdo.ui/icons/full/obj16/branch.gif b/plugins/org.eclipse.emf.cdo.ui/icons/full/obj16/branch.gif new file mode 100644 index 0000000000..bff2b8f164 Binary files /dev/null and b/plugins/org.eclipse.emf.cdo.ui/icons/full/obj16/branch.gif differ diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml index 286d5357af..e6c249394f 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml @@ -297,4 +297,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CreateBranchAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CreateBranchAction.java index fe9f3a5b91..51f7d88302 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CreateBranchAction.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CreateBranchAction.java @@ -11,26 +11,21 @@ */ package org.eclipse.emf.cdo.internal.ui.actions; -import org.eclipse.emf.cdo.common.CDOCommonRepository.State; import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.internal.ui.dialogs.CreateBranchDialog; +import org.eclipse.emf.cdo.internal.ui.handlers.CreateBranchHandler; import org.eclipse.emf.cdo.internal.ui.messages.Messages; -import org.eclipse.emf.cdo.session.CDOSession; -import org.eclipse.emf.cdo.ui.shared.SharedIcons; -import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.ui.actions.LongRunningAction; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchPage; /** * @author Eike Stepper */ -public class CreateBranchAction extends SessionAction +public class CreateBranchAction extends LongRunningAction { public static final String ID = "create-branch"; //$NON-NLS-1$ @@ -38,100 +33,47 @@ public class CreateBranchAction extends SessionAction private static final String TOOL_TIP = Messages.getString("CreateBranchAction.1"); //$NON-NLS-1$ - private String name; - private CDOBranchPoint base; - public CreateBranchAction(IWorkbenchPage page, CDOSession session) - { - super(page, TITLE + INTERACTIVE, TOOL_TIP, null, session); - setId(ID); - } + private String name; - @Override - public boolean isEnabled() + public CreateBranchAction(IWorkbenchPage page, CDOBranchPoint base) { - if (getSession().getRepositoryInfo().getState() == State.INITIAL) - { - return false; - } - - return super.isEnabled(); + super(page, TITLE + INTERACTIVE, TOOL_TIP, null); + this.base = base; + setId(ID); } @Override protected void preRun() throws Exception { - CreateBranchDialog dialog = new CreateBranchDialog(getPage(), getSession(), null, true, null) - { - @Override - protected Control createDialogArea(Composite parent) - { - getShell().setText(TITLE); - setTitle(TITLE); - setTitleImage(SharedIcons.getImage(SharedIcons.WIZBAN_TARGET_SELECTION)); - setMessage("Enter the name of the new branch and compose a valid base point.\nYou may also choose a base point from existing commits, tags or views."); - return super.createDialogArea(parent); - } - - @Override - protected String getComposeTabTitle() - { - return "Base Point"; - } - - @Override - protected void validate() - { - super.validate(); - String name = getName(); - if (StringUtil.isEmpty(name)) - { - aggregator.setValidationError(getNameText(), "Branch name is empty."); - return; - } - - CDOBranchPoint branchPoint = getBranchPoint(); - if (branchPoint != null) - { - CDOBranch branch = branchPoint.getBranch().getBranch(name); - if (branch != null) - { - aggregator.setValidationError(getNameText(), "Branch " + branch.getPathName() + " does already exist."); - return; - } - } - - aggregator.setValidationError(getNameText(), null); - } - }; + name = CreateBranchHandler.getValidChildName(base.getBranch()); - if (dialog.open() == Dialog.OK) + CreateBranchDialog dialog = new CreateBranchDialog(getShell(), base, name); + if (dialog.open() == CreateBranchDialog.OK) { + base = dialog.getBase(); name = dialog.getName(); - base = dialog.getBranchPoint(); - if (StringUtil.isEmpty(name) || base == null) - { - cancel(); - } - } - else - { - cancel(); + return; } - super.preRun(); + base = null; + name = null; + cancel(); } @Override protected void doRun(IProgressMonitor progressMonitor) throws Exception { - long timeStamp = base.getTimeStamp(); - if (timeStamp == CDOBranchPoint.UNSPECIFIED_DATE || timeStamp == CDOBranchPoint.INVALID_DATE) + try { - timeStamp = getSession().getRepositoryInfo().getTimeStamp(); + CDOBranch branch = base.getBranch(); + branch.createBranch(name, base.getTimeStamp()); + } + finally + { + base = null; + name = null; } - - base.getBranch().createBranch(name, timeStamp); } } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/delegates/CreateBranchActionDelegate.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/delegates/CreateBranchActionDelegate.java new file mode 100644 index 0000000000..7552571331 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/delegates/CreateBranchActionDelegate.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) and others. + * 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: + * Eike Stepper - initial API and implementation + * Victor Roldan Betancort - maintenance + */ +package org.eclipse.emf.cdo.internal.ui.actions.delegates; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.internal.ui.dialogs.CreateBranchDialog; +import org.eclipse.emf.cdo.internal.ui.handlers.CreateBranchHandler; + +import org.eclipse.net4j.util.ui.actions.LongRunningActionDelegate; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Eike Stepper + */ +public class CreateBranchActionDelegate extends LongRunningActionDelegate +{ + private CDOBranchPoint base; + + private String name; + + public CreateBranchActionDelegate() + { + } + + @Override + protected void preRun() throws Exception + { + ISelection selection = getSelection(); + if (selection instanceof IStructuredSelection) + { + IStructuredSelection ssel = (IStructuredSelection)selection; + Object element = ssel.getFirstElement(); + if (element instanceof CDOBranchPoint) + { + base = (CDOBranchPoint)element; + name = CreateBranchHandler.getValidChildName(base.getBranch()); + + CreateBranchDialog dialog = new CreateBranchDialog(new Shell(), base, name); + if (dialog.open() == CreateBranchDialog.OK) + { + base = dialog.getBase(); + name = dialog.getName(); + return; + } + } + } + + base = null; + name = null; + cancel(); + } + + @Override + protected void doRun(IProgressMonitor progressMonitor) throws Exception + { + try + { + CDOBranch branch = base.getBranch(); + branch.createBranch(name, base.getTimeStamp()); + } + finally + { + base = null; + name = null; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java index f20c6b00d3..da92a4ca0b 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java @@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.internal.ui.bundle; import org.eclipse.emf.cdo.ui.CDOLabelDecorator; +import org.eclipse.emf.cdo.ui.OverlayImage; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OMPlatform; @@ -21,6 +22,13 @@ import org.eclipse.net4j.util.om.pref.OMPreferences; import org.eclipse.net4j.util.om.trace.OMTracer; import org.eclipse.net4j.util.ui.UIActivator; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.edit.provider.ComposedImage; +import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; + /** * The Operations & Maintenance class of this bundle. * @@ -61,6 +69,27 @@ public abstract class OM public static final OMPreference PREF_EDITOR_AUTO_RELOAD = // PREFS.init("PREF_EDITOR_AUTO_RELOAD", true); //$NON-NLS-1$ + public static Image getOverlayImage(Object image, Object overlayImage, int x, int y) + { + ComposedImage composedImage = new OverlayImage(image, overlayImage, x, y); + return ExtendedImageRegistry.INSTANCE.getImage(composedImage); + } + + public static Image getImage(String imagePath) + { + return ExtendedImageRegistry.INSTANCE.getImage(getBundleURI(imagePath)); + } + + public static ImageDescriptor getImageDescriptor(String imagePath) + { + return ExtendedImageRegistry.INSTANCE.getImageDescriptor(getBundleURI(imagePath)); + } + + private static URI getBundleURI(String path) + { + return URI.createPlatformPluginURI(BUNDLE_ID + "/" + path, true); + } + /** * @author Eike Stepper */ diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/CreateBranchDialog.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/CreateBranchDialog.java index 013dd8a427..341ae51c73 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/CreateBranchDialog.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/CreateBranchDialog.java @@ -4,85 +4,248 @@ * 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: * Eike Stepper - initial API and implementation */ package org.eclipse.emf.cdo.internal.ui.dialogs; +import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; -import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.ui.CDOItemProvider; +import org.eclipse.emf.cdo.ui.shared.SharedIcons; +import org.eclipse.emf.cdo.ui.widgets.SelectTimeStampComposite; +import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.StringUtil; -import org.eclipse.net4j.util.ui.UIUtil; +import org.eclipse.net4j.util.ui.ValidationContext; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPage; /** * @author Eike Stepper */ -public class CreateBranchDialog extends SelectBranchPointDialog +public class CreateBranchDialog extends TitleAreaDialog { + public static final String TITLE = "New Branch"; + + private CDOBranchPoint base; + private String name; + private TreeViewer branchViewer; + + private SelectTimeStampComposite timeStampComposite; + + private String timeStampError; + private Text nameText; - public CreateBranchDialog(IWorkbenchPage page, CDOSession session, CDOBranchPoint branchPoint, - boolean allowTimeStamp, String name) + public CreateBranchDialog(Shell parentShell, CDOBranchPoint base, String defaultName) { - super(page, session, branchPoint, allowTimeStamp); - this.name = StringUtil.safe(name); + super(parentShell); + this.base = base; + name = StringUtil.safe(defaultName); + + setShellStyle(SWT.CLOSE | SWT.RESIZE | SWT.TITLE | SWT.APPLICATION_MODAL); } - public String getName() + public CDOBranchPoint getBase() { - return name; + return base; } - public void setName(String name) + public String getName() { - this.name = name; - validate(); + return name; } - public Text getNameText() + @Override + protected Point getInitialSize() { - return nameText; + return new Point(450, 450); } @Override - protected void createBranchPointArea(Composite parent) + protected Control createDialogArea(Composite parent) { - GridLayout gridLayout = UIUtil.createGridLayout(2); - gridLayout.marginHeight = 5; - gridLayout.horizontalSpacing = 5; + getShell().setText(TITLE); + setTitle(TITLE); + setTitleImage(SharedIcons.getImage(SharedIcons.WIZBAN_TARGET_SELECTION)); + setMessage("Select a base point and enter the name of the new branch."); + + Composite area = (Composite)super.createDialogArea(parent); - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(UIUtil.createGridData(true, false)); - composite.setLayout(gridLayout); + GridLayout containerGridLayout = new GridLayout(2, false); + containerGridLayout.marginWidth = 10; + containerGridLayout.marginHeight = 10; + containerGridLayout.verticalSpacing = 10; + + Composite container = new Composite(area, SWT.NONE); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + container.setLayout(containerGridLayout); + + CDOBranch branch = base.getBranch(); + CDOItemProvider itemProvider = new CDOItemProvider(null); + + branchViewer = new TreeViewer(container, SWT.BORDER | SWT.SINGLE); + branchViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + branchViewer.setLabelProvider(itemProvider); + branchViewer.setContentProvider(itemProvider); + branchViewer.setInput(branch.getBranchManager()); + branchViewer.addSelectionChangedListener(new ISelectionChangedListener() + { + public void selectionChanged(SelectionChangedEvent event) + { + IStructuredSelection selection = (IStructuredSelection)event.getSelection(); + CDOBranch branch = (CDOBranch)selection.getFirstElement(); + + if (timeStampComposite != null) + { + timeStampComposite.setBranch(branch); + } + + composeBase(); + validate(); + } + }); + + branchViewer.setSelection(new StructuredSelection(branch)); + branchViewer.setExpandedState(branch, true); + + Group timeStampGroup = new Group(container, SWT.NONE); + timeStampGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); + timeStampGroup.setLayout(new GridLayout(1, false)); + timeStampGroup.setText("Time Stamp:"); + + timeStampComposite = new SelectTimeStampComposite(timeStampGroup, SWT.NONE, branch, base.getTimeStamp()) + { + @Override + protected void timeStampChanged(long timeStamp) + { + composeBase(); + } + }; + + timeStampComposite.getTimeBrowseButton().setVisible(false); + timeStampComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + timeStampComposite.setValidationContext(new ValidationContext() + { + public void setValidationError(Object source, String message) + { + timeStampError = message; + validate(); + } + }); - Label label = new Label(composite, SWT.NONE); - label.setLayoutData(UIUtil.createGridData(false, false)); - label.setText("Name:"); + Label newLabel = new Label(container, SWT.NONE); + newLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + newLabel.setText("Name:"); - nameText = new Text(composite, SWT.BORDER); - nameText.setLayoutData(UIUtil.createGridData(true, false)); + nameText = new Text(container, SWT.BORDER); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); nameText.setText(name); + nameText.selectAll(); + nameText.setFocus(); nameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - setName(nameText.getText()); + name = nameText.getText(); + validate(); } }); - super.createBranchPointArea(parent); + validate(); + return area; + } + + protected void validate() + { + String error = timeStampError; + + if (error == null) + { + try + { + doValidate(); + } + catch (Exception ex) + { + error = ex.getMessage(); + } + } + + setErrorMessage(error); + + Button button = getButton(IDialogConstants.OK_ID); + if (button != null) + { + button.setEnabled(error == null); + } + } + + private void doValidate() throws Exception + { + if (name.length() == 0) + { + throw new Exception("Name is empty."); + } + + if (name.contains("/") || name.contains("\\")) + { + throw new Exception("Name constains a path separator."); + } + + CDOBranch baseBranch = base.getBranch(); + CDOBranch branch = baseBranch.getBranch(name); + if (branch != null) + { + throw new Exception("Name is not unique within " + baseBranch.getPathName() + "."); + } + } + + protected void composeBase() + { + if (branchViewer == null || timeStampComposite == null) + { + return; + } + + CDOBranchPoint oldBase = base; + + IStructuredSelection selection = (IStructuredSelection)branchViewer.getSelection(); + CDOBranch branch = (CDOBranch)selection.getFirstElement(); + + long timeStamp = timeStampComposite.getTimeStamp(); + + base = branch.getPoint(timeStamp); + if (!ObjectUtil.equals(base, oldBase)) + { + baseChanged(base); + } + } + + protected void baseChanged(CDOBranchPoint base) + { } } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/handlers/CreateBranchHandler.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/handlers/CreateBranchHandler.java new file mode 100644 index 0000000000..512a4c2422 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/handlers/CreateBranchHandler.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2009-2015 Eike Stepper (Berlin, Germany) and others. + * 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.internal.ui.handlers; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchCreationContext; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.internal.ui.dialogs.CreateBranchDialog; + +import org.eclipse.net4j.util.ui.handlers.AbstractBaseHandler; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class CreateBranchHandler extends AbstractBaseHandler +{ + private CDOBranchPoint base; + + private String name; + + public CreateBranchHandler() + { + super(CDOBranchCreationContext.class, false); + } + + @Override + protected void preRun(ExecutionEvent event) throws Exception + { + if (elements.size() == 1) + { + CDOBranchCreationContext context = elements.get(0); + base = context.getBase(); + name = getValidChildName(base.getBranch()); + + Shell shell = HandlerUtil.getActiveShell(event); + CreateBranchDialog dialog = new CreateBranchDialog(shell, base, name); + if (dialog.open() == CreateBranchDialog.OK) + { + base = dialog.getBase(); + name = dialog.getName(); + return; + } + } + + base = null; + name = null; + cancel(); + } + + @Override + protected void doExecute(IProgressMonitor monitor) throws Exception + { + try + { + CDOBranch branch = base.getBranch(); + branch.createBranch(name, base.getTimeStamp()); + } + finally + { + base = null; + name = null; + } + } + + public static String getValidChildName(CDOBranch branch) + { + Set names = new HashSet(); + for (CDOBranch child : branch.getBranches()) + { + names.add(child.getName()); + } + + for (int i = 1; i < Integer.MAX_VALUE; i++) + { + String name = "branch" + i; + if (!names.contains(name)) + { + return name; + } + } + + throw new IllegalStateException("Too many sub branches: " + branch); + } + + /** + * @author Eike Stepper + */ + public static class TagHandler extends CreateBranchHandler + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java index e13e20e9bb..983850a4ba 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java @@ -27,10 +27,15 @@ import org.eclipse.net4j.util.ui.views.ContainerView; import org.eclipse.net4j.util.ui.views.IElementFilter; import org.eclipse.core.runtime.Path; +import org.eclipse.jface.action.GroupMarker; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import java.util.Collections; @@ -94,6 +99,22 @@ public class CDOSessionsView extends ContainerView super.fillLocalToolBar(manager); } + @Override + protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) + { + super.fillContextMenu(manager, selection); + + manager.add(new Separator("group.new")); + manager.add(new Separator("group.open")); + manager.add(new GroupMarker("group.openWith")); + manager.add(new Separator("group.edit")); + manager.add(new GroupMarker("group.new.branch")); + manager.add(new Separator("group.port")); + manager.add(new Separator("group.build")); + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + manager.add(new Separator("group.properties")); + } + @Override protected void doubleClicked(Object object) { diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java index 1354a016bc..7505300419 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java @@ -643,8 +643,7 @@ public class CDOItemProvider extends ContainerItemProvider> */ public void fillBranch(IMenuManager manager, CDOBranch branch) { - CDOSession session = CDOUtil.getSession(branch); - manager.add(new CreateBranchAction(page, session)); + manager.add(new CreateBranchAction(page, branch.getHead())); } /** diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/OverlayImage.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/OverlayImage.java new file mode 100644 index 0000000000..5c7a9e3b2d --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/OverlayImage.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) and others. + * 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.ui; + +import org.eclipse.emf.edit.provider.ComposedImage; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Eike Stepper + * @since 4.4 + */ +public final class OverlayImage extends ComposedImage +{ + private final int x; + + private final int y; + + public OverlayImage(Object image, Object overlayImage, int x, int y) + { + super(Arrays.asList(image, overlayImage)); + this.x = x; + this.y = y; + } + + @Override + public List getDrawPoints(Size size) + { + List result = super.getDrawPoints(size); + Point overLayPoint = result.get(1); + overLayPoint.x = x; + overLayPoint.y = y; + return result; + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java index ad68025bbb..4dc8c3496c 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java @@ -675,7 +675,30 @@ public class CommitHistoryComposite extends Composite return StringUtil.EMPTY; } - return commitInfo.getBranch().getPathName(); + CDOBranch commitBranch = commitInfo.getBranch(); + long timeStamp = commitInfo.getTimeStamp(); + + StringBuilder builder = null; + for (CDOBranch childBranch : commitBranch.getBranches()) + { + if (childBranch.getBase().getTimeStamp() == timeStamp) + { + if (builder == null) + { + builder = new StringBuilder(commitBranch.getPathName()); + } + + builder.append(", "); + builder.append(childBranch.getPathName()); + } + } + + if (builder != null) + { + return builder.toString(); + } + + return commitBranch.getPathName(); } @Override diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java index 51c2979cbf..ed23e5ca74 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java @@ -42,7 +42,7 @@ import java.text.ParseException; /** * UI widget allowing users to indicate {@link org.eclipse.emf.cdo.common.branch.CDOBranchPoint timestamp} of a * particular historical state of a {@link org.eclipse.emf.cdo.common.branch.CDOBranch branch} - * + * * @author Eike Stepper * @since 4.0 */ @@ -73,8 +73,12 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar super(parent, style); setLayout(new FillLayout()); + GridLayout layout = new GridLayout(3, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + pointGroup = new Composite(this, SWT.NONE); - pointGroup.setLayout(new GridLayout(3, false)); + pointGroup.setLayout(layout); headRadio = new Button(pointGroup, SWT.RADIO); headRadio.setText(Messages.getString("BranchSelectionDialog.1")); //$NON-NLS-1$ -- cgit v1.2.3