Home | History | Annotate | Download | only in presentation
      1 /*******************************************************************************
      2  * Copyright (c) 2011 Google, Inc.
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Google, Inc. - initial API and implementation
     10  *******************************************************************************/
     11 package org.eclipse.wb.internal.core.model.property.editor.presentation;
     12 
     13 import org.eclipse.wb.internal.core.DesignerPlugin;
     14 import org.eclipse.wb.internal.core.EnvironmentUtils;
     15 import org.eclipse.wb.internal.core.model.property.Property;
     16 import org.eclipse.wb.internal.core.model.property.table.PropertyTable;
     17 
     18 import org.eclipse.swt.SWT;
     19 import org.eclipse.swt.graphics.Image;
     20 import org.eclipse.swt.widgets.Button;
     21 
     22 /**
     23  * Implementation of {@link PropertyEditorPresentation} for displaying {@link Button}.
     24  *
     25  * @author scheglov_ke
     26  * @author mitin_aa
     27  * @coverage core.model.property.editor
     28  */
     29 public abstract class ButtonPropertyEditorPresentation extends PropertyEditorPresentation {
     30   private final int m_style;
     31   private final ButtonPropertyEditorPresentationImpl m_impl;
     32 
     33   ////////////////////////////////////////////////////////////////////////////
     34   //
     35   // Constructors
     36   //
     37   ////////////////////////////////////////////////////////////////////////////
     38   public ButtonPropertyEditorPresentation() {
     39     this(SWT.NONE);
     40   }
     41 
     42   public ButtonPropertyEditorPresentation(int style) {
     43     m_style = style;
     44     m_impl =
     45         EnvironmentUtils.IS_MAC
     46             ? new ButtonPropertyEditorPresentationImplMac(this)
     47             : new ButtonPropertyEditorPresentationImpl(this);
     48   }
     49 
     50   ////////////////////////////////////////////////////////////////////////////
     51   //
     52   // Access
     53   //
     54   ////////////////////////////////////////////////////////////////////////////
     55   /**
     56    * Sets "selection" property of {@link Button}.
     57    */
     58   public final void setSelection(PropertyTable propertyTable, Property property, boolean selected) {
     59     m_impl.setSelection(propertyTable, property, selected);
     60   }
     61 
     62   ////////////////////////////////////////////////////////////////////////////
     63   //
     64   // PropertyEditorPresentation
     65   //
     66   ////////////////////////////////////////////////////////////////////////////
     67   @Override
     68   public final int show(final PropertyTable propertyTable,
     69       final Property property,
     70       final int x,
     71       final int y,
     72       final int width,
     73       final int height) {
     74     return m_impl.show(propertyTable, property, x, y, width, height);
     75   }
     76 
     77   @Override
     78   public final void hide(PropertyTable propertyTable, Property property) {
     79     m_impl.hide(propertyTable, property);
     80   }
     81 
     82   ////////////////////////////////////////////////////////////////////////////
     83   //
     84   // Access
     85   //
     86   ////////////////////////////////////////////////////////////////////////////
     87   final int getStyle() {
     88     return m_style;
     89   }
     90 
     91   ////////////////////////////////////////////////////////////////////////////
     92   //
     93   // Implementation
     94   //
     95   ////////////////////////////////////////////////////////////////////////////
     96   /**
     97    * @return the {@link Image} to display on {@link Button}.
     98    */
     99   protected Image getImage() {
    100     return DesignerPlugin.getImage("properties/dots.gif");
    101   }
    102 
    103   /**
    104    * @return the tooltip text to display for {@link Button}.
    105    */
    106   protected String getTooltip() {
    107     return null;
    108   }
    109 
    110   /**
    111    * Handles click on {@link Button}.
    112    */
    113   protected abstract void onClick(PropertyTable propertyTable, Property property) throws Exception;
    114 
    115   // Temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=388574
    116   public static boolean isInWorkaround;
    117   public void click(PropertyTable propertyTable, Property property) throws Exception {
    118     try {
    119       isInWorkaround = true;
    120       onClick(propertyTable, property);
    121     } finally {
    122         isInWorkaround = false;
    123     }
    124   }
    125 }
    126