Author: dazarov
Date: 2010-12-25 04:06:56 -0500 (Sat, 25 Dec 2010)
New Revision: 27734
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.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
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
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-25
00:07:01 UTC (rev 27733)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-25
09:06:56 UTC (rev 27734)
@@ -84,7 +84,18 @@
public static String ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE;
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 ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_IN_BEAN;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD_ALL;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE_ALL;
+ public static String ADD_QUALIFIERS_TO_BEAN_WIZARD_CREATE_NEW_QUALIFIER;
+
public static String CDI_GENERATE_BEANS_XML;
public static String CDI_INSTALL_WIZARD_PAGE_FACET;
public static String CDI_INSTALL_WIZARD_PAGE_CONFIGURE;
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-25
00:07:01 UTC (rev 27733)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-25
09:06:56 UTC (rev 27734)
@@ -68,7 +68,19 @@
ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE=Add @LocalBean annotation to
''{0}'' class
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 adding to it
''{0}'' bean
+
+ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE=Add Qualifiers to the Bean
+ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE=Available:
+ADD_QUALIFIERS_TO_BEAN_WIZARD_IN_BEAN=In the Bean:
+ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE=Move qualifiers to the right to add them to the
''{0}'' bean
+ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD=Add >
+ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD_ALL=Add All >>
+ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE=< Remove
+ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE_ALL=<< Remove All
+ADD_QUALIFIERS_TO_BEAN_WIZARD_CREATE_NEW_QUALIFIER=Create New Qualifier
+
CDI_GENERATE_BEANS_XML=Generate beans.xml file:
CDI_INSTALL_WIZARD_PAGE_FACET=Context and Dependency Injection (CDI) Facet
CDI_INSTALL_WIZARD_PAGE_CONFIGURE=Configure Context and Dependency Injection (CDI) Facet
Settings
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-25
00:07:01 UTC (rev 27733)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-25
09:06:56 UTC (rev 27734)
@@ -12,11 +12,11 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -28,6 +28,11 @@
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDIUtil;
+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.validation.CDIValidationErrorManager;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.common.EclipseUtil;
@@ -107,26 +112,74 @@
new DeleteAllInjectedConstructorsMarkerResolution(method, file)
};
}
- }
+ }/*else if(messageId == CDIValidationErrorManager.UNSATISFIED_INJECTION_POINTS_ID ||
+ messageId == CDIValidationErrorManager.AMBIGUOUS_INJECTION_POINTS_ID){
+ List<IBean> beans = findBeans(file, start);
+ IMarkerResolution[] resolutions = new IMarkerResolution[beans.size()];
+ for(int i = 0; i < beans.size(); i++){
+ resolutions[i] = new MakeInjectedPointUnambiguousMarkerResolution(beans, file, i);
+ }
+ return resolutions;
+ }*/
}
return new IMarkerResolution[] {};
}
+ private List<IBean> findBeans(IFile file, int start){
+ IJavaElement element = findJavaElement(file, start);
+ if(element == null)
+ return null;
+
+ CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(file.getProject());
+ if(cdiNature == null)
+ return null;
+
+
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject == null){
+ return null;
+ }
+
+ Set<IBean> allBeans = cdiProject.getBeans(file.getFullPath());
+
+ //System.out.println("All beans - "+allBeans.size());
+ //System.out.println("java element - "+element.getClass());
+
+ IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(allBeans, element, start);
+ if(injectionPoint == null){
+ return null;
+ }
+
+ Set<IBean> beanSet = cdiProject.getBeans(false, injectionPoint);
+
+ //System.out.println("Beans on injected point - "+beanSet.size());
+
+ List<IBean> beanList = CDIUtil.sortBeans(beanSet);
+
+ return beanList;
+ }
+
private IMethod findMethod(IFile file, int start){
+ IJavaElement javaElement = findJavaElement(file, start);
+ if(javaElement != null && javaElement instanceof IMethod){
+ IMethod method = (IMethod)javaElement;
+ if(!method.isBinary())
+ return method;
+ }
+ return null;
+ }
+
+ private IJavaElement findJavaElement(IFile file, int start){
try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+ ICompilationUnit compilationUnit = EclipseUtil.getCompilationUnit(file);
- IJavaElement javaElement = compilationUnit.getElementAt(start);
- if(javaElement != null && javaElement instanceof IMethod){
- IMethod method = (IMethod)javaElement;
- if(!method.isBinary())
- return method;
- }
+ return compilationUnit.getElementAt(start);
}catch(CoreException ex){
CDIUIPlugin.getDefault().logError(ex);
}
return null;
+
}
private List<IType> findLocalAnnotattedInterfaces(IMethod method) throws
JavaModelException{
@@ -163,17 +216,14 @@
private IField findNonStaticField(IFile file, int start){
try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+ IJavaElement javaElement = findJavaElement(file, start);
- IJavaElement javaElement = compilationUnit.getElementAt(start);
-
if(javaElement != null && javaElement instanceof IField){
IField field = (IField)javaElement;
if(!Flags.isStatic(field.getFlags()) && !field.isBinary())
return field;
}
- }catch(CoreException ex){
+ }catch(JavaModelException ex){
CDIUIPlugin.getDefault().logError(ex);
}
return null;
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java 2010-12-25
09:06:56 UTC (rev 27734)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.text.MessageFormat;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+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.IQualifier;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.wizard.AddQualifiersToBeanWizard;
+
+/**
+ * @author Daniel Azarov
+ */
+public class MakeInjectedPointUnambiguousMarkerResolution implements IMarkerResolution2
{
+ private String label;
+ private IFile file;
+ private List<IBean> beans;
+ private IBean selectedBean;
+
+ public MakeInjectedPointUnambiguousMarkerResolution(List<IBean> beans, IFile file,
int index){
+ this.file = file;
+ this.beans = beans;
+ this.selectedBean = beans.get(index);
+ this.label = MessageFormat.format(CDIUIMessages.MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE,
new Object[]{selectedBean.getBeanClass().getElementName()});
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ if(checkBeans()){
+ //System.out.println("Should show dialog here.");
+ Shell shell = Workbench.getInstance().getActiveWorkbenchWindow().getShell();
+ AddQualifiersToBeanWizard wizard = new AddQualifiersToBeanWizard(selectedBean);
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ dialog.open();
+ }else{
+ //System.out.println("Should update injected point without dialog");
+ }
+ }
+
+ private boolean checkBeans(){
+ Set<IQualifier> qualifiers = selectedBean.getQualifiers();
+ if(qualifiers.size() == 0)
+ return true;
+
+ for(IBean bean: beans){
+ if(bean.equals(selectedBean))
+ continue;
+ if(checkBeanQualifiers(bean, qualifiers))
+ return true;
+
+ }
+ return false;
+ }
+
+ private boolean checkBeanQualifiers(IBean bean, Set<IQualifier> qualifiers){
+ for(IQualifier qualifier : qualifiers){
+ if(!isBeanContainQualifier(bean.getQualifiers(), qualifier)){
+ return false;
+ }
+ }
+ if(bean.getQualifiers().size() == qualifiers.size())
+ return true;
+ return false;
+ }
+
+ private boolean isBeanContainQualifier(Set<IQualifier> qualifiers, IQualifier
qualifier){
+ for(IQualifier q : qualifiers){
+ if(q.getSourceType().getFullyQualifiedName().equals(qualifier.getSourceType().getFullyQualifiedName()))
+ return true;
+ }
+ return false;
+ }
+
+ 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/MakeInjectedPointUnambiguousMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java 2010-12-25
09:06:56 UTC (rev 27734)
@@ -0,0 +1,443 @@
+package org.jboss.tools.cdi.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.jface.dialogs.Dialog;
+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.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+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.Display;
+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.IQualifier;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+
+public class AddQualifiersToBeanComposite extends Composite {
+ private static Font font;
+
+ // original qualifiers on the bean
+ private ArrayList<IQualifier> originalQualifiers;
+
+ // qualifiers available to be added to the bean
+ private ArrayList<IQualifier> qualifiers;
+
+ // current qualifiers on the bean
+ private ArrayList<IQualifier> deployed = new ArrayList<IQualifier>();
+
+ private ListViewer availableListViewer;
+ private ListViewer deployedListViewer;
+
+ private Button add, addAll;
+ private Button remove, removeAll;
+
+ protected boolean isComplete = true;
+
+ public AddQualifiersToBeanComposite(Composite parent, IBean bean) {
+ super(parent, SWT.NONE);
+
+ originalQualifiers = new ArrayList<IQualifier>(bean.getQualifiers());
+
+ IQualifier[] qs = bean.getCDIProject().getQualifiers();
+ qualifiers = new ArrayList<IQualifier>();
+
+ for(IQualifier q : qs){
+ if(!originalQualifiers.contains(q))
+ qualifiers.add(q);
+ }
+
+ createControl();
+ }
+
+ public void setVisible(boolean visible) {
+ if (visible)
+ this.refresh();
+ super.setVisible(visible);
+ }
+
+ public void refresh() {
+
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ if (availableListViewer == null || availableListViewer.getControl().isDisposed())
+ return;
+ availableListViewer.refresh();
+ deployedListViewer.refresh();
+ setEnablement();
+ }
+ });
+ }
+
+ protected void createControl() {
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = 4;
+ layout.verticalSpacing = 10;
+ layout.numColumns = 3;
+ setLayout(layout);
+ setFont(getParent().getFont());
+
+ Display display = getDisplay();
+ FontData[] fd = getFont().getFontData();
+ int size2 = fd.length;
+ for (int i = 0; i < size2; i++)
+ fd[i].setStyle(SWT.ITALIC);
+ font = new Font(display, fd);
+ addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ font.dispose();
+ }
+ });
+
+ Label label = new Label(this, SWT.NONE);
+ label.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_AVAILABLE);
+
+ label = new Label(this, SWT.NONE);
+ label.setText("");
+
+ label = new Label(this, SWT.NONE);
+ label.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_IN_BEAN);
+
+ List availableList = new List(this, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL |
SWT.V_SCROLL);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = 200;
+ data.widthHint = 150;
+ availableList.setLayoutData(data);
+
+ availableListViewer = new ListViewer(availableList);
+ ILabelProvider labelProvider = new QualifiersListLabelProvider();
+ availableListViewer.setLabelProvider(labelProvider);
+ IContentProvider contentProvider = new QualifiersListContentProvider();
+ availableListViewer.setContentProvider(contentProvider);
+ availableListViewer.setComparator(new ViewerComparator() {
+ public int compare(Viewer viewer, Object o1, Object o2) {
+ if (o1 instanceof IQualifier && o2 instanceof IQualifier) {
+ IQualifier q1 = (IQualifier) o1;
+ IQualifier q2 = (IQualifier) o2;
+ return
(q1.getSourceType().getFullyQualifiedName().compareToIgnoreCase(q2.getSourceType().getFullyQualifiedName()));
+ }
+
+ return super.compare(viewer, o1, o2);
+ }
+ });
+ availableListViewer.setInput(qualifiers);
+
+ availableListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ setEnablement();
+ }
+ });
+ availableListViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ setEnablement();
+ if (add.isEnabled())
+ add(false);
+ }
+ });
+
+ Composite comp = new Composite(this, SWT.NONE);
+ data = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL);
+ data.widthHint = 120;
+ comp.setLayoutData(data);
+
+ layout = new GridLayout();
+ layout.marginWidth = 5;
+ layout.marginHeight = 25;
+ layout.verticalSpacing = 20;
+ comp.setLayout(layout);
+
+ add = new Button(comp, SWT.PUSH);
+ add.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD);
+ add.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ add.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ add(false);
+ }
+ });
+
+ remove = new Button(comp, SWT.PUSH);
+ remove.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE);
+ remove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ remove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ remove(false);
+ }
+ });
+
+ label = new Label(comp, SWT.NONE);
+ label.setText("");
+
+ addAll = new Button(comp, SWT.PUSH);
+ addAll.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD_ALL);
+ addAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ addAll.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ add(true);
+ }
+ });
+
+ removeAll = new Button(comp, SWT.PUSH);
+ removeAll.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE_ALL);
+ removeAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ removeAll.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ remove(true);
+ }
+ });
+
+ List deployedList = new List(this, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL |
SWT.V_SCROLL);
+ data = new GridData(GridData.FILL_BOTH);
+ data.widthHint = 150;
+ deployedList.setLayoutData(data);
+
+ deployedListViewer = new ListViewer(deployedList);
+ deployedListViewer.setLabelProvider(labelProvider);
+ deployedListViewer.setContentProvider(contentProvider);
+ deployedListViewer.setComparator(new ViewerComparator() {
+ public int compare(Viewer viewer, Object o1, Object o2) {
+ if (o1 instanceof IQualifier && o2 instanceof IQualifier) {
+ IQualifier q1 = (IQualifier) o1;
+ IQualifier q2 = (IQualifier) o2;
+ return
(q1.getSourceType().getFullyQualifiedName().compareToIgnoreCase(q2.getSourceType().getFullyQualifiedName()));
+ }
+
+ return super.compare(viewer, o1, o2);
+ }
+ });
+ deployedListViewer.setInput(originalQualifiers);
+
+ deployedListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ setEnablement();
+ }
+ });
+ deployedListViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ setEnablement();
+ if (remove.isEnabled())
+ remove(false);
+ }
+ });
+
+ final Button createQualifier = new Button(this, SWT.PUSH);
+ createQualifier.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_CREATE_NEW_QUALIFIER);
+
+ createQualifier.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ // TODO
+ }
+ });
+
+ setEnablement();
+ availableList.setFocus();
+
+ Dialog.applyDialogFont(this);
+ }
+
+ protected IQualifier[] getAvailableSelection() {
+ IStructuredSelection sel = (IStructuredSelection) availableListViewer.getSelection();
+ if (sel.isEmpty())
+ return new IQualifier[0];
+
+ IQualifier[] mss = new IQualifier[sel.size()];
+ System.arraycopy(sel.toArray(), 0, mss, 0, sel.size());
+ return mss;
+ }
+
+ protected IQualifier[] getDeployedSelection() {
+ IStructuredSelection sel = (IStructuredSelection) deployedListViewer.getSelection();
+ if (sel.isEmpty())
+ return new IQualifier[0];
+
+ IQualifier[] mss = new IQualifier[sel.size()];
+ System.arraycopy(sel.toArray(), 0, mss, 0, sel.size());
+ return mss;
+ }
+
+ protected void setEnablement() {
+ isComplete = true;
+
+ IQualifier[] ms = getAvailableSelection();
+ if (ms == null || ms.length == 0) {
+ add.setEnabled(false);
+ } else {
+ boolean enabled = false;
+ for (int i = 0; i < ms.length; i++) {
+ IQualifier qualifier = ms[i];
+ if (qualifier != null) {
+ if (qualifiers.contains(qualifier)) {
+ enabled = true;
+ }else{
+ enabled = false;
+ break;
+ }
+ }
+ }
+ add.setEnabled(enabled);
+ }
+ addAll.setEnabled(qualifiers.size() > 0);
+
+ ms = getDeployedSelection();
+ if (ms == null || ms.length == 0) {
+ remove.setEnabled(false);
+ } else {
+ boolean enabled = false;
+ for (int i = 0; i < ms.length; i++) {
+ IQualifier qualifier = ms[i];
+ if (qualifier != null && deployed.contains(qualifier)) {
+ enabled = true;
+ }
+ else{
+ enabled = false;
+ break;
+ }
+ }
+ remove.setEnabled(enabled);
+ }
+
+ removeAll.setEnabled(deployed.size() > 0);
+ }
+
+ protected void add(boolean all) {
+ if (all) {
+ IQualifier[] qualifiers2 = new IQualifier[qualifiers.size()];
+ qualifiers.toArray(qualifiers2);
+ moveAll(qualifiers2, true);
+ } else
+ moveAll(getAvailableSelection(), true);
+ }
+
+ protected void remove(boolean all) {
+ if (all) {
+ ArrayList<IQualifier> list = new ArrayList<IQualifier>();
+ list.addAll(deployed);
+
+ IQualifier[] qualifiers2 = new IQualifier[list.size()];
+ list.toArray(qualifiers2);
+
+ moveAll(qualifiers2, false);
+ } else
+ moveAll(getDeployedSelection(), false);
+ }
+
+ protected void moveAll(IQualifier[] mods, boolean add2) {
+ int size = mods.length;
+ ArrayList<IQualifier> list = new ArrayList<IQualifier>();
+ for (int i = 0; i < size; i++) {
+ if (!list.contains(mods[i]))
+ list.add(mods[i]);
+ }
+
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ IQualifier qualifier = (IQualifier) iterator.next();
+ if (add2) {
+ qualifiers.remove(qualifier);
+ deployed.add(qualifier);
+ availableListViewer.remove(qualifier);
+ deployedListViewer.add(qualifier);
+ } else {
+ qualifiers.add(qualifier);
+ deployed.remove(qualifier);
+ availableListViewer.add(qualifier);
+ deployedListViewer.remove(qualifier);
+ }
+ }
+
+ setEnablement();
+ }
+
+
+ public ArrayList<IQualifier> getQualifiersToRemove() {
+ ArrayList<IQualifier> list = new ArrayList<IQualifier>();
+ Iterator iterator = originalQualifiers.iterator();
+ while (iterator.hasNext()) {
+ IQualifier qualifier = (IQualifier) iterator.next();
+ if (!deployed.contains(qualifier))
+ list.add(qualifier);
+ }
+ return list;
+ }
+
+ public ArrayList<IQualifier> getQualifiersToAdd() {
+ ArrayList<IQualifier> list = new ArrayList<IQualifier>();
+ Iterator iterator = deployed.iterator();
+ while (iterator.hasNext()) {
+ IQualifier qualifier = (IQualifier) iterator.next();
+ if (!originalQualifiers.contains(qualifier))
+ list.add(qualifier);
+ }
+ return list;
+ }
+
+ public boolean isComplete() {
+ return isComplete;
+ }
+
+ class QualifiersListLabelProvider 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 IQualifier){
+ IQualifier qualifier = (IQualifier)element;
+ return qualifier.getSourceType().getFullyQualifiedName();
+ }
+ return "";
+ }
+
+ }
+
+ class QualifiersListContentProvider 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[]{};
+ }
+
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java 2010-12-25
09:06:56 UTC (rev 27734)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.wizard.Wizard;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.common.model.ui.ModelUIImages;
+
+public class AddQualifiersToBeanWizard extends Wizard{
+ private IBean bean;
+
+ public AddQualifiersToBeanWizard(IBean bean){
+ this.bean = bean;
+ setWindowTitle(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE);
+
+ setDefaultPageImageDescriptor(ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
+ }
+
+ public void addPages() {
+ addPage(new AddQualifiersToBeanWizardPage(""));
+ }
+
+
+ @Override
+ public boolean performFinish() {
+ return false;
+ }
+
+ public IBean getBean(){
+ return bean;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizard.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java 2010-12-25
09:06:56 UTC (rev 27734)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.text.MessageFormat;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+
+public class AddQualifiersToBeanWizardPage extends WizardPage{
+
+ protected AddQualifiersToBeanWizardPage(String pageName) {
+ super(pageName);
+ setTitle(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_TITLE);
+ }
+
+ public void createControl(Composite parent) {
+ setControl(new AddQualifiersToBeanComposite(parent,
((AddQualifiersToBeanWizard)getWizard()).getBean()));
+ setMessage(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
+ new
Object[]{((AddQualifiersToBeanWizard)getWizard()).getBean().getBeanClass().getElementName()}));
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain