Author: dazarov
Date: 2010-12-29 14:11:18 -0500 (Wed, 29 Dec 2010)
New Revision: 27802
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AbstractModifyInjectionPointWizard.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java
Log:
https://issues.jboss.org/browse/JBIDE-7635
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-29
14:40:18 UTC (rev 27801)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -85,7 +85,7 @@
public static String DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE;
public static String DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE;
public static String MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE;
- public static String COLLECTING_MARKER_RESOLUTIONS;
+ public static String SELECT_BEAN_TITLE;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE;
public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-29
14:40:18 UTC (rev 27801)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-29
19:11:18 UTC (rev 27802)
@@ -69,7 +69,7 @@
DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE=Delete @Disposes annotations from
all methods except ''{0}'' method
DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE=Delete @Inject annotations from
all constructors except ''{0}'' constructor
MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE=Make injected point unambiguous by specifying
''{0}'' bean
-COLLECTING_MARKER_RESOLUTIONS=Collecting CDI Marker Resolutions...
+SELECT_BEAN_TITLE=Select CDI Bean to configure the Injection Point
ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE=Add Qualifiers to the Bean
ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE=Available:
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-29
14:40:18 UTC (rev 27801)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -38,8 +38,8 @@
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.internal.core.impl.CDIProject;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
-import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -51,7 +51,7 @@
public class CDIProblemMarkerResolutionGenerator implements
IMarkerResolutionGenerator2 {
private static final String JAVA_EXTENSION = "java"; //$NON-NLS-1$
- IMarkerResolution[] resolutions;
+ private static final int MARKER_RESULUTION_NUMBER_LIMIT = 7;
public IMarkerResolution[] getResolutions(IMarker marker) {
try {
@@ -123,72 +123,65 @@
IInjectionPoint injectionPoint = findInjectionPoint(file, start);
if(injectionPoint != null){
List<IBean> beans = findBeans(injectionPoint);
- IMarkerResolution[] resolutions = new IMarkerResolution[beans.size()];
- for(int i = 0; i < beans.size(); i++){
- resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(injectionPoint,
beans, i);
+ if(beans.size() < MARKER_RESULUTION_NUMBER_LIMIT){
+ IMarkerResolution[] resolutions = new IMarkerResolution[beans.size()];
+ for(int i = 0; i < beans.size(); i++){
+ resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(injectionPoint,
beans, i);
+ }
+ return resolutions;
+ }else{
+ IMarkerResolution[] resolutions = new IMarkerResolution[1];
+ resolutions[0] = new SelectBeanMarkerResolution(injectionPoint, beans);
+ return resolutions;
}
- return resolutions;
}
}else if(messageId == CDIValidationErrorManager.UNSATISFIED_INJECTION_POINTS_ID){
-
- if (Display.getCurrent() != null) {
- try{
- PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new
IRunnableWithProgress(){
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- monitor.beginTask(CDIUIMessages.COLLECTING_MARKER_RESOLUTIONS, 10);
- monitor.worked(3);
- resolutions = collectMarkerResolutions(file, start);
- monitor.worked(7);
- }
- });
- }catch(InterruptedException ie){
- CDIUIPlugin.getDefault().logError(ie);
- }catch(InvocationTargetException ite){
- CDIUIPlugin.getDefault().logError(ite);
- }
- } else {
- resolutions = collectMarkerResolutions(file, start);
- }
- return resolutions;
- }
- }
- return new IMarkerResolution[] {};
- }
-
- private IMarkerResolution[] collectMarkerResolutions(IFile file, int start){
- IJavaElement element = findJavaElement(file, start);
- if(element != null){
- CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(file.getProject());
- if(cdiNature != null){
- ICDIProject cdiProject = cdiNature.getDelegate();
- if(cdiProject != null){
- Set<IBean> allBeans = cdiProject.getBeans(file.getFullPath());
+ IInjectionPoint injectionPoint = findInjectionPoint(file, start);
+ if(injectionPoint != null){
- IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(allBeans, element,
start);
-
- IBean[] bs = cdiProject.getBeans();
- ArrayList<IBean> beans = new ArrayList<IBean>();
- try{
- for(IBean b : bs){
- if(Flags.isPublic(b.getBeanClass().getFlags()))
- beans.add(b);
- }
-
+ List<IBean> beans = findLegalBeans(injectionPoint);
+ if(beans.size() < MARKER_RESULUTION_NUMBER_LIMIT){
IMarkerResolution[] resolutions = new IMarkerResolution[beans.size()];
for(int i = 0; i < beans.size(); i++){
resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(injectionPoint,
beans, i);
}
return resolutions;
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
+ }else{
+ IMarkerResolution[] resolutions = new IMarkerResolution[1];
+ resolutions[0] = new SelectBeanMarkerResolution(injectionPoint, beans);
+ return resolutions;
}
}
}
}
- return new IMarkerResolution[]{};
+ return new IMarkerResolution[] {};
}
+ private List<IBean> findLegalBeans(IInjectionPoint injectionPoint){
+ IBean[] bs = injectionPoint.getCDIProject().getBeans();
+
+ String injectionPointTypeName =
injectionPoint.getClassBean().getBeanClass().getFullyQualifiedName();
+ String injectionPointPackage =
injectionPointTypeName.substring(0,injectionPointTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+
+ ArrayList<IBean> beans = new ArrayList<IBean>();
+ for(IBean bean : bs){
+ if(CDIProject.containsType(bean.getLegalTypes(), injectionPoint.getType())){
+ boolean isPublic = true;
+ try{
+ isPublic = Flags.isPublic(bean.getBeanClass().getFlags());
+ }catch(JavaModelException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ String beanTypeName = bean.getBeanClass().getFullyQualifiedName();
+ String beanPackage =
beanTypeName.substring(0,beanTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+ if(isPublic || injectionPointPackage.equals(beanPackage))
+ beans.add(bean);
+ }
+ }
+ return beans;
+ }
+
+
private IInjectionPoint findInjectionPoint(IFile file, int start){
IJavaElement element = findJavaElement(file, start);
if(element == null)
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.ui.marker;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.internal.Workbench;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.wizard.SelectBeanWizard;
+
+/**
+ * @author Daniel Azarov
+ */
+public class SelectBeanMarkerResolution implements IMarkerResolution2 {
+ private String label;
+ private IInjectionPoint injectionPoint;
+ private List<IBean> beans;
+
+ public SelectBeanMarkerResolution(IInjectionPoint injectionPoint, List<IBean>
beans){
+ this.injectionPoint = injectionPoint;
+ this.label = CDIUIMessages.SELECT_BEAN_TITLE;
+ this.beans = beans;;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ Shell shell = Workbench.getInstance().getActiveWorkbenchWindow().getShell();
+ SelectBeanWizard wizard = new SelectBeanWizard(injectionPoint, beans);
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ int status = dialog.open();
+ if(status != WizardDialog.OK)
+ return;
+
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/SelectBeanMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AbstractModifyInjectionPointWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AbstractModifyInjectionPointWizard.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AbstractModifyInjectionPointWizard.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.ui.wizard;
+
+import java.util.List;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+
+public abstract class AbstractModifyInjectionPointWizard extends Wizard {
+ protected IInjectionPoint injectionPoint;
+ protected List<IBean> beans;
+ protected IBean bean;
+
+ public AbstractModifyInjectionPointWizard(IInjectionPoint injectionPoint,
List<IBean> beans){
+ this.injectionPoint = injectionPoint;
+ this.beans = beans;
+ }
+
+
+ public AbstractModifyInjectionPointWizard(IInjectionPoint injectionPoint,
List<IBean> beans, IBean bean){
+ this.injectionPoint = injectionPoint;
+ this.beans = beans;
+ this.bean = bean;
+ }
+
+ public IInjectionPoint getInjectionPoint(){
+ return injectionPoint;
+ }
+
+ public List<IBean> getBeans(){
+ return beans;
+ }
+
+ public IBean getBean(){
+ return bean;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AbstractModifyInjectionPointWizard.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java 2010-12-29
14:40:18 UTC (rev 27801)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -59,10 +59,10 @@
private WizardPage wizard;
// original qualifiers on the bean
- private ArrayList<IQualifier> originalQualifiers;
+ private ArrayList<IQualifier> originalQualifiers = new
ArrayList<IQualifier>();
// qualifiers available to be added to the bean
- private ArrayList<IQualifier> qualifiers;
+ private ArrayList<IQualifier> qualifiers = new ArrayList<IQualifier>();
// current qualifiers on the bean
private ArrayList<IQualifier> deployed = new ArrayList<IQualifier>();
@@ -75,21 +75,35 @@
private Button add, addAll;
private Button remove, removeAll;
+
+ private Label nLabel;
protected boolean isComplete = true;
public AddQualifiersToBeanComposite(Composite parent, WizardPage wizard) {
super(parent, SWT.NONE);
this.wizard = wizard;
- this.injectionPoint =
((AddQualifiersToBeanWizard)wizard.getWizard()).getInjectionPoint();
- this.bean = ((AddQualifiersToBeanWizard)wizard.getWizard()).getBean();
- this.beans = ((AddQualifiersToBeanWizard)wizard.getWizard()).getBeans();
+ this.injectionPoint =
((AbstractModifyInjectionPointWizard)wizard.getWizard()).getInjectionPoint();
+ this.bean = ((AbstractModifyInjectionPointWizard)wizard.getWizard()).getBean();
+ this.beans = ((AbstractModifyInjectionPointWizard)wizard.getWizard()).getBeans();
+ createControl();
+ if(bean != null)
+ init(bean);
+ }
+
+ public void init(IBean bean){
+ this.bean = bean;
originalQualifiers = new ArrayList<IQualifier>(bean.getQualifiers());
+ deployedListViewer.setInput(originalQualifiers);
+ qualifiers.clear();
+
loadAvailableQualifiers();
-
- createControl();
+ if(nLabel != null)
+ nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
+ new Object[]{bean.getBeanClass().getElementName()}));
+ refresh();
}
private void loadAvailableQualifiers(){
@@ -118,6 +132,7 @@
qualifiers.add(q);
}
}
+ availableListViewer.setInput(qualifiers);
}
@@ -196,14 +211,15 @@
}
});
- Label label = new Label(this, SWT.NONE);
+ nLabel = new Label(this, SWT.NONE);
GridData data = new GridData(GridData.FILL_HORIZONTAL |
GridData.VERTICAL_ALIGN_BEGINNING);
data.horizontalSpan = 3;
- label.setLayoutData(data);
- label.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
+ nLabel.setLayoutData(data);
+ if(bean != null)
+ nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
new Object[]{bean.getBeanClass().getElementName()}));
- label = new Label(this, SWT.NONE);
+ Label label = new Label(this, SWT.NONE);
label.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE);
label = new Label(this, SWT.NONE);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java 2010-12-29
14:40:18 UTC (rev 27801)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -12,23 +12,17 @@
import java.util.List;
-import org.eclipse.jface.wizard.Wizard;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.common.model.ui.ModelUIImages;
-public class AddQualifiersToBeanWizard extends Wizard{
- private IInjectionPoint injectionPoint;
- private List<IBean> beans;
- private IBean bean;
+public class AddQualifiersToBeanWizard extends AbstractModifyInjectionPointWizard{
private AddQualifiersToBeanWizardPage page;
public AddQualifiersToBeanWizard(IInjectionPoint injectionPoint, List<IBean>
beans, IBean bean){
- this.injectionPoint = injectionPoint;
- this.beans = beans;
- this.bean = bean;
+ super(injectionPoint, beans, bean);
setWindowTitle(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE);
setDefaultPageImageDescriptor(ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
@@ -48,15 +42,4 @@
return page.getDeployedQualifiers();
}
- public IInjectionPoint getInjectionPoint(){
- return injectionPoint;
- }
-
- public List<IBean> getBeans(){
- return beans;
- }
-
- public IBean getBean(){
- return bean;
- }
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java 2010-12-29
14:40:18 UTC (rev 27801)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -10,11 +10,11 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.wizard;
-import java.text.MessageFormat;
import java.util.ArrayList;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.ui.CDIUIMessages;
@@ -36,4 +36,8 @@
return composite.getDeployedQualifiers();
}
+ public void init(IBean bean){
+ composite.init(bean);
+ }
+
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java 2010-12-29
19:11:18 UTC (rev 27802)
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IQualifier;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.marker.MarkerResolutionUtils;
+import org.jboss.tools.common.model.ui.ModelUIImages;
+
+public class SelectBeanWizard extends AbstractModifyInjectionPointWizard{
+ private AddQualifiersToBeanWizardPage page;
+
+ public SelectBeanWizard(IInjectionPoint injectionPoint, java.util.List<IBean>
beans){
+ super(injectionPoint, beans);
+ setWindowTitle(CDIUIMessages.SELECT_BEAN_TITLE);
+
+ setDefaultPageImageDescriptor(ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
+ }
+
+ public void addPages() {
+ addPage(new SelectBeanWizardPage(""));
+ page = new AddQualifiersToBeanWizardPage("");
+ addPage(page);
+ }
+ public java.util.List<IQualifier> getDeployedQualifiers(){
+ return page.getDeployedQualifiers();
+ }
+
+ @Override
+ public boolean performFinish() {
+ return true;
+ }
+
+ class SelectBeanWizardPage extends WizardPage{
+ ListViewer listViewer;
+ protected SelectBeanWizardPage(String pageName) {
+ super(pageName);
+ setTitle(CDIUIMessages.SELECT_BEAN_TITLE);
+ setPageComplete(false);
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = 4;
+ layout.verticalSpacing = 10;
+ layout.numColumns = 1;
+ composite.setLayout(layout);
+ composite.setFont(composite.getParent().getFont());
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Select CDI Bean:");
+
+ List availableList = new List(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = 200;
+ data.widthHint = 150;
+ availableList.setLayoutData(data);
+
+ listViewer = new ListViewer(availableList);
+ ILabelProvider labelProvider = new BeanListLabelProvider();
+ listViewer.setLabelProvider(labelProvider);
+ IContentProvider contentProvider = new BeanListContentProvider();
+ listViewer.setContentProvider(contentProvider);
+ listViewer.setComparator(new ViewerComparator() {
+ public int compare(Viewer viewer, Object o1, Object o2) {
+ if (o1 instanceof IBean && o2 instanceof IBean) {
+ IBean b1 = (IBean) o1;
+ IBean b2 = (IBean) o2;
+ return
(b1.getBeanClass().getElementName().compareToIgnoreCase(b2.getBeanClass().getElementName()));
+ }
+
+ return super.compare(viewer, o1, o2);
+ }
+ });
+ listViewer.setInput(beans);
+
+ listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ bean = getSelection();
+ if(bean != null){
+ setPageComplete(true);
+ IWizardPage next = getNextPage();
+ if(next instanceof AddQualifiersToBeanWizardPage)
+ ((AddQualifiersToBeanWizardPage)next).init(bean);
+ }else
+ setPageComplete(false);
+ }
+ });
+ listViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ }
+ });
+
+ setControl(composite);
+ }
+
+ protected IBean getSelection() {
+ IStructuredSelection sel = (IStructuredSelection) listViewer.getSelection();
+ if (sel.isEmpty())
+ return null;
+
+ return (IBean)sel.getFirstElement();
+ }
+
+
+ }
+
+ class BeanListLabelProvider implements ILabelProvider{
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ if(element instanceof IBean){
+ IBean bean = (IBean)element;
+ String beanTypeName = bean.getBeanClass().getFullyQualifiedName();
+ String beanPackage =
beanTypeName.substring(0,beanTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+ String name = bean.getBeanClass().getElementName();
+
+ return name+" - "+beanPackage;
+ }
+ return "";
+ }
+
+ }
+
+ class BeanListContentProvider implements IStructuredContentProvider{
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof ArrayList){
+ return ((ArrayList)inputElement).toArray();
+ }
+ return new Object[]{};
+ }
+
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/SelectBeanWizard.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain