FileDocCategorySizeDatePackage
LayoutCreatorDialog.javaAPI DocAndroid 1.5 API5715Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.layout

LayoutCreatorDialog

public class LayoutCreatorDialog extends org.eclipse.jface.dialogs.TrayDialog
Dialog to choose a non existing {@link FolderConfiguration}.

Fields Summary
private com.android.ide.eclipse.adt.ui.ConfigurationSelector
mSelector
private org.eclipse.swt.widgets.Composite
mStatusComposite
private org.eclipse.swt.widgets.Label
mStatusLabel
private org.eclipse.swt.widgets.Label
mStatusImage
private final com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration
mConfig
private final String
mFileName
Constructors Summary
LayoutCreatorDialog(org.eclipse.swt.widgets.Shell parentShell, String fileName, com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config)
Creates a dialog, and init the UI from a {@link FolderConfiguration}.

param
parentShell the parent {@link Shell}.
param
config The starting configuration.


                               
          
        super(parentShell);

        mFileName = fileName;        
        // FIXME: add some data to know what configurations already exist. 
        mConfig.set(config);
    
Methods Summary
protected org.eclipse.swt.widgets.ControlcreateDialogArea(org.eclipse.swt.widgets.Composite parent)

        Composite top = new Composite(parent, SWT.NONE);
        top.setLayoutData(new GridData());
        top.setLayout(new GridLayout(1, false));

        new Label(top, SWT.NONE).setText(
                String.format("Configuration for the alternate version of %1$s", mFileName));
        
        mSelector = new ConfigurationSelector(top);
        mSelector.setConfiguration(mConfig);
        
        // parent's layout is a GridLayout as specified in the javadoc.
        GridData gd = new GridData();
        gd.widthHint = ConfigurationSelector.WIDTH_HINT;
        gd.heightHint = ConfigurationSelector.HEIGHT_HINT;
        mSelector.setLayoutData(gd);
        
        // add a listener to check on the validity of the FolderConfiguration as
        // they are built.
        mSelector.setOnChangeListener(new Runnable() {
            public void run() {
                ConfigurationState state = mSelector.getState();
                
                switch (state) {
                    case OK:
                        mSelector.getConfiguration(mConfig);

                        resetStatus();
                        mStatusImage.setImage(null);
                        getButton(IDialogConstants.OK_ID).setEnabled(true);
                        break;
                    case INVALID_CONFIG:
                        ResourceQualifier invalidQualifier = mSelector.getInvalidQualifier();
                        mStatusLabel.setText(String.format(
                                "Invalid Configuration: %1$s has no filter set.",
                                invalidQualifier.getName()));
                        mStatusImage.setImage(IconFactory.getInstance().getIcon("warning")); //$NON-NLS-1$
                        getButton(IDialogConstants.OK_ID).setEnabled(false);
                        break;
                    case REGION_WITHOUT_LANGUAGE:
                        mStatusLabel.setText(
                                "The Region qualifier requires the Language qualifier.");
                        mStatusImage.setImage(IconFactory.getInstance().getIcon("warning")); //$NON-NLS-1$
                        getButton(IDialogConstants.OK_ID).setEnabled(false);
                        break;
                }

                // need to relayout, because of the change in size in mErrorImage.
                mStatusComposite.layout();
            }
        });

        mStatusComposite = new Composite(top, SWT.NONE);
        mStatusComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        GridLayout gl = new GridLayout(2, false);
        mStatusComposite.setLayout(gl);
        gl.marginHeight = gl.marginWidth = 0;

        mStatusImage = new Label(mStatusComposite, SWT.NONE);
        mStatusLabel = new Label(mStatusComposite, SWT.NONE);
        mStatusLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        resetStatus();

        return top;
    
public voidgetConfiguration(com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config)

        config.set(mConfig);
    
private voidresetStatus()
resets the status label to show the file that will be created.

        mStatusLabel.setText(String.format("New File: res/%1$s/%2$s",
                mConfig.getFolderName(ResourceFolderType.LAYOUT), mFileName));