Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.adt.internal.editors.ui;
     18 
     19 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiFlagAttributeNode;
     20 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiResourceAttributeNode;
     21 
     22 import org.eclipse.swt.widgets.Composite;
     23 import org.eclipse.swt.widgets.Control;
     24 
     25 /**
     26  * DialogCellEditor able to receive a {@link UiFlagAttributeNode} in the {@link #setValue(Object)}
     27  * method.
     28  * <p/>The dialog box opened is the same as the one in the ui created by
     29  * {@link UiFlagAttributeNode#createUiControl(Composite, org.eclipse.ui.forms.IManagedForm)}
     30  */
     31 public class ResourceValueCellEditor extends EditableDialogCellEditor {
     32 
     33     private UiResourceAttributeNode mUiResourceAttribute;
     34 
     35     public ResourceValueCellEditor(Composite parent) {
     36         super(parent);
     37     }
     38 
     39     @Override
     40     protected Object openDialogBox(Control cellEditorWindow) {
     41         if (mUiResourceAttribute != null) {
     42             String currentValue = (String)getValue();
     43             return mUiResourceAttribute.showDialog(cellEditorWindow.getShell(), currentValue);
     44         }
     45 
     46         return null;
     47     }
     48 
     49     @Override
     50     protected void doSetValue(Object value) {
     51         if (value instanceof UiResourceAttributeNode) {
     52             mUiResourceAttribute = (UiResourceAttributeNode)value;
     53             super.doSetValue(mUiResourceAttribute.getCurrentValue());
     54             return;
     55         }
     56 
     57         super.doSetValue(value);
     58     }
     59 }
     60