Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 199726 Details for
Bug 350359
FileUploadReceiver does not pass filename extension
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
adds an edit form either to enable automatic calculation of related projects, based on project similarities, or to manually add related projects
0001-Make-Related-Projects-box-optional.patch (text/plain), 32.07 KB, created by
Elena Nayashkova
on 2011-07-15 03:24:08 EDT
(
hide
)
Description:
adds an edit form either to enable automatic calculation of related projects, based on project similarities, or to manually add related projects
Filename:
MIME Type:
Creator:
Elena Nayashkova
Created:
2011-07-15 03:24:08 EDT
Size:
32.07 KB
patch
obsolete
>From 360d144a5650ada61cdddbf8e83dd12de461dc65 Mon Sep 17 00:00:00 2001 >From: Elena Nayashkova <elena.nayashkova@sap.com> >Date: Tue, 12 Jul 2011 14:37:04 +0200 >Subject: [PATCH] Make Related Projects box optional > >Do not show RelatedProjectsInfoBox by default. In the edit form allow to enable the calculation of related projects or manual entries. > >Bug: 350539 >Change-Id: I27a1d926fc05536acf995b77a3ec214d265219c2 >--- > .../META-INF/MANIFEST.MF | 3 +- > .../OSGI-INF/ExtensionServiceRelatedProjects.xml | 18 ++ > .../skalli/model/ext/misc/RelatedProjectsExt.java | 49 ++++ > .../internal/ExtensionServiceRelatedProjects.java | 77 ++++++ > .../META-INF/MANIFEST.MF | 1 + > .../ExtensionServiceRelatedProjectsExtEditForm.xml | 19 ++ > .../internal/forms/RelatedProjectsExtEditForm.java | 98 +++++++ > .../internal/infobox/RelatedProjectsInfoBox.java | 52 +++- > .../eclipse/skalli/view/ext/AbstractInfoBox.java | 1 + > .../VAADIN/themes/simple/styles.css | 1 + > .../VAADIN/themes/simple/styles_multicombobox.css | 16 ++ > .../skalli/view/component/MultiComboBox.java | 275 ++++++++++++++++++++ > 12 files changed, 601 insertions(+), 9 deletions(-) > create mode 100644 org.eclipse.skalli.model.ext.misc/OSGI-INF/ExtensionServiceRelatedProjects.xml > create mode 100644 org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/RelatedProjectsExt.java > create mode 100644 org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/internal/ExtensionServiceRelatedProjects.java > create mode 100644 org.eclipse.skalli.view.ext.impl/OSGI-INF/ExtensionServiceRelatedProjectsExtEditForm.xml > create mode 100644 org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/forms/RelatedProjectsExtEditForm.java > create mode 100644 org.eclipse.skalli.view/VAADIN/themes/simple/styles_multicombobox.css > create mode 100644 org.eclipse.skalli.view/src/main/java/org/eclipse/skalli/view/component/MultiComboBox.java > >diff --git a/org.eclipse.skalli.model.ext.misc/META-INF/MANIFEST.MF b/org.eclipse.skalli.model.ext.misc/META-INF/MANIFEST.MF >index 18ed1cc..d98a03f 100644 >--- a/org.eclipse.skalli.model.ext.misc/META-INF/MANIFEST.MF >+++ b/org.eclipse.skalli.model.ext.misc/META-INF/MANIFEST.MF >@@ -35,7 +35,8 @@ Service-Component: OSGI-INF/ExtensionServiceReview.xml, > OSGI-INF/ExtensionServiceLinkGroups.xml, > OSGI-INF/MailingListMappingConfigSection.xml, > OSGI-INF/ScmLocationMappingConfigSection.xml, >- OSGI-INF/ScrumPeopleProvider.xml >+ OSGI-INF/ScrumPeopleProvider.xml, >+ OSGI-INF/ExtensionServiceRelatedProjects.xml > Export-Package: org.eclipse.skalli.model.ext.devinf, > org.eclipse.skalli.model.ext.info, > org.eclipse.skalli.model.ext.linkgroups, >diff --git a/org.eclipse.skalli.model.ext.misc/OSGI-INF/ExtensionServiceRelatedProjects.xml b/org.eclipse.skalli.model.ext.misc/OSGI-INF/ExtensionServiceRelatedProjects.xml >new file mode 100644 >index 0000000..44cb930 >--- /dev/null >+++ b/org.eclipse.skalli.model.ext.misc/OSGI-INF/ExtensionServiceRelatedProjects.xml >@@ -0,0 +1,18 @@ >+<?xml version="1.0" encoding="UTF-8"?><!-- >+ Copyright (c) 2010, 2011 SAP AG 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: >+ SAP AG - initial API and implementation >+ --> >+ >+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.skalli.model.ext.related"> >+ <implementation class="org.eclipse.skalli.model.ext.misc.internal.ExtensionServiceRelatedProjects"/> >+ <service> >+ <provide interface="org.eclipse.skalli.model.ext.ExtensionService"/> >+ </service> >+</scr:component> >+ >diff --git a/org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/RelatedProjectsExt.java b/org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/RelatedProjectsExt.java >new file mode 100644 >index 0000000..6271951 >--- /dev/null >+++ b/org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/RelatedProjectsExt.java >@@ -0,0 +1,49 @@ >+/******************************************************************************* >+ * Copyright (c) 2010, 2011 SAP AG 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: >+ * SAP AG - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.skalli.model.ext.misc; >+ >+import org.eclipse.skalli.common.util.UUIDList; >+import org.eclipse.skalli.model.ext.ExtensionEntityBase; >+import org.eclipse.skalli.model.ext.PropertyName; >+ >+public class RelatedProjectsExt extends ExtensionEntityBase { >+ public static final String MODEL_VERSION = "1.0"; //$NON-NLS-1$ >+ public static final String NAMESPACE = "http://www.eclipse.org/skalli/2010/Model/Extension-Related"; //$NON-NLS-1$ >+ >+ @PropertyName(position = 0) >+ public static final String PROPERTY_CALCULATED = "calculated"; >+ >+ @PropertyName(position = 1) >+ public static final String PROPERTY_RELATED_PROJECT = "relatedProjects"; //$NON-NLS-1$ >+ >+ private UUIDList relatedProjects; >+ private boolean calculated; >+ >+ public boolean getCalculated() { >+ return calculated; >+ } >+ >+ public void setCalculated(boolean calculated) { >+ this.calculated = calculated; >+ } >+ >+ public UUIDList getRelatedProjects() { >+ if (relatedProjects == null) { >+ relatedProjects = new UUIDList(); >+ } >+ return relatedProjects; >+ } >+ >+ public void setRelatedProjects(UUIDList relatedProjects) { >+ this.relatedProjects = new UUIDList(relatedProjects); >+ } >+ >+} >diff --git a/org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/internal/ExtensionServiceRelatedProjects.java b/org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/internal/ExtensionServiceRelatedProjects.java >new file mode 100644 >index 0000000..38011e0 >--- /dev/null >+++ b/org.eclipse.skalli.model.ext.misc/src/main/java/org/eclipse/skalli/model/ext/misc/internal/ExtensionServiceRelatedProjects.java >@@ -0,0 +1,77 @@ >+/******************************************************************************* >+ * Copyright (c) 2010, 2011 SAP AG 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: >+ * SAP AG - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.skalli.model.ext.misc.internal; >+ >+import java.util.Map; >+ >+import org.eclipse.skalli.common.util.CollectionUtils; >+import org.eclipse.skalli.model.ext.ExtensionService; >+import org.eclipse.skalli.model.ext.ExtensionServiceBase; >+import org.eclipse.skalli.model.ext.misc.RelatedProjectsExt; >+ >+public class ExtensionServiceRelatedProjects extends ExtensionServiceBase<RelatedProjectsExt> >+ implements ExtensionService<RelatedProjectsExt> { >+ >+ private static final String DESCRIPTION = "Information about projects that might be related to this projects or could also be of interest."; >+ >+ private static final String CAPTION = "Related Projects"; >+ >+ private static final Map<String, String> CAPTIONS = CollectionUtils >+ .asMap(new String[][] { >+ { RelatedProjectsExt.PROPERTY_RELATED_PROJECT, "Related Project" }, >+ { RelatedProjectsExt.PROPERTY_CALCULATED, >+ "Calculate Related Projects (based on similarities to this project)" } }); >+ >+ @Override >+ public Class<RelatedProjectsExt> getExtensionClass() { >+ return RelatedProjectsExt.class; >+ } >+ >+ @Override >+ public String getModelVersion() { >+ return RelatedProjectsExt.MODEL_VERSION; >+ } >+ >+ @Override >+ public String getShortName() { >+ return "relatedProjects"; >+ } >+ >+ @Override >+ public String getCaption() { >+ return CAPTION; >+ } >+ >+ @Override >+ public String getCaption(String propertyName) { >+ String caption = CAPTIONS.get(propertyName); >+ if (caption == null) { >+ caption = super.getCaption(propertyName); >+ } >+ return caption; >+ } >+ >+ @Override >+ public String getDescription() { >+ return DESCRIPTION; >+ } >+ >+ @Override >+ public String getNamespace() { >+ return RelatedProjectsExt.NAMESPACE; >+ } >+ >+ @Override >+ public String getXsdFileName() { >+ return null; >+ } >+ >+} >diff --git a/org.eclipse.skalli.view.ext.impl/META-INF/MANIFEST.MF b/org.eclipse.skalli.view.ext.impl/META-INF/MANIFEST.MF >index 5ee01e5..a36a059 100644 >--- a/org.eclipse.skalli.view.ext.impl/META-INF/MANIFEST.MF >+++ b/org.eclipse.skalli.view.ext.impl/META-INF/MANIFEST.MF >@@ -41,6 +41,7 @@ Service-Component: OSGI-INF/ExtensionServiceProjectBasicsEditForm.xml, > OSGI-INF/ExtensionServiceMavenProjectExtEditForm.xml, > OSGI-INF/ExtensionServiceReviewProjectExtEditForm.xml, > OSGI-INF/ExtensionServiceScrumProjectExtEditForm.xml, >+ OSGI-INF/ExtensionServiceRelatedProjectsExtEditForm.xml, > OSGI-INF/ExtensionServiceProjectAboutBox.xml, > OSGI-INF/ExtensionServiceProjectDevInfBox.xml, > OSGI-INF/ExtensionServiceProjectIssuesBox.xml, >diff --git a/org.eclipse.skalli.view.ext.impl/OSGI-INF/ExtensionServiceRelatedProjectsExtEditForm.xml b/org.eclipse.skalli.view.ext.impl/OSGI-INF/ExtensionServiceRelatedProjectsExtEditForm.xml >new file mode 100644 >index 0000000..5347b3e >--- /dev/null >+++ b/org.eclipse.skalli.view.ext.impl/OSGI-INF/ExtensionServiceRelatedProjectsExtEditForm.xml >@@ -0,0 +1,19 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<!-- >+ Copyright (c) 2010, 2011 SAP AG 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: >+ SAP AG - initial API and implementation >+ --> >+ >+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.skalli.view.ext.impl.internal.forms.related"> >+ <implementation class="org.eclipse.skalli.view.ext.impl.internal.forms.RelatedProjectsExtEditForm"/> >+ <service> >+ <provide interface="org.eclipse.skalli.view.ext.ExtensionFormService"/> >+ </service> >+</scr:component> >+ >diff --git a/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/forms/RelatedProjectsExtEditForm.java b/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/forms/RelatedProjectsExtEditForm.java >new file mode 100644 >index 0000000..0041689 >--- /dev/null >+++ b/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/forms/RelatedProjectsExtEditForm.java >@@ -0,0 +1,98 @@ >+/******************************************************************************* >+ * Copyright (c) 2010, 2011 SAP AG 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: >+ * SAP AG - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.skalli.view.ext.impl.internal.forms; >+ >+import org.eclipse.skalli.common.util.UUIDList; >+import org.eclipse.skalli.model.core.Project; >+import org.eclipse.skalli.model.ext.misc.RelatedProjectsExt; >+import org.eclipse.skalli.view.component.MultiComboBox; >+import org.eclipse.skalli.view.ext.AbstractExtensionFormService; >+import org.eclipse.skalli.view.ext.DefaultProjectFieldFactory; >+import org.eclipse.skalli.view.ext.ProjectEditContext; >+ >+import com.vaadin.data.Item; >+import com.vaadin.data.Property.ValueChangeListener; >+import com.vaadin.data.util.BeanItem; >+import com.vaadin.ui.CheckBox; >+import com.vaadin.ui.Field; >+import com.vaadin.ui.FormFieldFactory; >+ >+public class RelatedProjectsExtEditForm extends AbstractExtensionFormService<RelatedProjectsExt> { >+ >+ @Override >+ public String getIconPath() { >+ return "res/icons/relProjects.png"; //$NON-NLS-1$ >+ } >+ >+ @Override >+ public float getRank() { >+ return 1.5f; >+ } >+ >+ @Override >+ protected FormFieldFactory getFieldFactory(Project project, ProjectEditContext context) { >+ return new FieldFactory(project, context); >+ } >+ >+ @Override >+ protected Item getItemDataSource(Project project) { >+ return new BeanItem<RelatedProjectsExt>(getExtension(project)); >+ } >+ >+ private class FieldFactory extends DefaultProjectFieldFactory<RelatedProjectsExt> { >+ >+ private static final long serialVersionUID = 939519704283769367L; >+ private RelatedProjectsExt extension; >+ private Field comboBox; >+ >+ public FieldFactory(Project project, ProjectEditContext context) { >+ super(project, RelatedProjectsExt.class, context); >+ this.extension = getExtension(project); >+ } >+ >+ @Override >+ protected Field createField(Object propertyId, String caption) { >+ >+ if (RelatedProjectsExt.PROPERTY_CALCULATED.equals(propertyId)) { >+ final CheckBox field = new CheckBox(caption); >+ field.setImmediate(true); >+ field.addListener(new ValueChangeListener() { >+ >+ private static final long serialVersionUID = 3996507266934851419L; >+ >+ @Override >+ public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { >+ if (comboBox != null) { >+ comboBox.setEnabled(!field.booleanValue()); >+ } >+ } >+ }); >+ return field; >+ } else if (RelatedProjectsExt.PROPERTY_RELATED_PROJECT.equals(propertyId)) { >+ UUIDList ids = extension.getRelatedProjects(); >+ comboBox = new MultiComboBox(caption, ids); >+ comboBox.setEnabled(!extension.getCalculated()); >+ return comboBox; >+ } >+ return null; >+ } >+ } >+ >+ @Override >+ public Class<RelatedProjectsExt> getExtensionClass() { >+ return RelatedProjectsExt.class; >+ } >+ >+ @Override >+ public RelatedProjectsExt newExtensionInstance() { >+ return new RelatedProjectsExt(); >+ } >+} >diff --git a/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/infobox/RelatedProjectsInfoBox.java b/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/infobox/RelatedProjectsInfoBox.java >index a42d25d..a74d084 100644 >--- a/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/infobox/RelatedProjectsInfoBox.java >+++ b/org.eclipse.skalli.view.ext.impl/src/main/java/org/eclipse/skalli/view/ext/impl/internal/infobox/RelatedProjectsInfoBox.java >@@ -10,19 +10,25 @@ > *******************************************************************************/ > package org.eclipse.skalli.view.ext.impl.internal.infobox; > >+import java.util.UUID; >+ >+import org.eclipse.skalli.api.java.ProjectService; > import org.eclipse.skalli.api.java.SearchHit; > import org.eclipse.skalli.api.java.SearchResult; > import org.eclipse.skalli.api.java.SearchService; > import org.eclipse.skalli.common.Services; >+import org.eclipse.skalli.common.util.UUIDList; > import org.eclipse.skalli.model.core.Project; >+import org.eclipse.skalli.model.ext.misc.RelatedProjectsExt; > import org.eclipse.skalli.view.ext.AbstractInfoBox; > import org.eclipse.skalli.view.ext.ExtensionUtil; > import org.eclipse.skalli.view.ext.ProjectInfoBox; >+ > import com.vaadin.terminal.ExternalResource; > import com.vaadin.ui.Component; > import com.vaadin.ui.CssLayout; >+import com.vaadin.ui.Label; > import com.vaadin.ui.Layout; >-import com.vaadin.ui.Link; > > public class RelatedProjectsInfoBox extends AbstractInfoBox implements ProjectInfoBox { > >@@ -41,18 +47,47 @@ public class RelatedProjectsInfoBox extends AbstractInfoBox implements ProjectIn > Layout layout = new CssLayout(); > layout.setSizeFull(); > >+ RelatedProjectsExt ext = project.getExtension(RelatedProjectsExt.class); >+ if (ext != null) { >+ Label label = new Label("The following projects might also be of interest to you:", >+ Label.CONTENT_XHTML); >+ layout.addComponent(label); >+ boolean calculated = ext.getCalculated(); >+ if (calculated) { >+ addCalculatedContent(project, layout); >+ } else { >+ UUIDList ids = ext.getRelatedProjects(); >+ ProjectService projectService = Services.getRequiredService(ProjectService.class); >+ for (UUID uuid : ids) { >+ Project relatedProject = projectService.getByUUID(uuid); >+ ExternalResource externalResource = new ExternalResource("/projects/" + relatedProject.getProjectId()); >+ String content = HSPACE + "<a href=" + externalResource.getURL() + ">" + relatedProject.getName() >+ + "</a>"; >+ Label l = new Label(content, Label.CONTENT_XHTML); >+ layout.addComponent(l); >+ } >+ } >+ } >+ return layout; >+ } >+ >+ protected void addCalculatedContent(Project project, Layout layout) { > SearchService searchService = Services.getService(SearchService.class); > if (searchService != null) { > SearchResult<Project> relatedProjects = searchService.getRelatedProjects(project, 5); > for (SearchHit<Project> hit : relatedProjects.getResult()) { >- Link link = new Link(); >- link.setCaption(hit.getEntity().getName()); >- link.setResource(new ExternalResource("/projects/" + hit.getEntity().getProjectId())); //$NON-NLS-1$ >- layout.addComponent(link); >+ ExternalResource externalResource = new ExternalResource("/projects/" + hit.getEntity().getProjectId()); >+ String content = HSPACE + "<a href=" + externalResource.getURL() + ">" + hit.getEntity().getName() >+ + "*</a>"; >+ Label label = new Label(content, Label.CONTENT_XHTML); >+ layout.addComponent(label); > } >- } >+ Label label = new Label(HSPACE + "*calculated based on similarities between the projects", >+ Label.CONTENT_XHTML); >+ label.setStyleName("light");//$NON-NLS-1$ >+ layout.addComponent(label); > >- return layout; >+ } > } > > @Override >@@ -67,7 +102,8 @@ public class RelatedProjectsInfoBox extends AbstractInfoBox implements ProjectIn > > @Override > public boolean isVisible(Project project, String loggedInUserId) { >- if (project.isDeleted()) { >+ RelatedProjectsExt ext = project.getExtension(RelatedProjectsExt.class); >+ if (ext == null || ext.getRelatedProjects().isEmpty()) { > return false; > } else { > return true; >diff --git a/org.eclipse.skalli.view.ext/src/main/java/org/eclipse/skalli/view/ext/AbstractInfoBox.java b/org.eclipse.skalli.view.ext/src/main/java/org/eclipse/skalli/view/ext/AbstractInfoBox.java >index c05fbf4..f7f874e 100644 >--- a/org.eclipse.skalli.view.ext/src/main/java/org/eclipse/skalli/view/ext/AbstractInfoBox.java >+++ b/org.eclipse.skalli.view.ext/src/main/java/org/eclipse/skalli/view/ext/AbstractInfoBox.java >@@ -15,5 +15,6 @@ public abstract class AbstractInfoBox { > protected static final String STYLE_LABEL = "infolabel"; > protected static final String STYLE_LINK = "infolink"; > protected static final String STYLE_TEAMLABEL = "teamlabel"; >+ protected static final String HSPACE = " "; //$NON-NLS-1$ > > } >diff --git a/org.eclipse.skalli.view/VAADIN/themes/simple/styles.css b/org.eclipse.skalli.view/VAADIN/themes/simple/styles.css >index 4103451..947f456 100644 >--- a/org.eclipse.skalli.view/VAADIN/themes/simple/styles.css >+++ b/org.eclipse.skalli.view/VAADIN/themes/simple/styles.css >@@ -7,6 +7,7 @@ > @import url(styles_tray.css); > @import url(styles_peoplesearch.css); > @import url(styles_multitext.css); >+ @import url(styles_multicombobox.css); > > .v-app { > background: #fff; >diff --git a/org.eclipse.skalli.view/VAADIN/themes/simple/styles_multicombobox.css b/org.eclipse.skalli.view/VAADIN/themes/simple/styles_multicombobox.css >new file mode 100644 >index 0000000..3fbb675 >--- /dev/null >+++ b/org.eclipse.skalli.view/VAADIN/themes/simple/styles_multicombobox.css >@@ -0,0 +1,16 @@ >+.multicombobox-layout { >+ >+} >+ >+.multicombobox-line { >+ margin-bottom: 5px; >+} >+ >+.multicombobox-btn { >+ margin-left: 5px; >+ margin-top: 5px; >+} >+ >+.multicombobox-btn .v-button-caption { >+ font-size: x-small; >+} >\ No newline at end of file >diff --git a/org.eclipse.skalli.view/src/main/java/org/eclipse/skalli/view/component/MultiComboBox.java b/org.eclipse.skalli.view/src/main/java/org/eclipse/skalli/view/component/MultiComboBox.java >new file mode 100644 >index 0000000..fd5547a >--- /dev/null >+++ b/org.eclipse.skalli.view/src/main/java/org/eclipse/skalli/view/component/MultiComboBox.java >@@ -0,0 +1,275 @@ >+/******************************************************************************* >+ * Copyright (c) 2010, 2011 SAP AG 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: >+ * SAP AG - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.skalli.view.component; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.Iterator; >+import java.util.List; >+import java.util.UUID; >+ >+import org.apache.commons.lang.StringUtils; >+import org.eclipse.skalli.api.java.ProjectService; >+import org.eclipse.skalli.common.Services; >+import org.eclipse.skalli.common.util.UUIDList; >+import org.eclipse.skalli.model.core.Project; >+import org.eclipse.skalli.model.ext.PropertyName; >+ >+import com.vaadin.data.Item; >+import com.vaadin.data.Validator.InvalidValueException; >+import com.vaadin.data.util.IndexedContainer; >+import com.vaadin.ui.AbstractSelect; >+import com.vaadin.ui.AbstractSelect.Filtering; >+import com.vaadin.ui.Button; >+import com.vaadin.ui.Button.ClickEvent; >+import com.vaadin.ui.ComboBox; >+import com.vaadin.ui.CustomField; >+import com.vaadin.ui.HorizontalLayout; >+import com.vaadin.ui.Select; >+import com.vaadin.ui.VerticalLayout; >+ >+public class MultiComboBox extends CustomField { >+ >+ private static final long serialVersionUID = -2946220818606365985L; >+ >+ private static final String STYLE_LAYOUT = "multicombobox-layout"; >+ private static final String STYLE_LINE_LAYOUT = "multicombobox-line"; >+ private static final String STYLE_BUTTON = "multicombobox-btn"; >+ >+ private UUIDList values; >+ private VerticalLayout layout; >+ private List<ComboBoxElement> comboBoxEntries; >+ private String description; >+ private boolean readOnly; >+ private int columns; >+ >+ private static class ComboBoxElement { >+ public ComboBoxElement(ComboBox comboBox) { >+ this.comboBox = comboBox; >+ comboBox.setItemCaptionPropertyId(ProjectDataSource.PROPERTY_DISPLAYNAME); >+ comboBox.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); >+ comboBox.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); >+ comboBox.setImmediate(true); >+ comboBox.setNewItemsAllowed(false); >+ comboBox.setNullSelectionAllowed(true); >+ } >+ >+ ComboBox comboBox; >+ Button removeButton; >+ } >+ >+ public MultiComboBox(String caption, UUIDList values) { >+ if (values == null) { >+ throw new IllegalArgumentException("argument 'values' must not be null"); >+ } >+ setCaption(caption); >+ this.values = values; >+ init(values); >+ layout = new VerticalLayout(); >+ layout.setStyleName(STYLE_LAYOUT); >+ renderComboBoxes(); >+ setCompositionRoot(layout); >+ } >+ >+ private void renderComboBoxes() { >+ boolean hasMultipleEntries = comboBoxEntries.size() > 1; >+ int last = comboBoxEntries.size() - 1; >+ for (int i = 0; i <= last; ++i) { >+ ComboBoxElement comboBoxEntry = comboBoxEntries.get(i); >+ HorizontalLayout horLayout = new HorizontalLayout(); >+ horLayout.setStyleName(STYLE_LINE_LAYOUT); >+ ComboBox comboBox = comboBoxEntry.comboBox; >+ if (comboBox.getValue() == null) { >+ comboBox.setEnabled(!readOnly); >+ } else { >+ comboBox.setReadOnly(readOnly); >+ } >+ horLayout.addComponent(comboBox); >+ >+ if (hasMultipleEntries) { >+ Button b = createRemoveButton(); >+ comboBoxEntry.removeButton = b; >+ horLayout.addComponent(b); >+ } >+ if (i == last) { >+ horLayout.addComponent(createAddButton()); >+ } >+ >+ layout.addComponent(horLayout); >+ } >+ } >+ >+ private void init(UUIDList values) { >+ comboBoxEntries = new ArrayList<ComboBoxElement>(); >+ if (values != null && !values.isEmpty()) { >+ for (UUID value : values) { >+ ComboBox comboBox = createComboBox(value); >+ comboBoxEntries.add(new ComboBoxElement(comboBox)); >+ } >+ } else { >+ ComboBox comboBox = createComboBox(null); >+ comboBoxEntries.add(new ComboBoxElement(comboBox)); >+ } >+ } >+ >+ private ComboBox createComboBox(UUID uuid) { >+ ComboBox comboBox = new ComboBox(null, new ProjectDataSource()); >+ if (description != null) { >+ comboBox.setDescription(description); >+ } >+ if (uuid != null) { >+ ProjectService projectService = Services.getRequiredService(ProjectService.class); >+ Project project = projectService.getByUUID(uuid); >+ comboBox.select(project); >+ } >+ return comboBox; >+ } >+ >+ public void setColumns(int columns) { >+ this.columns = columns; >+ for (ComboBoxElement entry : comboBoxEntries) { >+ entry.comboBox.setWidth(columns, Select.UNITS_EM); >+ } >+ } >+ >+ private Button createAddButton() { >+ Button b = new Button("Add"); >+ b.setStyleName(Button.STYLE_LINK); >+ b.addStyleName(STYLE_BUTTON); >+ b.setDescription("Add another entry"); >+ b.setEnabled(!readOnly); >+ b.addListener(new Button.ClickListener() { >+ @Override >+ public void buttonClick(ClickEvent event) { >+ ComboBox cb = createComboBox(null); >+ cb.setWidth(columns, Select.UNITS_EM); >+ comboBoxEntries.add(new ComboBoxElement(cb)); >+ layout.removeAllComponents(); >+ renderComboBoxes(); >+ } >+ }); >+ return b; >+ } >+ >+ private Button createRemoveButton() { >+ Button b = new Button("Remove"); >+ b.setStyleName(Button.STYLE_LINK); >+ b.addStyleName(STYLE_BUTTON); >+ b.setDescription("Remove this entry"); >+ b.addListener(new Button.ClickListener() { >+ @Override >+ public void buttonClick(ClickEvent event) { >+ Button b = event.getButton(); >+ Iterator<ComboBoxElement> it = comboBoxEntries.iterator(); >+ while (it.hasNext()) { >+ ComboBoxElement element = it.next(); >+ if (element.removeButton == b) { >+ it.remove(); >+ break; >+ } >+ } >+ layout.removeAllComponents(); >+ renderComboBoxes(); >+ } >+ }); >+ return b; >+ } >+ >+ @Override >+ public void setDescription(String description) { >+ this.description = description; >+ for (ComboBoxElement element : comboBoxEntries) { >+ element.comboBox.setDescription(description); >+ } >+ } >+ >+ @Override >+ public Object getValue() { >+ UUIDList uuid = new UUIDList(comboBoxEntries.size()); >+ copyValues(uuid); >+ return uuid; >+ } >+ >+ @Override >+ public void commit() throws SourceException, InvalidValueException { >+ values.clear(); >+ copyValues(values); >+ } >+ >+ private void copyValues(UUIDList values) { >+ for (ComboBoxElement entry : comboBoxEntries) { >+ Project project = (Project) entry.comboBox.getValue(); >+ if (project == null) { >+ return; >+ } >+ UUID value = project.getUuid(); >+ if (StringUtils.isNotBlank(value.toString())) { >+ values.add(value); >+ } >+ } >+ } >+ >+ @Override >+ public Class<?> getType() { >+ return Collection.class; >+ } >+ >+ private static class ProjectDataSource extends IndexedContainer { >+ >+ private static final long serialVersionUID = 8192530422436522676L; >+ >+ @PropertyName(position = 0) >+ public static final Object PROPERTY_DISPLAYNAME = "displayName"; >+ >+ public ProjectDataSource() { >+ super(); >+ addContainerProperty(Project.PROPERTY_NAME, String.class, null); >+ addContainerProperty(Project.PROPERTY_PROJECTID, String.class, null); >+ addContainerProperty(PROPERTY_DISPLAYNAME, String.class, null); >+ >+ ProjectService projectService = Services.getRequiredService(ProjectService.class); >+ List<Project> projects = projectService.getAll(); >+ for (Project project : projects) { >+ addItem(project); >+ } >+ sort(new Object[] { Project.PROPERTY_NAME, Project.PROPERTY_PROJECTID }, new boolean[] { true, true }); >+ } >+ >+ private Item addItem(Project project) { >+ // item key = project instance >+ Item item = getItem(project); >+ if (item == null) { >+ item = super.addItem(project); // IndexedContainer#addItem return null, if entry already exists!!! >+ } >+ if (item != null) { >+ String projectId = project.getProjectId(); >+ String name = project.getName(); >+ item.getItemProperty(Project.PROPERTY_NAME).setValue(name); >+ item.getItemProperty(Project.PROPERTY_PROJECTID).setValue(projectId); >+ item.getItemProperty(PROPERTY_DISPLAYNAME).setValue(name + " <" + projectId + ">"); >+ } >+ return item; >+ } >+ } >+ >+ @Override >+ public void setReadOnly(boolean readOnly) { >+ this.readOnly = readOnly; >+ layout.removeAllComponents(); >+ renderComboBoxes(); >+ } >+ >+ @Override >+ public boolean isReadOnly() { >+ return readOnly; >+ } >+ >+} >-- >1.7.0.2.msysgit.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 350359
: 199726