diff options
author | Eike Stepper | 2012-10-05 11:42:52 +0000 |
---|---|---|
committer | Eike Stepper | 2012-10-05 11:42:52 +0000 |
commit | bd3e3935ef223f341b10072f13427d5e124ff760 (patch) | |
tree | 5c9b70c19df185c6f70e4e8a07add966f2e373e9 /plugins/org.eclipse.emf.cdo.ui | |
parent | 9699c005e9832e03bf0d150f881a72df71b69880 (diff) | |
download | cdo-bd3e3935ef223f341b10072f13427d5e124ff760.tar.gz cdo-bd3e3935ef223f341b10072f13427d5e124ff760.tar.xz cdo-bd3e3935ef223f341b10072f13427d5e124ff760.zip |
[256624] [UI] Create a Commit History ViewPart drops/I20121005-0745
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256624
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui')
10 files changed, 754 insertions, 191 deletions
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 dff10a9236..b14754900b 100644 --- a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF @@ -9,8 +9,7 @@ Bundle-ClassPath: . Bundle-Localization: plugin Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport, +Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport, org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport, org.eclipse.core.filesystem;bundle-version="[1.3.0,2.0.0)";resolution:=optional, org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport, diff --git a/plugins/org.eclipse.emf.cdo.ui/build.properties b/plugins/org.eclipse.emf.cdo.ui/build.properties index 7b794ed73b..7be581652b 100644 --- a/plugins/org.eclipse.emf.cdo.ui/build.properties +++ b/plugins/org.eclipse.emf.cdo.ui/build.properties @@ -18,7 +18,8 @@ bin.includes = META-INF/,\ model/,\ .options,\ about.html,\ - copyright.txt + copyright.txt,\ + icons/ src.includes = about.html,\ copyright.txt,\ CDOClient1.launch,\ 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 81d9e0748b..84bd982ebb 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 @@ -13,7 +13,7 @@ package org.eclipse.emf.cdo.internal.ui.actions; import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; -import org.eclipse.emf.cdo.internal.ui.dialogs.SelectBranchPointDialog; +import org.eclipse.emf.cdo.internal.ui.dialogs.CreateBranchDialog; import org.eclipse.emf.cdo.internal.ui.messages.Messages; import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.ui.shared.SharedIcons; @@ -50,7 +50,7 @@ public class CreateBranchAction extends SessionAction @Override protected void preRun() throws Exception { - SelectBranchPointDialog.WithName dialog = new SelectBranchPointDialog.WithName(getPage(), getSession(), null, true, + CreateBranchDialog dialog = new CreateBranchDialog(getPage(), getSession(), null, true, null) { @Override 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 new file mode 100644 index 0000000000..4db38575d8 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/CreateBranchDialog.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2004 - 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 + */ +package org.eclipse.emf.cdo.internal.ui.dialogs; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.session.CDOSession; + +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.ui.UIUtil; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPage; + +/** + * @author Eike Stepper + */ +public class CreateBranchDialog extends SelectBranchPointDialog +{ + private String name; + + private Text nameText; + + public CreateBranchDialog(IWorkbenchPage page, CDOSession session, CDOBranchPoint branchPoint, boolean allowTimeStamp, + String name) + { + super(page, session, branchPoint, allowTimeStamp); + this.name = StringUtil.safe(name); + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + validate(); + } + + public Text getNameText() + { + return nameText; + } + + @Override + protected void createBranchPointArea(Composite parent) + { + GridLayout gridLayout = UIUtil.createGridLayout(2); + gridLayout.marginHeight = 5; + gridLayout.horizontalSpacing = 5; + + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(UIUtil.createGridData(true, false)); + composite.setLayout(gridLayout); + + Label label = new Label(composite, SWT.NONE); + label.setLayoutData(UIUtil.createGridData(false, false)); + label.setText("Name:"); + + nameText = new Text(composite, SWT.BORDER); + nameText.setLayoutData(UIUtil.createGridData(true, false)); + nameText.setText(name); + nameText.addModifyListener(new ModifyListener() + { + public void modifyText(ModifyEvent e) + { + setName(nameText.getText()); + } + }); + + super.createBranchPointArea(parent); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java index 0b428d1713..a958c9e876 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java @@ -11,10 +11,11 @@ package org.eclipse.emf.cdo.internal.ui.dialogs; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite; import org.eclipse.emf.cdo.ui.widgets.ComposeBranchPointComposite; -import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.net4j.util.ui.ValidationContext; @@ -23,15 +24,12 @@ import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPage; /** @@ -116,20 +114,22 @@ public class SelectBranchPointDialog extends TitleAreaDialog implements Validati protected void configureShell(Shell newShell) { super.configureShell(newShell); - newShell.setSize(500, 500); + newShell.setSize(700, 500); } @Override protected Control createDialogArea(Composite parent) { - Composite composite = (Composite)super.createDialogArea(parent); - composite.setLayoutData(UIUtil.createGridData()); - composite.setLayout(new GridLayout(1, false)); + Composite area = (Composite)super.createDialogArea(parent); - createBranchPointArea(composite); - UIUtil.setValidationContext(composite, aggregator); + Composite container = new Composite(area, SWT.NONE); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + container.setLayout(new GridLayout(1, false)); - return composite; + createBranchPointArea(container); + UIUtil.setValidationContext(container, aggregator); + + return area; } protected void createBranchPointArea(Composite parent) @@ -186,6 +186,17 @@ public class SelectBranchPointDialog extends TitleAreaDialog implements Validati protected void createCommitsTab(Composite parent) { + CommitHistoryComposite control = new CommitHistoryComposite(parent, SWT.NONE) + { + @Override + protected void commitInfoChanged(CDOCommitInfo newCommitInfo) + { + setBranchPoint(newCommitInfo); + } + }; + + control.setLayoutData(UIUtil.createGridData()); + control.setInput(new CommitHistoryComposite.Input(session, null)); } protected void createTagsTab(Composite parent) @@ -204,66 +215,4 @@ public class SelectBranchPointDialog extends TitleAreaDialog implements Validati protected void validate() { } - - /** - * @author Eike Stepper - */ - public static class WithName extends SelectBranchPointDialog - { - private String name; - - private Text nameText; - - public WithName(IWorkbenchPage page, CDOSession session, CDOBranchPoint branchPoint, boolean allowTimeStamp, - String name) - { - super(page, session, branchPoint, allowTimeStamp); - this.name = StringUtil.safe(name); - } - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - validate(); - } - - public Text getNameText() - { - return nameText; - } - - @Override - protected void createBranchPointArea(Composite parent) - { - GridLayout gridLayout = UIUtil.createGridLayout(2); - gridLayout.marginHeight = 5; - gridLayout.horizontalSpacing = 5; - - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(UIUtil.createGridData(true, false)); - composite.setLayout(gridLayout); - - Label label = new Label(composite, SWT.NONE); - label.setLayoutData(UIUtil.createGridData(false, false)); - label.setText("Name:"); - - nameText = new Text(composite, SWT.BORDER); - nameText.setLayoutData(UIUtil.createGridData(true, false)); - nameText.setText(name); - nameText.addModifyListener(new ModifyListener() - { - public void modifyText(ModifyEvent e) - { - setName(nameText.getText()); - } - }); - - super.createBranchPointArea(parent); - } - } } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java index ef227a9895..ed82eec876 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java @@ -571,32 +571,47 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv { if (event instanceof CDOViewTargetChangedEvent) { - Object input = selectionViewer.getInput(); - if (input == EMPTY_INPUT) + final CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event; + getSite().getShell().getDisplay().asyncExec(new Runnable() { - if (inputID != null) + public void run() { - try + Object input = selectionViewer.getInput(); + if (input == EMPTY_INPUT) { - CDOObject object = view.getObject(inputID); - selectionViewer.setInput(object); - inputID = null; + if (inputID != null) + { + try + { + CDOObject object = view.getObject(inputID); + selectionViewer.setInput(object); + inputID = null; + } + catch (Exception ex) + { + // Ignore + } + } } - catch (Exception ex) + else if (input instanceof EObject) { - // Ignore + CDOObject object = CDOUtil.getCDOObject((EObject)input); + if (object.cdoInvalid()) + { + if (e.getBranchPoint().getTimeStamp() == e.getOldBranchPoint().getTimeStamp()) + { + inputID = null; + closeEditor(); + } + else + { + inputID = object.cdoID(); + selectionViewer.setInput(EMPTY_INPUT); + } + } } } - } - else if (input instanceof EObject) - { - CDOObject object = CDOUtil.getCDOObject((EObject)input); - if (object.cdoInvalid()) - { - inputID = object.cdoID(); - selectionViewer.setInput(EMPTY_INPUT); - } - } + }); } } }; 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 bd8b234582..596ead6ace 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 @@ -52,6 +52,7 @@ import org.eclipse.emf.cdo.session.CDOSessionInvalidationEvent; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.transfer.CDOTransferElement; import org.eclipse.emf.cdo.ui.shared.SharedIcons; +import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent; @@ -109,6 +110,8 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> private IWorkbenchPage page; + private boolean mergeMainBranchWithSession; + public CDOItemProvider(IWorkbenchPage page, IElementFilter rootElementFilter) { super(rootElementFilter); @@ -138,6 +141,26 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> super.dispose(); } + /** + * @since 4.2 + */ + public boolean isMergeMainBranchWithSession() + { + return mergeMainBranchWithSession; + } + + /** + * @since 4.2 + */ + public void setMergeMainBranchWithSession(boolean mergeMainBranchWithSession) + { + if (this.mergeMainBranchWithSession != mergeMainBranchWithSession) + { + this.mergeMainBranchWithSession = mergeMainBranchWithSession; + refreshViewer(true); + } + } + @Override public Object[] getChildren(Object element) { @@ -148,7 +171,12 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (element instanceof CDOBranch) { - return ((CDOBranch)element).getBranches(); + return getChildren((CDOBranch)element); + } + + if (mergeMainBranchWithSession && element instanceof CDOSession) + { + return getChildren(((CDOSession)element).getBranchManager().getMainBranch()); } if (element instanceof CDOView) @@ -164,6 +192,46 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> return super.getChildren(element); } + /** + * @since 4.2 + */ + protected Object[] getChildren(CDOBranch branch) + { + CDOBranch[] branches = branch.getBranches(); + if (!mergeMainBranchWithSession) + { + return branch.getBranches(); + } + + Object[] views = getViews(branch); + + if (views.length == 0) + { + return branches; + } + + if (branches.length == 0) + { + return views; + } + + Object[] children = new Object[branches.length + views.length]; + System.arraycopy(branches, 0, children, 0, branches.length); + System.arraycopy(views, 0, children, branches.length, views.length); + return children; + } + + private Object[] getViews(CDOBranch branch) + { + CDOSession session = CDOUtil.getSession(branch); + if (session != null) + { + return session.getViews(branch); + } + + return NO_ELEMENTS; + } + @Override public boolean hasChildren(Object element) { @@ -174,7 +242,15 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (element instanceof CDOBranch) { - return !((CDOBranch)element).isEmpty(); + return hasChildren((CDOBranch)element); + } + + if (element instanceof CDOSession) + { + if (mergeMainBranchWithSession) + { + return hasChildren(((CDOSession)element).getBranchManager().getMainBranch()); + } } if (element instanceof CDOView) @@ -190,6 +266,20 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> return super.hasChildren(element); } + /** + * @since 4.2 + */ + protected boolean hasChildren(CDOBranch branch) + { + if (!branch.isEmpty()) + { + return true; + } + + Object[] views = getViews(branch); + return views.length != 0; + } + @Override public Object getParent(Object element) { @@ -198,6 +288,11 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> CDOBranch branch = (CDOBranch)element; if (branch.isMainBranch()) { + if (mergeMainBranchWithSession) + { + return CDOUtil.getSession(branch); + } + return branch.getBranchManager(); } @@ -216,6 +311,18 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> return parent; } + if (element instanceof CDOView) + { + CDOView view = (CDOView)element; + CDOBranch branch = view.getBranch(); + if (branch.isMainBranch() || !mergeMainBranchWithSession) + { + return view.getSession(); + } + + return branch; + } + return super.getParent(element); } @@ -360,6 +467,10 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> { fillView(manager, (CDOView)object); } + else if (object instanceof CDOBranch) + { + fillBranch(manager, (CDOBranch)object); + } else if (object instanceof CDOResourceFolder) { fillResourceFolder(manager, (CDOResourceFolder)object); @@ -375,58 +486,6 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> } /** - * @since 3.0 - */ - protected void fillResourceFolder(IMenuManager manager, CDOResourceFolder folder) - { - } - - /** - * @since 4.2 - */ - protected void fillResourceLeaf(IMenuManager manager, Object object) - { - CDOEditorUtil.populateMenu(manager, (CDOResourceLeaf)object, page); - - if (object instanceof CDOResource) - { - fillResource(manager, (CDOResource)object); - } - else if (object instanceof CDOTextResource) - { - fillTextResource(manager, (CDOTextResource)object); - } - else if (object instanceof CDOBinaryResource) - { - fillBinaryResource(manager, (CDOBinaryResource)object); - } - } - - /** - * @since 3.0 - */ - protected void fillResource(IMenuManager manager, CDOResource resource) - { - // manager.add(new OpenResourceEditorAction(page, resource)); - } - - /** - * @since 4.2 - */ - protected void fillTextResource(IMenuManager manager, CDOTextResource resource) - { - // manager.add(new OpenResourceEditorAction(page, resource)); - } - - /** - * @since 4.2 - */ - protected void fillBinaryResource(IMenuManager manager, CDOBinaryResource resource) - { - // manager.add(new OpenResourceEditorAction(page, resource)); - } - - /** * @since 2.0 */ protected void fillSession(IMenuManager manager, CDOSession session) @@ -455,7 +514,7 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (session.getRepositoryInfo().isSupportingBranches()) { manager.add(new Separator()); - manager.add(new CreateBranchAction(page, session)); + fillBranch(manager, session.getBranchManager().getMainBranch()); } manager.add(new Separator()); @@ -553,6 +612,67 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> manager.add(new CloseViewAction(page, view)); } + /** + * @since 4.2 + */ + protected void fillBranch(IMenuManager manager, CDOBranch branch) + { + CDOSession session = CDOUtil.getSession(branch); + manager.add(new CreateBranchAction(page, session)); + } + + /** + * @since 3.0 + */ + protected void fillResourceFolder(IMenuManager manager, CDOResourceFolder folder) + { + } + + /** + * @since 4.2 + */ + protected void fillResourceLeaf(IMenuManager manager, Object object) + { + CDOEditorUtil.populateMenu(manager, (CDOResourceLeaf)object, page); + + if (object instanceof CDOResource) + { + fillResource(manager, (CDOResource)object); + } + else if (object instanceof CDOTextResource) + { + fillTextResource(manager, (CDOTextResource)object); + } + else if (object instanceof CDOBinaryResource) + { + fillBinaryResource(manager, (CDOBinaryResource)object); + } + } + + /** + * @since 3.0 + */ + protected void fillResource(IMenuManager manager, CDOResource resource) + { + // manager.add(new OpenResourceEditorAction(page, resource)); + } + + /** + * @since 4.2 + */ + protected void fillTextResource(IMenuManager manager, CDOTextResource resource) + { + // manager.add(new OpenResourceEditorAction(page, resource)); + } + + /** + * @since 4.2 + */ + protected void fillBinaryResource(IMenuManager manager, CDOBinaryResource resource) + { + // manager.add(new OpenResourceEditorAction(page, resource)); + } + @Override protected void elementAdded(Object element, Object parent) { diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java index ed51a7a5e9..b6389530be 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java @@ -31,7 +31,7 @@ import org.eclipse.swt.graphics.Font; * A {@link org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider AdapterFactoryLabelProvider} specialization * that decorates {@link org.eclipse.emf.cdo.CDOObject objects} with a color/font code according to their current * {@link org.eclipse.emf.cdo.CDOState state}. - * + * * @author Eike Stepper * @see org.eclipse.jface.viewers.IColorProvider * @see org.eclipse.jface.viewers.IFontProvider 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 new file mode 100644 index 0000000000..9d5d7726d2 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java @@ -0,0 +1,353 @@ +/* + * Copyright (c) 2004 - 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 + */ +package org.eclipse.emf.cdo.ui.widgets; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.commit.CDOCommitHistory; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager; +import org.eclipse.emf.cdo.common.util.CDOCommonUtil; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.ui.shared.SharedIcons; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.ui.StructuredContentProvider; +import org.eclipse.net4j.util.ui.TableLabelProvider; + +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +/** + * @author Eike Stepper + * @since 4.2 + */ +public class CommitHistoryComposite extends Composite +{ + private CDOCommitHistory history; + + private TableViewer tableViewer; + + private LabelProvider labelProvider; + + private Input input; + + public CommitHistoryComposite(Composite parent, int style) + { + super(parent, style); + + setLayout(new FillLayout(SWT.HORIZONTAL)); + + tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + tableViewer.setContentProvider(new ContentProvider()); + + labelProvider = new LabelProvider(); + labelProvider.support(tableViewer); + } + + public final CDOCommitHistory getHistory() + { + return history; + } + + public final TableViewer getTableViewer() + { + return tableViewer; + } + + public final Input getInput() + { + return input; + } + + public final void setInput(Input input) + { + this.input = input; + + CDOSession session = input.getSession(); + String userID = session.getUserID(); + labelProvider.setLocalUserID(userID); + + CDOCommitInfoManager commitInfoManager = session.getCommitInfoManager(); + history = commitInfoManager.getHistory(input.getBranch()); + if (history.isEmpty()) + { + history.loadCommitInfos(25); + } + + tableViewer.setInput(history); + } + + @Override + public boolean setFocus() + { + return tableViewer.getTable().setFocus(); + } + + @Override + public void dispose() + { + input = null; + history = null; + super.dispose(); + } + + protected void commitInfoChanged(CDOCommitInfo newCommitInfo) + { + } + + /** + * @author Eike Stepper + */ + public static class Input + { + private final CDOSession session; + + private final CDOBranch branch; + + public Input(Object object) + { + if (object instanceof CDOSession) + { + session = (CDOSession)object; + branch = null; + return; + } + + if (object instanceof CDOView) + { + CDOView view = (CDOView)object; + session = view.getSession(); + branch = view.getBranch(); + return; + } + + if (object instanceof EObject) + { + EObject eObject = (EObject)object; + CDOObject cdoObject = CDOUtil.getCDOObject(eObject); + if (cdoObject != null) + { + CDOView view = cdoObject.cdoView(); + if (view != null) + { + session = view.getSession(); + branch = view.getBranch(); + return; + } + } + } + + throw new IllegalStateException("Illegal input: " + object); + } + + public Input(CDOSession session, CDOBranch branch) + { + this.session = session; + this.branch = branch; + } + + public final CDOSession getSession() + { + return session; + } + + public final CDOBranch getBranch() + { + return branch; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + (branch == null ? 0 : branch.hashCode()); + result = prime * result + (session == null ? 0 : session.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + + if (obj == null) + { + return false; + } + + if (!(obj instanceof Input)) + { + return false; + } + + Input other = (Input)obj; + if (branch == null) + { + if (other.branch != null) + { + return false; + } + } + else if (!branch.equals(other.branch)) + { + return false; + } + + if (session == null) + { + if (other.session != null) + { + return false; + } + } + else if (!session.equals(other.session)) + { + return false; + } + + return true; + } + + @Override + public String toString() + { + String str = session.getRepositoryInfo().getName(); + if (branch != null) + { + str += " [" + branch.getPathName() + "]"; + } + + return str; + } + } + + /** + * @author Eike Stepper + */ + public static class ContentProvider extends StructuredContentProvider<CDOCommitHistory> + { + public Object[] getElements(Object inputElement) + { + return ((CDOCommitHistory)inputElement).getElements(); + } + + @Override + protected void connectInput(CDOCommitHistory history) + { + history.addListener(this); + } + + @Override + protected void disconnectInput(CDOCommitHistory history) + { + history.removeListener(this); + } + } + + /** + * @author Eike Stepper + */ + public static class LabelProvider extends TableLabelProvider<CDOCommitInfo> + { + private static final ImageDescriptor COMMIT = SharedIcons.getDescriptor(SharedIcons.OBJ_COMMIT); + + private static final ImageDescriptor PERSON = SharedIcons.getDescriptor(SharedIcons.OBJ_PERSON); + + private static final ImageDescriptor PERSON_ME = SharedIcons.getDescriptor(SharedIcons.OBJ_PERSON_ME); + + private String localUserID; + + public LabelProvider() + { + addColumn(new Column<CDOCommitInfo>("Time", 160) + { + @Override + public String getText(CDOCommitInfo commitInfo) + { + return CDOCommonUtil.formatTimeStamp(commitInfo.getTimeStamp()); + } + + @Override + public Image getImage(CDOCommitInfo commitInfo) + { + return (Image)getResource(COMMIT); + } + }); + + addColumn(new Column<CDOCommitInfo>("Comment", 200) + { + @Override + public String getText(CDOCommitInfo commitInfo) + { + return commitInfo.getComment(); + } + }); + + addColumn(new Column<CDOCommitInfo>("User", 120) + { + @Override + public String getText(CDOCommitInfo commitInfo) + { + return commitInfo.getUserID(); + } + + @Override + public Image getImage(CDOCommitInfo commitInfo) + { + String userID = commitInfo.getUserID(); + if (userID != null) + { + if (userID.equals(localUserID)) + { + return (Image)getResource(PERSON_ME); + } + + return (Image)getResource(PERSON); + } + + return null; + } + }); + + addColumn(new Column<CDOCommitInfo>("Branch", 160) + { + @Override + public String getText(CDOCommitInfo commitInfo) + { + return commitInfo.getBranch().getPathName(); + } + }); + } + + public String getLocalUserID() + { + return localUserID; + } + + public void setLocalUserID(String localUserID) + { + this.localUserID = localUserID; + // fireLabelProviderChanged(new LabelProviderChangedEvent(this)); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectBranchComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectBranchComposite.java index 3582916143..de9cfb32cd 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectBranchComposite.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectBranchComposite.java @@ -39,7 +39,7 @@ import org.eclipse.swt.widgets.Listener; /** * UI widget that provides visualization of all available {@link org.eclipse.emf.cdo.common.branch.CDOBranch branches}, * and with the capability to select one. - * + * * @author Eike Stepper * @since 4.0 */ @@ -51,14 +51,20 @@ public class SelectBranchComposite extends Composite implements ValidationPartic private CDOBranch branch; - private IHistory<String> branchHistory; - private HistoryText branchText; private TreeViewer branchViewer; public SelectBranchComposite(Composite parent, int style, CDOSession session, CDOBranch branch) { + this(parent, style, session, branch, false); + } + + /** + * @since 4.2 + */ + public SelectBranchComposite(Composite parent, int style, CDOSession session, CDOBranch branch, boolean withHistory) + { super(parent, style); this.session = session; this.branch = branch; @@ -70,24 +76,27 @@ public class SelectBranchComposite extends Composite implements ValidationPartic setLayout(gridLayout); - String prefName = "PREF_HISTORY_BRANCHES-" + session.getRepositoryInfo().getUUID(); //$NON-NLS-1$ - OMPreference<String[]> pref = OM.PREFS.getArray(prefName); - if (pref == null) + if (withHistory) { - pref = OM.PREFS.initArray(prefName); - } + String prefName = "PREF_HISTORY_BRANCHES-" + session.getRepositoryInfo().getUUID(); //$NON-NLS-1$ + OMPreference<String[]> pref = OM.PREFS.getArray(prefName); + if (pref == null) + { + pref = OM.PREFS.initArray(prefName); + } - branchHistory = new PreferenceHistory(pref); + IHistory<String> branchHistory = new PreferenceHistory(pref); - branchText = new HistoryText(this, SWT.BORDER | SWT.SINGLE, branchHistory); - branchText.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); - branchText.getCombo().addModifyListener(new ModifyListener() - { - public void modifyText(ModifyEvent e) + branchText = new HistoryText(this, SWT.BORDER | SWT.SINGLE, branchHistory); + branchText.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); + branchText.getCombo().addModifyListener(new ModifyListener() { - setBranchFromPath(); - } - }); + public void modifyText(ModifyEvent e) + { + setBranchFromPath(); + } + }); + } CDOItemProvider itemProvider = new CDOItemProvider(null); branchViewer = new TreeViewer(this, SWT.BORDER | SWT.SINGLE); @@ -103,10 +112,20 @@ public class SelectBranchComposite extends Composite implements ValidationPartic } }); - branchText.setFocus(); setBranchFromPath(); } + @Override + public boolean setFocus() + { + if (branchText != null) + { + return branchText.setFocus(); + } + + return branchViewer.getTree().setFocus(); + } + public ValidationContext getValidationContext() { return validationContext; @@ -139,23 +158,32 @@ public class SelectBranchComposite extends Composite implements ValidationPartic public void rememberSettings() { - branchText.getHistory().add(branch.getPathName()); + if (branchText != null) + { + branchText.getHistory().add(branch.getPathName()); + } } @Override public void addListener(int eventType, Listener listener) { super.addListener(eventType, listener); - branchText.addListener(eventType, listener); branchViewer.getTree().addListener(eventType, listener); + if (branchText != null) + { + branchText.addListener(eventType, listener); + } } @Override public void removeListener(int eventType, Listener listener) { super.removeListener(eventType, listener); - branchText.removeListener(eventType, listener); branchViewer.getTree().removeListener(eventType, listener); + if (branchText != null) + { + branchText.removeListener(eventType, listener); + } } protected void branchChanged(CDOBranch newBranch) @@ -164,25 +192,28 @@ public class SelectBranchComposite extends Composite implements ValidationPartic private void setBranchFromPath() { - String branchPath = branchText.getText(); - CDOBranch newBranch = session.getBranchManager().getBranch(branchPath); - if (newBranch != branch) + if (branchText != null) { - branch = newBranch; - if (newBranch != null) - { - branchViewer.reveal(branch); - branchViewer.setSelection(new StructuredSelection(branch)); - } - else + String branchPath = branchText.getText(); + CDOBranch newBranch = session.getBranchManager().getBranch(branchPath); + if (newBranch != branch) { - branchViewer.setSelection(StructuredSelection.EMPTY); + branch = newBranch; + if (newBranch != null) + { + branchViewer.reveal(branch); + branchViewer.setSelection(new StructuredSelection(branch)); + } + else + { + branchViewer.setSelection(StructuredSelection.EMPTY); + } + + branchChanged(newBranch); } - branchChanged(newBranch); + validate(); } - - validate(); } private void setBranchFromViewer() @@ -192,7 +223,11 @@ public class SelectBranchComposite extends Composite implements ValidationPartic if (newBranch != branch) { branch = newBranch; - branchText.setText(branch.getPathName()); + if (branchText != null) + { + branchText.setText(branch.getPathName()); + } + branchChanged(newBranch); } @@ -203,7 +238,10 @@ public class SelectBranchComposite extends Composite implements ValidationPartic { if (validationContext != null) { - validationContext.setValidationError(branchText.getCombo(), branch != null ? null : "Branch does not exist."); + if (branchText != null) + { + validationContext.setValidationError(branchText.getCombo(), branch != null ? null : "Branch does not exist."); + } } } } |