org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/FacetsSelectionPanel.java
changeset 465 87920e15f8eb
parent 463 aea4c83725d8
equal deleted inserted replaced
464:0b02f3d6f52c 465:87920e15f8eb
    47 import org.eclipse.swt.events.DisposeEvent;
    47 import org.eclipse.swt.events.DisposeEvent;
    48 import org.eclipse.swt.events.DisposeListener;
    48 import org.eclipse.swt.events.DisposeListener;
    49 import org.eclipse.swt.graphics.Image;
    49 import org.eclipse.swt.graphics.Image;
    50 import org.eclipse.swt.graphics.ImageData;
    50 import org.eclipse.swt.graphics.ImageData;
    51 import org.eclipse.swt.graphics.Point;
    51 import org.eclipse.swt.graphics.Point;
       
    52 import org.eclipse.swt.layout.GridData;
       
    53 import org.eclipse.swt.layout.GridLayout;
    52 import org.eclipse.swt.widgets.Composite;
    54 import org.eclipse.swt.widgets.Composite;
    53 import org.eclipse.swt.widgets.Control;
    55 import org.eclipse.swt.widgets.Control;
    54 import org.eclipse.swt.widgets.Display;
    56 import org.eclipse.swt.widgets.Display;
    55 import org.eclipse.swt.widgets.Event;
    57 import org.eclipse.swt.widgets.Event;
    56 import org.eclipse.swt.widgets.Label;
    58 import org.eclipse.swt.widgets.Label;
    57 import org.eclipse.swt.widgets.Listener;
    59 import org.eclipse.swt.widgets.Listener;
    58 import org.eclipse.swt.widgets.Table;
    60 import org.eclipse.swt.widgets.Table;
    59 import org.eclipse.swt.widgets.TableItem;
    61 import org.eclipse.swt.widgets.TableItem;
       
    62 import org.eclipse.swt.widgets.Text;
    60 import org.eclipse.ui.ISharedImages;
    63 import org.eclipse.ui.ISharedImages;
    61 import org.eclipse.ui.PlatformUI;
    64 import org.eclipse.ui.PlatformUI;
    62 import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
    65 import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
    63 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
    66 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
    64 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
    67 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
    68 import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
    71 import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
    69 import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleEvent;
    72 import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleEvent;
    70 import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleListener;
    73 import org.eclipse.wst.common.project.facet.core.runtime.events.IRuntimeLifecycleListener;
    71 import org.eclipse.wst.common.project.facet.ui.IDecorationsProvider;
    74 import org.eclipse.wst.common.project.facet.ui.IDecorationsProvider;
    72 import org.eclipse.wst.common.project.facet.ui.internal.FacetUiPlugin;
    75 import org.eclipse.wst.common.project.facet.ui.internal.FacetUiPlugin;
    73 import org.eclipse.wst.common.project.facet.ui.internal.util.BasicToolTip;
       
    74 import org.eclipse.wst.common.project.facet.ui.internal.util.HeaderToolTip;
       
    75 import org.symbian.tools.tmw.core.TMWCore;
    76 import org.symbian.tools.tmw.core.TMWCore;
    76 
    77 
    77 /**
    78 /**
    78  * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
    79  * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
    79  */
    80  */
    80 
    81 
       
    82 @SuppressWarnings("restriction")
    81 public final class FacetsSelectionPanel extends Composite implements ISelectionProvider {
    83 public final class FacetsSelectionPanel extends Composite implements ISelectionProvider {
    82     private final Composite topComposite;
    84     private final Composite topComposite;
    83     private final SashForm sform1;
    85     private final SashForm sform1;
    84     private final CheckboxTableViewer tableViewer;
    86     private final CheckboxTableViewer tableViewer;
    85     private final Table table;
    87     private final Table table;
    89     private final IFacetedProjectWorkingCopy fpjwc;
    91     private final IFacetedProjectWorkingCopy fpjwc;
    90     private final List<IFacetedProjectListener> registeredWorkingCopyListeners;
    92     private final List<IFacetedProjectListener> registeredWorkingCopyListeners;
    91     private final Map<IProjectFacet, IProjectFacetVersion> selectedVersions;
    93     private final Map<IProjectFacet, IProjectFacetVersion> selectedVersions;
    92     private final List<ISelectionChangedListener> selectionListeners;
    94     private final List<ISelectionChangedListener> selectionListeners;
    93     private Object selection;
    95     private Object selection;
    94 
       
    95     /**
       
    96      * Holds images used throughout the panel.
       
    97      */
       
    98 
       
    99     private final ImageRegistry imageRegistry;
    96     private final ImageRegistry imageRegistry;
   100 
       
   101     private final IRuntimeLifecycleListener runtimeLifecycleListener;
    97     private final IRuntimeLifecycleListener runtimeLifecycleListener;
       
    98     private final Text description;
       
    99     private final Composite facets;
   102 
   100 
   103     public interface IFilter {
   101     public interface IFilter {
   104         boolean check(IProjectFacetVersion fv);
   102         boolean check(IProjectFacetVersion fv);
   105     }
   103     }
   106 
   104 
   117         // Initialize the image registry.
   115         // Initialize the image registry.
   118 
   116 
   119         this.imageRegistry = new ImageRegistry();
   117         this.imageRegistry = new ImageRegistry();
   120         // Layout the panel.
   118         // Layout the panel.
   121 
   119 
   122         setLayout(glmargins(gl(1), 0, 0));
   120         setLayout(glmargins(new GridLayout(1, false), 0, 0));
   123 
   121 
   124         this.topComposite = new Composite(this, SWT.NONE);
   122         this.topComposite = new Composite(this, SWT.NONE);
   125         this.topComposite.setLayout(glmargins(gl(4), 0, 0));
   123         this.topComposite.setLayout(glmargins(new GridLayout(4, false), 0, 0));
   126 
   124 
   127         this.sform1 = new SashForm(this.topComposite, SWT.VERTICAL | SWT.SMOOTH);
   125         this.sform1 = new SashForm(this.topComposite, SWT.VERTICAL | SWT.SMOOTH);
   128         this.sform1.setLayoutData(gdhspan(gdfill(), 4));
   126         this.sform1.setLayoutData(gdhspan(gdfill(), 4));
   129 
   127 
   130         this.table = new Table(this.sform1, SWT.BORDER | SWT.CHECK);
   128         facets = new Composite(sform1, SWT.NONE);
       
   129         facets.setLayout(new GridLayout(2, false));
       
   130         this.table = new Table(facets, SWT.BORDER | SWT.CHECK);
       
   131         GridData gd = new GridData(GridData.FILL_VERTICAL);
       
   132         gd.widthHint = 250;
       
   133         table.setLayoutData(gd);
       
   134         description = new Text(facets, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER);
       
   135         gd = new GridData(GridData.FILL_BOTH);
       
   136         description.setLayoutData(gd);
   131         this.tableViewer = new CheckboxTableViewer(this.table);
   137         this.tableViewer = new CheckboxTableViewer(this.table);
   132 
   138 
   133         this.tableViewer.setLabelProvider(new FacetColumnLabelProvider());
   139         this.tableViewer.setLabelProvider(new FacetColumnLabelProvider());
   134         this.tableViewer.setContentProvider(new ContentProvider());
   140         this.tableViewer.setContentProvider(new ContentProvider());
   135         this.tableViewer.setSorter(new Sorter());
   141         this.tableViewer.setSorter(new Sorter());
   136 
   142 
   137         new FacetToolTip(this.table);
       
   138         this.fixedFacetToolTip = new FixedFacetToolTip(this.table);
   143         this.fixedFacetToolTip = new FixedFacetToolTip(this.table);
   139 
   144 
   140         this.tableViewer.setInput(new Object());
   145         this.tableViewer.setInput(new Object());
   141 
   146 
   142         this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
   147         this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
   209         // Set the preferred dimensions of the panel.
   214         // Set the preferred dimensions of the panel.
   210 
   215 
   211         final int prefWidthTree = getPreferredWidth(this.table);
   216         final int prefWidthTree = getPreferredWidth(this.table);
   212         final int prefWidth = prefWidthTree + 80;
   217         final int prefWidth = prefWidthTree + 80;
   213 
   218 
   214         this.topComposite.setLayoutData(gdwhint(gdhhint(gdfill(), 500), prefWidth));
   219         this.topComposite.setLayoutData(gdwhint(gdhhint(gdfill(), 200), prefWidth));
   215 
   220 
   216         this.sform1.setWeights(new int[] { 70, 30 });
   221         this.sform1.setWeights(new int[] { 70, 30 });
   217 
   222 
   218         // Select the first item in the table.
   223         // Select the first item in the table.
   219 
   224 
   361     private void handleSelectionChangedEvent() {
   366     private void handleSelectionChangedEvent() {
   362         Object selection = ((IStructuredSelection) this.tableViewer.getSelection()).getFirstElement();
   367         Object selection = ((IStructuredSelection) this.tableViewer.getSelection()).getFirstElement();
   363 
   368 
   364         if (selection != null && selection instanceof IProjectFacet) {
   369         if (selection != null && selection instanceof IProjectFacet) {
   365             selection = getSelectedVersion((IProjectFacet) selection);
   370             selection = getSelectedVersion((IProjectFacet) selection);
       
   371             description.setText(((IProjectFacetVersion) selection).getProjectFacet().getDescription());
   366         }
   372         }
   367 
   373 
   368         if (selection != this.selection) {
   374         if (selection != this.selection) {
   369             this.selection = selection;
   375             this.selection = selection;
   370 
   376 
   487 
   493 
   488         this.problemsView.refresh();
   494         this.problemsView.refresh();
   489 
   495 
   490         if (getFilteredProblems().length == 0) {
   496         if (getFilteredProblems().length == 0) {
   491             if (this.sform1.getMaximizedControl() == null) {
   497             if (this.sform1.getMaximizedControl() == null) {
   492                 this.sform1.setMaximizedControl(this.tableViewer.getControl());
   498                 this.sform1.setMaximizedControl(facets);
   493             }
   499             }
   494         } else {
   500         } else {
   495             if (this.sform1.getMaximizedControl() != null) {
   501             if (this.sform1.getMaximizedControl() != null) {
   496                 this.sform1.setMaximizedControl(null);
   502                 this.sform1.setMaximizedControl(null);
   497             }
   503             }
   513             break;
   519             break;
   514         }
   520         }
   515         }
   521         }
   516     }
   522     }
   517 
   523 
   518     private TableItem getTreeItem(final int x, final int y) {
       
   519         return getTreeItemHelper(x, y, this.table.getItems());
       
   520     }
       
   521 
       
   522     private static TableItem getTreeItemHelper(final int x, final int y, final TableItem[] items) {
       
   523         for (TableItem item : items) {
       
   524             if (item.getBounds().contains(x, y)) {
       
   525                 return item;
       
   526             }
       
   527         }
       
   528 
       
   529         return null;
       
   530     }
       
   531 
       
   532     private IStatus[] getFilteredProblems() {
   524     private IStatus[] getFilteredProblems() {
   533         final IStatus[] unfiltered = this.fpjwc.validate().getChildren();
   525         final IStatus[] unfiltered = this.fpjwc.validate().getChildren();
   534         boolean somethingToRemove = false;
   526         boolean somethingToRemove = false;
   535 
   527 
   536         for (IStatus st : unfiltered) {
   528         for (IStatus st : unfiltered) {
   647         private static String getLabel(final Object obj) {
   639         private static String getLabel(final Object obj) {
   648             return ((IProjectFacet) obj).getLabel();
   640             return ((IProjectFacet) obj).getLabel();
   649         }
   641         }
   650     }
   642     }
   651 
   643 
   652     private final class FacetToolTip extends HeaderToolTip {
   644     private final class FixedFacetToolTip extends ToolTip {
   653         public FacetToolTip(final Control control) {
   645         private static final int FAKE_EVENT_TYPE = -9999;
   654             super(control);
   646 
   655         }
   647         private String message = ""; //$NON-NLS-1$
   656 
   648 
   657         @Override
   649         @Override
   658         protected final boolean shouldCreateToolTip(final Event event) {
   650         protected Composite createToolTipContentArea(final Event event, final Composite parent) {
   659             if (getShowToolTips() == false) {
       
   660                 return false;
       
   661             }
       
   662 
       
   663             final TableItem treeItem = getTreeItem(event.x, event.y);
       
   664             String description = null;
       
   665 
       
   666             if (treeItem != null && treeItem.getBounds(0).contains(event.x, event.y)) {
       
   667                 final Object treeItemData = treeItem.getData();
       
   668 
       
   669                 if (treeItemData instanceof IProjectFacet) {
       
   670                     description = ((IProjectFacet) treeItemData).getDescription();
       
   671                 }
       
   672             }
       
   673 
       
   674             return (description != null && description.trim().length() > 0);
       
   675         }
       
   676 
       
   677         @Override
       
   678         protected String getToolTipTitle(final Event event) {
       
   679             final IProjectFacet f = (IProjectFacet) getTreeItem(event.x, event.y).getData();
       
   680             return getSelectedVersion(f).toString();
       
   681         }
       
   682 
       
   683         @Override
       
   684         protected Composite createContentArea(final Event event, final Composite parent) {
       
   685             final Display display = parent.getDisplay();
   651             final Display display = parent.getDisplay();
   686 
   652 
   687             final Composite composite = new Composite(parent, SWT.NONE);
   653             final Composite composite = new Composite(parent, SWT.NONE);
   688             composite.setLayout(gl(1));
   654             composite.setLayout(gl(1));
   689             composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   655             composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   690 
   656 
   691             final Label label = new Label(composite, SWT.WRAP);
   657             final Label label = new Label(composite, SWT.WRAP);
   692             label.setLayoutData(gdfill());
   658             label.setLayoutData(gdwhint(gdfill(), 300));
   693             label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   659             label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   694 
   660             label.setText(this.message);
   695             final IProjectFacet f = (IProjectFacet) getTreeItem(event.x, event.y).getData();
       
   696             label.setText(f.getDescription());
       
   697 
   661 
   698             return composite;
   662             return composite;
   699         }
   663         }
   700     }
   664 
   701 
   665         public void setMessage(final String message) {
   702     private final class FixedFacetToolTip extends BasicToolTip {
   666             this.message = message;
   703         private static final int FAKE_EVENT_TYPE = -9999;
   667         }
   704 
   668 
   705         public FixedFacetToolTip(final Control control) {
   669         public FixedFacetToolTip(final Control control) {
   706             super(control);
   670             super(control);
   707             setPopupDelay(0);
   671             setPopupDelay(0);
       
   672             setShift(new Point(10, 3));
   708         }
   673         }
   709 
   674 
   710         public void show(final Point location) {
   675         public void show(final Point location) {
   711             // The JFace ToolTip class does not support alternative methods of tool tip activation.
   676             // The JFace ToolTip class does not support alternative methods of tool tip activation.
   712             // An enhancement request https://bugs.eclipse.org/bugs/show_bug.cgi?id=174844 tracks
   677             // An enhancement request https://bugs.eclipse.org/bugs/show_bug.cgi?id=174844 tracks