Author: dazarov
Date: 2011-03-10 17:03:09 -0500 (Thu, 10 Mar 2011)
New Revision: 29678
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java
Removed:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/MarkerProblemAnnotationHoverProcessor.java
Modified:
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/AddQualifiersToBeanWizardPage.java
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/QuickFixProposal.java
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/XMLTextViewerConfiguration.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
Log:
https://issues.jboss.org/browse/JBIDE-8350
Modified:
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 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeInjectedPointUnambiguousMarkerResolution.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -28,8 +28,8 @@
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.wizard.AddQualifiersToBeanComposite;
import org.jboss.tools.cdi.ui.wizard.AddQualifiersToBeanWizard;
+import org.jboss.tools.cdi.ui.wizard.xpl.AddQualifiersToBeanComposite;
/**
* @author Daniel Azarov
Deleted:
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 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanComposite.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -1,661 +0,0 @@
-package org.jboss.tools.cdi.ui.wizard;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IMessageProvider;
-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.StructuredSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-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.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.SearchPattern;
-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.CDIUIPlugin;
-import org.jboss.tools.cdi.ui.marker.MarkerResolutionUtils;
-
-public class AddQualifiersToBeanComposite extends Composite {
- private static Font font;
- private IInjectionPoint injectionPoint;
- private IBean bean;
- private java.util.List<IBean> beans;
- private WizardPage wizard;
- private Text pattern;
-
- // original qualifiers on the bean
- private ArrayList<IQualifier> originalQualifiers = new
ArrayList<IQualifier>();
-
- // qualifiers available to be added to the bean
- private ArrayList<IQualifier> qualifiers = new ArrayList<IQualifier>();
-
- // current qualifiers on the bean
- private ArrayList<IQualifier> deployed = new ArrayList<IQualifier>();
-
- // original + deployed
- ArrayList<IQualifier> total = new ArrayList<IQualifier>();
-
- private ListViewer availableListViewer;
- private ListViewer deployedListViewer;
-
- 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 =
((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();
- if(nLabel != null)
- nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
- new Object[]{bean.getBeanClass().getElementName()}));
- refresh();
- }
-
- private void loadAvailableQualifiers(){
- String beanTypeName = bean.getBeanClass().getFullyQualifiedName();
- String beanPackage =
beanTypeName.substring(0,beanTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
-
- String injectionPointTypeName =
injectionPoint.getClassBean().getBeanClass().getFullyQualifiedName();
- String injectionPointPackage =
injectionPointTypeName.substring(0,injectionPointTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
-
- boolean samePackage = beanPackage.equals(injectionPointPackage);
-
- IQualifier[] qs = bean.getCDIProject().getQualifiers();
- qualifiers = new ArrayList<IQualifier>();
-
- for(IQualifier q : qs){
- if(!originalQualifiers.contains(q)){
- boolean isPublic = true;
- try{
- isPublic = Flags.isPublic(q.getSourceType().getFlags());
- }catch(JavaModelException ex){
- CDIUIPlugin.getDefault().logError(ex);
- }
- String qualifierTypeName = q.getSourceType().getFullyQualifiedName();
- String qualifierPackage =
qualifierTypeName.substring(0,qualifierTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
- if(isPublic || (samePackage &&
injectionPointPackage.equals(qualifierPackage)))
- qualifiers.add(q);
- }
- }
- availableListViewer.setInput(qualifiers);
-
- }
-
- 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();
- }
- });
- }
-
- public boolean checkBeans(){
- total.clear();
- total.addAll(originalQualifiers);
- total.addAll(deployed);
- HashSet<IQualifier> qfs = new HashSet<IQualifier>(total);
-
- for(IBean b: beans){
- if(b.equals(bean))
- continue;
- if(checkBeanQualifiers(b, qfs))
- return false;
-
- }
- return true;
- }
-
- public static 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;
- }
-
- public static boolean isBeanContainQualifier(Set<IQualifier> qualifiers,
IQualifier qualifier){
- for(IQualifier q : qualifiers){
- if(q.getSourceType().getFullyQualifiedName().equals(qualifier.getSourceType().getFullyQualifiedName()))
- return true;
- }
- return false;
- }
-
-
- 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();
- }
- });
-
- nLabel = new Label(this, SWT.NONE);
- GridData data = new GridData(GridData.FILL_HORIZONTAL |
GridData.VERTICAL_ALIGN_BEGINNING);
- data.horizontalSpan = 3;
- nLabel.setLayoutData(data);
- if(bean != null)
- nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
- new Object[]{bean.getBeanClass().getElementName()}));
-
- Label label = new Label(this, SWT.NONE);
- label.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_ENTER_QUALIFIER_NAME);
- label.setLayoutData(data);
-
- pattern = new Text(this, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- pattern.setLayoutData(data);
- pattern.addModifyListener(new ModifyListener(){
- public void modifyText(ModifyEvent e){
- availableListViewer.refresh();
- }
- });
- pattern.setFocus();
-
- label = new Label(this, SWT.NONE);
- label.setText("");
-
- label = new Label(this, SWT.NONE);
- label.setText("");
-
- 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);
- 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().getElementName().compareToIgnoreCase(q2.getSourceType().getElementName()));
- }
-
- 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);
- }
- });
- availableListViewer.addFilter(new QualifierFilter());
-
- 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().getElementName().compareToIgnoreCase(q2.getSourceType().getElementName()));
- }
-
- 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) {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- NewQualifierCreationWizard wizard = new NewQualifierCreationWizard();
- StructuredSelection selection = new StructuredSelection(new
Object[]{bean.getBeanClass()});
-
- wizard.init(PlatformUI.getWorkbench(), selection);
- WizardDialog dialog = new WizardDialog(shell, wizard);
- int status = dialog.open();
- if(status == WizardDialog.OK){
- // reload qualifiers
- try {
- Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
- } catch (InterruptedException e) {
- // do nothing
- }
-
- qualifiers.clear();
-
- loadAvailableQualifiers();
-
- refresh();
- }
- }
- });
-
- 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);
-
- // check uniqueness of qualifiers
- isComplete = checkBeans();
- if(isComplete)
- wizard.setMessage("");
- else
- wizard.setMessage(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_SET_IS_NOT_UNIQUE,
IMessageProvider.ERROR);
-
- wizard.setPageComplete(isComplete);
- }
-
- 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;
- }
-
- public ArrayList<IQualifier> getDeployedQualifiers(){
- total.clear();
- total.addAll(originalQualifiers);
- total.addAll(deployed);
-
- return total;
- }
-
- public void deploy(IQualifier qualifier){
- IQualifier[] qualifiers = new IQualifier[]{qualifier};
- moveAll(qualifiers, true);
- }
-
- public ArrayList<IQualifier> getAvailableQualifiers(){
- return qualifiers;
- }
-
- 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;
- String qualifierTypeName = qualifier.getSourceType().getFullyQualifiedName();
- String qualifierPackage =
qualifierTypeName.substring(0,qualifierTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
- String name = qualifier.getSourceType().getElementName();
-
- return name+" - "+qualifierPackage;
- }
- 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[]{};
- }
-
- }
-
- public class QualifierFilter extends ViewerFilter {
- SearchPattern patternMatcher = new SearchPattern();
- public boolean isConsistentItem(Object item) {
- return true;
- }
-
- public boolean select(Viewer viewer, Object parentElement,
- Object element) {
-
- if (element instanceof IQualifier) {
- String qualifierTypeName =
((IQualifier)element).getSourceType().getFullyQualifiedName();
- if(pattern.getText().isEmpty())
- patternMatcher.setPattern("*");
- else
- patternMatcher.setPattern(pattern.getText());
- boolean result = patternMatcher.matches(qualifierTypeName);
- if (!result) {
- String pattern = patternMatcher.getPattern();
- if (pattern.indexOf(".") < 0) {
- int lastIndex = qualifierTypeName.lastIndexOf(".");
- if (lastIndex >= 0
- && (lastIndex + 1) < qualifierTypeName.length())
- return patternMatcher.matches(qualifierTypeName.substring(lastIndex + 1));
- }
- }
- return result;
- }
- return false;
- }
- }
-
-}
\ No newline at end of file
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 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/AddQualifiersToBeanWizardPage.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -17,6 +17,7 @@
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.xpl.AddQualifiersToBeanComposite;
public class AddQualifiersToBeanWizardPage extends WizardPage{
Copied:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java
(from rev 29661,
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/xpl/AddQualifiersToBeanComposite.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -0,0 +1,675 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2011 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * Exadel, Inc.
+ * Red Hat, Inc.
+ *******************************************************************************/
+package org.jboss.tools.cdi.ui.wizard.xpl;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IMessageProvider;
+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.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+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.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SearchPattern;
+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.CDIUIPlugin;
+import org.jboss.tools.cdi.ui.marker.MarkerResolutionUtils;
+import org.jboss.tools.cdi.ui.wizard.AbstractModifyInjectionPointWizard;
+import org.jboss.tools.cdi.ui.wizard.NewQualifierCreationWizard;
+
+public class AddQualifiersToBeanComposite extends Composite {
+ private static Font font;
+ private IInjectionPoint injectionPoint;
+ private IBean bean;
+ private java.util.List<IBean> beans;
+ private WizardPage wizard;
+ private Text pattern;
+
+ // original qualifiers on the bean
+ private ArrayList<IQualifier> originalQualifiers = new
ArrayList<IQualifier>();
+
+ // qualifiers available to be added to the bean
+ private ArrayList<IQualifier> qualifiers = new ArrayList<IQualifier>();
+
+ // current qualifiers on the bean
+ private ArrayList<IQualifier> deployed = new ArrayList<IQualifier>();
+
+ // original + deployed
+ ArrayList<IQualifier> total = new ArrayList<IQualifier>();
+
+ private ListViewer availableListViewer;
+ private ListViewer deployedListViewer;
+
+ 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 =
((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();
+ if(nLabel != null)
+ nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
+ new Object[]{bean.getBeanClass().getElementName()}));
+ refresh();
+ }
+
+ private void loadAvailableQualifiers(){
+ String beanTypeName = bean.getBeanClass().getFullyQualifiedName();
+ String beanPackage =
beanTypeName.substring(0,beanTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+
+ String injectionPointTypeName =
injectionPoint.getClassBean().getBeanClass().getFullyQualifiedName();
+ String injectionPointPackage =
injectionPointTypeName.substring(0,injectionPointTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+
+ boolean samePackage = beanPackage.equals(injectionPointPackage);
+
+ IQualifier[] qs = bean.getCDIProject().getQualifiers();
+ qualifiers = new ArrayList<IQualifier>();
+
+ for(IQualifier q : qs){
+ if(!originalQualifiers.contains(q)){
+ boolean isPublic = true;
+ try{
+ isPublic = Flags.isPublic(q.getSourceType().getFlags());
+ }catch(JavaModelException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ String qualifierTypeName = q.getSourceType().getFullyQualifiedName();
+ String qualifierPackage =
qualifierTypeName.substring(0,qualifierTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+ if(isPublic || (samePackage &&
injectionPointPackage.equals(qualifierPackage)))
+ qualifiers.add(q);
+ }
+ }
+ availableListViewer.setInput(qualifiers);
+
+ }
+
+ 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();
+ }
+ });
+ }
+
+ public boolean checkBeans(){
+ total.clear();
+ total.addAll(originalQualifiers);
+ total.addAll(deployed);
+ HashSet<IQualifier> qfs = new HashSet<IQualifier>(total);
+
+ for(IBean b: beans){
+ if(b.equals(bean))
+ continue;
+ if(checkBeanQualifiers(b, qfs))
+ return false;
+
+ }
+ return true;
+ }
+
+ public static 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;
+ }
+
+ public static boolean isBeanContainQualifier(Set<IQualifier> qualifiers,
IQualifier qualifier){
+ for(IQualifier q : qualifiers){
+ if(q.getSourceType().getFullyQualifiedName().equals(qualifier.getSourceType().getFullyQualifiedName()))
+ return true;
+ }
+ return false;
+ }
+
+
+ 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();
+ }
+ });
+
+ nLabel = new Label(this, SWT.NONE);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL |
GridData.VERTICAL_ALIGN_BEGINNING);
+ data.horizontalSpan = 3;
+ nLabel.setLayoutData(data);
+ if(bean != null)
+ nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
+ new Object[]{bean.getBeanClass().getElementName()}));
+
+ Label label = new Label(this, SWT.NONE);
+ label.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_ENTER_QUALIFIER_NAME);
+ label.setLayoutData(data);
+
+ pattern = new Text(this, SWT.BORDER);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ pattern.setLayoutData(data);
+ pattern.addModifyListener(new ModifyListener(){
+ public void modifyText(ModifyEvent e){
+ availableListViewer.refresh();
+ }
+ });
+ pattern.setFocus();
+
+ label = new Label(this, SWT.NONE);
+ label.setText("");
+
+ label = new Label(this, SWT.NONE);
+ label.setText("");
+
+ 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);
+ 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().getElementName().compareToIgnoreCase(q2.getSourceType().getElementName()));
+ }
+
+ 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);
+ }
+ });
+ availableListViewer.addFilter(new QualifierFilter());
+
+ 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().getElementName().compareToIgnoreCase(q2.getSourceType().getElementName()));
+ }
+
+ 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) {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ NewQualifierCreationWizard wizard = new NewQualifierCreationWizard();
+ StructuredSelection selection = new StructuredSelection(new
Object[]{bean.getBeanClass()});
+
+ wizard.init(PlatformUI.getWorkbench(), selection);
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ int status = dialog.open();
+ if(status == WizardDialog.OK){
+ // reload qualifiers
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+
+ qualifiers.clear();
+
+ loadAvailableQualifiers();
+
+ refresh();
+ }
+ }
+ });
+
+ 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);
+
+ // check uniqueness of qualifiers
+ isComplete = checkBeans();
+ if(isComplete)
+ wizard.setMessage("");
+ else
+ wizard.setMessage(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_SET_IS_NOT_UNIQUE,
IMessageProvider.ERROR);
+
+ wizard.setPageComplete(isComplete);
+ }
+
+ 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;
+ }
+
+ public ArrayList<IQualifier> getDeployedQualifiers(){
+ total.clear();
+ total.addAll(originalQualifiers);
+ total.addAll(deployed);
+
+ return total;
+ }
+
+ public void deploy(IQualifier qualifier){
+ IQualifier[] qualifiers = new IQualifier[]{qualifier};
+ moveAll(qualifiers, true);
+ }
+
+ public ArrayList<IQualifier> getAvailableQualifiers(){
+ return qualifiers;
+ }
+
+ 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;
+ String qualifierTypeName = qualifier.getSourceType().getFullyQualifiedName();
+ String qualifierPackage =
qualifierTypeName.substring(0,qualifierTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
+ String name = qualifier.getSourceType().getElementName();
+
+ return name+" - "+qualifierPackage;
+ }
+ 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[]{};
+ }
+
+ }
+
+ public class QualifierFilter extends ViewerFilter {
+ SearchPattern patternMatcher = new SearchPattern();
+ public boolean isConsistentItem(Object item) {
+ return true;
+ }
+
+ public boolean select(Viewer viewer, Object parentElement,
+ Object element) {
+
+ if (element instanceof IQualifier) {
+ String qualifierTypeName =
((IQualifier)element).getSourceType().getFullyQualifiedName();
+ if(pattern.getText().isEmpty())
+ patternMatcher.setPattern("*");
+ else
+ patternMatcher.setPattern(pattern.getText());
+ boolean result = patternMatcher.matches(qualifierTypeName);
+ if (!result) {
+ String pattern = patternMatcher.getPattern();
+ if (pattern.indexOf(".") < 0) {
+ int lastIndex = qualifierTypeName.lastIndexOf(".");
+ if (lastIndex >= 0
+ && (lastIndex + 1) < qualifierTypeName.length())
+ return patternMatcher.matches(qualifierTypeName.substring(lastIndex + 1));
+ }
+ }
+ return result;
+ }
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/MarkerProblemAnnotationHoverProcessor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/MarkerProblemAnnotationHoverProcessor.java 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/MarkerProblemAnnotationHoverProcessor.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -1,379 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Exadel, Inc. and 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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.text.xml;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.AbstractInformationControl;
-import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IInformationControlExtension2;
-import org.eclipse.jface.text.IInformationControlExtension4;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ITextHoverExtension;
-import org.eclipse.jface.text.ITextHoverExtension2;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.ScrolledComposite;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.ScrollBar;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
-import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
-import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor;
-
-public class MarkerProblemAnnotationHoverProcessor extends
ProblemAnnotationHoverProcessor implements ITextHoverExtension, ITextHoverExtension2{
-
- private IInformationControlCreator controlCreator = null;
- private static IInformationControlCreator presenterControlCreator;
-
- public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) {
- return null;
- }
-
- public Object getHoverInfo2(ITextViewer viewer, IRegion hoverRegion) {
- IAnnotationModel model = ((SourceViewer) viewer).getAnnotationModel();
- if (model != null) {
- Iterator<Annotation> iterator = model.getAnnotationIterator();
- while (iterator.hasNext()) {
- Annotation annotation = (Annotation) iterator.next();
- if (!isAnnotationValid(annotation))
- continue;
-
- Position position = model.getPosition(annotation);
-
- if (position.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
- return new MarkerAnnotationInfo((SimpleMarkerAnnotation)annotation, position,
viewer);
- }
- }
- }
- return null;
- }
-
- public IInformationControlCreator getInformationPresenterControlCreator() {
- if (presenterControlCreator == null)
- presenterControlCreator= new PresenterControlCreator();
- return presenterControlCreator;
- }
-
- protected boolean isAnnotationValid(Annotation annotation) {
- if(annotation instanceof SimpleMarkerAnnotation)
- return true;
- return false;
- }
-
- public IInformationControlCreator getHoverControlCreator() {
- if (controlCreator == null)
- controlCreator= new
AnnotationHoverControlCreator(getInformationPresenterControlCreator());
- return controlCreator;
- }
-
- private static class MarkerAnnotationInformationControl extends
AbstractInformationControl implements IInformationControlExtension2{
- private final DefaultMarkerAnnotationAccess annotationAccess;
- private MarkerAnnotationInfo info;
- private Composite parent;
-
- public MarkerAnnotationInformationControl(Shell parentShell,
- String str) {
- super(parentShell, str);
- annotationAccess= new DefaultMarkerAnnotationAccess();
- create();
- }
-
- public boolean hasContents() {
- return info != null;
- }
-
- private MarkerAnnotationInfo getAnnotationInfo() {
- return info;
- }
-
- @Override
- protected void createContent(Composite parent) {
- this.parent = parent;
- GridLayout layout= new GridLayout(1, false);
- layout.verticalSpacing= 0;
- layout.marginWidth= 0;
- layout.marginHeight= 0;
- parent.setLayout(layout);
- }
-
- public final void setVisible(boolean visible) {
- if (!visible)
- disposeContent();
- super.setVisible(visible);
- }
-
- public Point computeSizeHint() {
- Point preferedSize= getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-
- Point constrains= getSizeConstraints();
- if (constrains == null)
- return preferedSize;
-
- Point constrainedSize= getShell().computeSize(constrains.x, SWT.DEFAULT, true);
-
- int width= Math.min(preferedSize.x, constrainedSize.x);
- int height= Math.max(preferedSize.y, constrainedSize.y);
-
- return new Point(width, height);
- }
-
- public void setInput(Object input) {
- Assert.isLegal(input instanceof MarkerAnnotationInfo);
- info = (MarkerAnnotationInfo)input;
- disposeContent();
- createContent();
- }
-
- protected void disposeContent() {
- for (Control child : parent.getChildren()) {
- child.dispose();
- }
- }
-
- protected void createContent() {
- createInfo(parent, getAnnotationInfo().annotation);
- setDecoration(parent, parent.getForeground(), parent.getBackground(),
JFaceResources.getDialogFont());
-
- QuickFixProposal[] proposals = getAnnotationInfo().getCompletionProposals();
- if (proposals.length > 0)
- createControl(parent, proposals);
-
- parent.layout(true);
- }
-
- private void createControl(Composite parent, QuickFixProposal[] proposals) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout2 = new GridLayout(1, false);
- layout2.marginHeight = 0;
- layout2.marginWidth = 0;
- layout2.verticalSpacing = 2;
- composite.setLayout(layout2);
-
- Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
- GridData gridData= new GridData(SWT.FILL, SWT.CENTER, true, false);
- separator.setLayoutData(gridData);
-
- Label quickFixLabel= new Label(composite, SWT.NONE);
- GridData layoutData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
- layoutData.horizontalIndent = 4;
- quickFixLabel.setLayoutData(layoutData);
- String text;
- if (proposals.length == 1) {
- text= TextXMLMessages.SINGLE_QUICK_FIX;
- } else {
- text= NLS.bind(TextXMLMessages.MULTIPLE_QUICK_FIX, proposals.length);
- }
- quickFixLabel.setText(text);
-
- setDecoration(composite, parent.getForeground(), parent.getBackground(),
JFaceResources.getDialogFont());
- createList(composite, proposals);
- }
-
- private void createList(Composite parent, QuickFixProposal[] proposals) {
- final ScrolledComposite scrolledComposite= new ScrolledComposite(parent, SWT.V_SCROLL
| SWT.H_SCROLL);
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- scrolledComposite.setLayoutData(gridData);
- scrolledComposite.setExpandVertical(false);
- scrolledComposite.setExpandHorizontal(false);
-
- Composite composite = new Composite(scrolledComposite, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout(2, false);
- layout.marginLeft = 5;
- layout.verticalSpacing = 2;
- composite.setLayout(layout);
-
- List<Link> list = new ArrayList<Link>();
- for (QuickFixProposal proposal : proposals) {
- list.add(createLink(composite, proposal));
- }
-
- scrolledComposite.setContent(composite);
- setDecoration(scrolledComposite, parent.getForeground(), parent.getBackground(),
JFaceResources.getDialogFont());
-
- Point contentSize= composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- composite.setSize(contentSize);
-
- Point constraints= getSizeConstraints();
- if (constraints != null && contentSize.x < constraints.x) {
- ScrollBar horizontalBar= scrolledComposite.getHorizontalBar();
-
- int scrollBarHeight;
- if (horizontalBar == null) {
- Point scrollSize = scrolledComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- scrollBarHeight = scrollSize.y - contentSize.y;
- } else {
- scrollBarHeight = horizontalBar.getSize().y;
- }
- gridData.heightHint = contentSize.y - scrollBarHeight;
- }
- }
-
- private Link createLink(Composite parent, final QuickFixProposal proposal) {
- Link proposalLink = new Link(parent, SWT.WRAP);
- GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
- String linkText = proposal.getDisplayString();
- proposalLink.setText("<a>" + linkText + "</a>");
//$NON-NLS-1$ //$NON-NLS-2$
- proposalLink.setLayoutData(layoutData);
- proposalLink.addMouseListener(new MouseListener(){
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- public void mouseDown(MouseEvent e) {
- fix(proposal, info.viewer, info.position.offset);
- }
-
- public void mouseUp(MouseEvent e) {
- }
- });
- return proposalLink;
- }
-
- private void fix(QuickFixProposal p, ITextViewer viewer, int offset) {
- dispose();
-
- IRewriteTarget target = null;
- try {
- IDocument document = viewer.getDocument();
-
- if (viewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) viewer;
- target= extension.getRewriteTarget();
- }
-
- if (target != null)
- target.beginCompoundChange();
-
- p.apply(document);
-
- Point selection = p.getSelection(document);
- if (selection != null) {
- viewer.setSelectedRange(selection.x, selection.y);
- viewer.revealRange(selection.x, selection.y);
- }
- } finally {
- if (target != null)
- target.endCompoundChange();
- }
- }
-
- private void createInfo(Composite parent, final Annotation annotation) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- GridLayout layout = new GridLayout(2, false);
- layout.marginHeight = 2;
- layout.marginWidth = 2;
- layout.horizontalSpacing = 0;
- composite.setLayout(layout);
-
- final Canvas canvas = new Canvas(composite, SWT.NO_FOCUS);
- GridData gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
- gridData.widthHint = 17;
- gridData.heightHint = 16;
- canvas.setLayoutData(gridData);
- canvas.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- e.gc.setFont(null);
- annotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
- }
- });
-
- StyledText text = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- text.setLayoutData(data);
- String annotationText = annotation.getText();
- if (annotationText != null)
- text.setText(annotationText);
- }
-
- private void setDecoration(Control control, Color foreground, Color background, Font
font) {
- control.setForeground(foreground);
- control.setBackground(background);
- control.setFont(font);
-
- if (control instanceof Composite) {
- for (Control child : ((Composite) control).getChildren()) {
- setDecoration(child, foreground, background, font);
- }
- }
- }
-
- }
-
- private static final class AnnotationHoverControlCreator extends
AbstractReusableInformationControlCreator {
- private final IInformationControlCreator presenterControlCreator;
-
- public AnnotationHoverControlCreator(IInformationControlCreator
presenterControlCreator) {
- this.presenterControlCreator = presenterControlCreator;
- }
-
- public IInformationControl doCreateInformationControl(Shell parent) {
- return new MarkerAnnotationInformationControl(parent,
EditorsUI.getTooltipAffordanceString()) {
- public IInformationControlCreator getInformationPresenterControlCreator() {
- return presenterControlCreator;
- }
- };
- }
-
- public boolean canReuse(IInformationControl control) {
- if (!super.canReuse(control))
- return false;
-
- if (control instanceof IInformationControlExtension4)
- ((IInformationControlExtension4)
control).setStatusText(EditorsUI.getTooltipAffordanceString());
-
- return true;
- }
- }
-
- private static final class PresenterControlCreator extends
AbstractReusableInformationControlCreator {
- public IInformationControl doCreateInformationControl(Shell parent) {
- return new MarkerAnnotationInformationControl(parent,
EditorsUI.getTooltipAffordanceString()) {
- public IInformationControlCreator getInformationPresenterControlCreator() {
- return presenterControlCreator;
- }
- };
- }
- }
-
-}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/QuickFixProposal.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/QuickFixProposal.java 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/QuickFixProposal.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -19,7 +19,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
-class QuickFixProposal implements ICompletionProposal{
+public class QuickFixProposal implements ICompletionProposal{
private IMarkerResolution resolution;
private IMarker marker;
Modified:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/XMLTextViewerConfiguration.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/XMLTextViewerConfiguration.java 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/XMLTextViewerConfiguration.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -35,6 +35,7 @@
import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML;
import
org.eclipse.wst.xml.ui.internal.contentassist.XMLStructuredContentAssistProcessor;
import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
+import org.jboss.tools.common.text.xml.xpl.MarkerProblemAnnotationHoverProcessor;
/**
* @author Igels
Copied:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java
(from rev 29661,
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/MarkerProblemAnnotationHoverProcessor.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -0,0 +1,384 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2011 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * Exadel, Inc.
+ * Red Hat, Inc.
+ *******************************************************************************/
+package org.jboss.tools.common.text.xml.xpl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.AbstractInformationControl;
+import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IInformationControlExtension2;
+import org.eclipse.jface.text.IInformationControlExtension4;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.IRewriteTarget;
+import org.eclipse.jface.text.ITextHoverExtension;
+import org.eclipse.jface.text.ITextHoverExtension2;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITextViewerExtension;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.ScrollBar;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
+import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
+import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor;
+import org.jboss.tools.common.text.xml.MarkerAnnotationInfo;
+import org.jboss.tools.common.text.xml.QuickFixProposal;
+import org.jboss.tools.common.text.xml.TextXMLMessages;
+
+public class MarkerProblemAnnotationHoverProcessor extends
ProblemAnnotationHoverProcessor implements ITextHoverExtension, ITextHoverExtension2{
+
+ private IInformationControlCreator controlCreator = null;
+ private static IInformationControlCreator presenterControlCreator;
+
+ public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) {
+ return null;
+ }
+
+ public Object getHoverInfo2(ITextViewer viewer, IRegion hoverRegion) {
+ IAnnotationModel model = ((SourceViewer) viewer).getAnnotationModel();
+ if (model != null) {
+ Iterator<Annotation> iterator = model.getAnnotationIterator();
+ while (iterator.hasNext()) {
+ Annotation annotation = (Annotation) iterator.next();
+ if (!isAnnotationValid(annotation))
+ continue;
+
+ Position position = model.getPosition(annotation);
+
+ if (position.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
+ return new MarkerAnnotationInfo((SimpleMarkerAnnotation)annotation, position,
viewer);
+ }
+ }
+ }
+ return null;
+ }
+
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ if (presenterControlCreator == null)
+ presenterControlCreator= new PresenterControlCreator();
+ return presenterControlCreator;
+ }
+
+ protected boolean isAnnotationValid(Annotation annotation) {
+ if(annotation instanceof SimpleMarkerAnnotation)
+ return true;
+ return false;
+ }
+
+ public IInformationControlCreator getHoverControlCreator() {
+ if (controlCreator == null)
+ controlCreator= new
AnnotationHoverControlCreator(getInformationPresenterControlCreator());
+ return controlCreator;
+ }
+
+ private static class MarkerAnnotationInformationControl extends
AbstractInformationControl implements IInformationControlExtension2{
+ private final DefaultMarkerAnnotationAccess annotationAccess;
+ private MarkerAnnotationInfo info;
+ private Composite parent;
+
+ public MarkerAnnotationInformationControl(Shell parentShell,
+ String str) {
+ super(parentShell, str);
+ annotationAccess= new DefaultMarkerAnnotationAccess();
+ create();
+ }
+
+ public boolean hasContents() {
+ return info != null;
+ }
+
+ private MarkerAnnotationInfo getAnnotationInfo() {
+ return info;
+ }
+
+ @Override
+ protected void createContent(Composite parent) {
+ this.parent = parent;
+ GridLayout layout= new GridLayout(1, false);
+ layout.verticalSpacing= 0;
+ layout.marginWidth= 0;
+ layout.marginHeight= 0;
+ parent.setLayout(layout);
+ }
+
+ public final void setVisible(boolean visible) {
+ if (!visible)
+ disposeContent();
+ super.setVisible(visible);
+ }
+
+ public Point computeSizeHint() {
+ Point preferedSize= getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+
+ Point constrains= getSizeConstraints();
+ if (constrains == null)
+ return preferedSize;
+
+ Point constrainedSize= getShell().computeSize(constrains.x, SWT.DEFAULT, true);
+
+ int width= Math.min(preferedSize.x, constrainedSize.x);
+ int height= Math.max(preferedSize.y, constrainedSize.y);
+
+ return new Point(width, height);
+ }
+
+ public void setInput(Object input) {
+ Assert.isLegal(input instanceof MarkerAnnotationInfo);
+ info = (MarkerAnnotationInfo)input;
+ disposeContent();
+ createContent();
+ }
+
+ protected void disposeContent() {
+ for (Control child : parent.getChildren()) {
+ child.dispose();
+ }
+ }
+
+ protected void createContent() {
+ createInfo(parent, getAnnotationInfo().annotation);
+ setDecoration(parent, parent.getForeground(), parent.getBackground(),
JFaceResources.getDialogFont());
+
+ QuickFixProposal[] proposals = getAnnotationInfo().getCompletionProposals();
+ if (proposals.length > 0)
+ createControl(parent, proposals);
+
+ parent.layout(true);
+ }
+
+ private void createControl(Composite parent, QuickFixProposal[] proposals) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ GridLayout layout2 = new GridLayout(1, false);
+ layout2.marginHeight = 0;
+ layout2.marginWidth = 0;
+ layout2.verticalSpacing = 2;
+ composite.setLayout(layout2);
+
+ Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridData gridData= new GridData(SWT.FILL, SWT.CENTER, true, false);
+ separator.setLayoutData(gridData);
+
+ Label quickFixLabel= new Label(composite, SWT.NONE);
+ GridData layoutData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
+ layoutData.horizontalIndent = 4;
+ quickFixLabel.setLayoutData(layoutData);
+ String text;
+ if (proposals.length == 1) {
+ text= TextXMLMessages.SINGLE_QUICK_FIX;
+ } else {
+ text= NLS.bind(TextXMLMessages.MULTIPLE_QUICK_FIX, proposals.length);
+ }
+ quickFixLabel.setText(text);
+
+ setDecoration(composite, parent.getForeground(), parent.getBackground(),
JFaceResources.getDialogFont());
+ createList(composite, proposals);
+ }
+
+ private void createList(Composite parent, QuickFixProposal[] proposals) {
+ final ScrolledComposite scrolledComposite= new ScrolledComposite(parent, SWT.V_SCROLL
| SWT.H_SCROLL);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ scrolledComposite.setLayoutData(gridData);
+ scrolledComposite.setExpandVertical(false);
+ scrolledComposite.setExpandHorizontal(false);
+
+ Composite composite = new Composite(scrolledComposite, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginLeft = 5;
+ layout.verticalSpacing = 2;
+ composite.setLayout(layout);
+
+ List<Link> list = new ArrayList<Link>();
+ for (QuickFixProposal proposal : proposals) {
+ list.add(createLink(composite, proposal));
+ }
+
+ scrolledComposite.setContent(composite);
+ setDecoration(scrolledComposite, parent.getForeground(), parent.getBackground(),
JFaceResources.getDialogFont());
+
+ Point contentSize= composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ composite.setSize(contentSize);
+
+ Point constraints= getSizeConstraints();
+ if (constraints != null && contentSize.x < constraints.x) {
+ ScrollBar horizontalBar= scrolledComposite.getHorizontalBar();
+
+ int scrollBarHeight;
+ if (horizontalBar == null) {
+ Point scrollSize = scrolledComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ scrollBarHeight = scrollSize.y - contentSize.y;
+ } else {
+ scrollBarHeight = horizontalBar.getSize().y;
+ }
+ gridData.heightHint = contentSize.y - scrollBarHeight;
+ }
+ }
+
+ private Link createLink(Composite parent, final QuickFixProposal proposal) {
+ Link proposalLink = new Link(parent, SWT.WRAP);
+ GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
+ String linkText = proposal.getDisplayString();
+ proposalLink.setText("<a>" + linkText + "</a>");
//$NON-NLS-1$ //$NON-NLS-2$
+ proposalLink.setLayoutData(layoutData);
+ proposalLink.addMouseListener(new MouseListener(){
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+
+ public void mouseDown(MouseEvent e) {
+ fix(proposal, info.viewer, info.position.offset);
+ }
+
+ public void mouseUp(MouseEvent e) {
+ }
+ });
+ return proposalLink;
+ }
+
+ private void fix(QuickFixProposal p, ITextViewer viewer, int offset) {
+ dispose();
+
+ IRewriteTarget target = null;
+ try {
+ IDocument document = viewer.getDocument();
+
+ if (viewer instanceof ITextViewerExtension) {
+ ITextViewerExtension extension= (ITextViewerExtension) viewer;
+ target= extension.getRewriteTarget();
+ }
+
+ if (target != null)
+ target.beginCompoundChange();
+
+ p.apply(document);
+
+ Point selection = p.getSelection(document);
+ if (selection != null) {
+ viewer.setSelectedRange(selection.x, selection.y);
+ viewer.revealRange(selection.x, selection.y);
+ }
+ } finally {
+ if (target != null)
+ target.endCompoundChange();
+ }
+ }
+
+ private void createInfo(Composite parent, final Annotation annotation) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginHeight = 2;
+ layout.marginWidth = 2;
+ layout.horizontalSpacing = 0;
+ composite.setLayout(layout);
+
+ final Canvas canvas = new Canvas(composite, SWT.NO_FOCUS);
+ GridData gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
+ gridData.widthHint = 17;
+ gridData.heightHint = 16;
+ canvas.setLayoutData(gridData);
+ canvas.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ e.gc.setFont(null);
+ annotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
+ }
+ });
+
+ StyledText text = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ text.setLayoutData(data);
+ String annotationText = annotation.getText();
+ if (annotationText != null)
+ text.setText(annotationText);
+ }
+
+ private void setDecoration(Control control, Color foreground, Color background, Font
font) {
+ control.setForeground(foreground);
+ control.setBackground(background);
+ control.setFont(font);
+
+ if (control instanceof Composite) {
+ for (Control child : ((Composite) control).getChildren()) {
+ setDecoration(child, foreground, background, font);
+ }
+ }
+ }
+
+ }
+
+ private static final class AnnotationHoverControlCreator extends
AbstractReusableInformationControlCreator {
+ private final IInformationControlCreator presenterControlCreator;
+
+ public AnnotationHoverControlCreator(IInformationControlCreator
presenterControlCreator) {
+ this.presenterControlCreator = presenterControlCreator;
+ }
+
+ public IInformationControl doCreateInformationControl(Shell parent) {
+ return new MarkerAnnotationInformationControl(parent,
EditorsUI.getTooltipAffordanceString()) {
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ return presenterControlCreator;
+ }
+ };
+ }
+
+ public boolean canReuse(IInformationControl control) {
+ if (!super.canReuse(control))
+ return false;
+
+ if (control instanceof IInformationControlExtension4)
+ ((IInformationControlExtension4)
control).setStatusText(EditorsUI.getTooltipAffordanceString());
+
+ return true;
+ }
+ }
+
+ private static final class PresenterControlCreator extends
AbstractReusableInformationControlCreator {
+ public IInformationControl doCreateInformationControl(Shell parent) {
+ return new MarkerAnnotationInformationControl(parent,
EditorsUI.getTooltipAffordanceString()) {
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ return presenterControlCreator;
+ }
+ };
+ }
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -40,8 +40,8 @@
import org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor;
import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor;
import org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager;
-import org.jboss.tools.common.text.xml.MarkerProblemAnnotationHoverProcessor;
import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
+import org.jboss.tools.common.text.xml.xpl.MarkerProblemAnnotationHoverProcessor;
import org.jboss.tools.jst.jsp.format.HTMLFormatProcessor;
import org.jboss.tools.jst.jsp.jspeditor.info.ChainTextHover;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java 2011-03-10
21:45:42 UTC (rev 29677)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java 2011-03-10
22:03:09 UTC (rev 29678)
@@ -28,8 +28,8 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;
import org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager;
-import org.jboss.tools.common.text.xml.MarkerProblemAnnotationHoverProcessor;
import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
+import org.jboss.tools.common.text.xml.xpl.MarkerProblemAnnotationHoverProcessor;
/**
* @author Igels