Package de.innovationgate.eclipse.editors.all

Source Code of de.innovationgate.eclipse.editors.all.WGADesignMetadataPropertyPage

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.all;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PropertyPage;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;

public class WGADesignMetadataPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {

  private Combo _comboLanguage;
  private Button _chkSortLabelFiles;

  public WGADesignMetadataPropertyPage() {
  }

  @Override
  protected Control createContents(Composite parent) {   
    Composite composite = new Composite(parent, SWT.FILL);
    composite.setLayout(new GridLayout(2, false));

    if (getDesignRoot() == null) {
      Label label = new Label(composite, SWT.None);
      label.setText("Note:");
      label = new Label(composite, SWT.None);
      label.setText("The selected resource is no wga design.");
      noDefaultAndApplyButton();
    } else {
      Label label = new Label(composite, SWT.None);
      label.setText("Development language:");
      _comboLanguage = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
     
      // fill combo
      List<String> languages = new ArrayList<String>();
      WGADesignStructureHelper helper = new WGADesignStructureHelper(getDesignRoot());
      try {
        languages.addAll(helper.getAvailableLableLanguages());         
      } catch (CoreException e) {
        Plugin.getDefault().getLog().log(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Unable to retrieve configured label languages.", e));
      }
      if (languages.isEmpty()) {
        languages.add(WGADesignStructureHelper.DEFAULT_DESIGN_DEV_LANGUAGE);
      }
      _comboLanguage.setItems(languages.toArray(new String[0]));
     
      // set combo default     
      int index = 0;     
      try {
        String devLang = helper.getDevelopmentLanguage();
        int pos = _comboLanguage.indexOf(devLang);
        if (pos != -1) {
          index = pos;
        }
      } catch (CoreException e) {
        Plugin.getDefault().getLog().log(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Unable to retrieve dev language of resource '" + getDesignRoot().getLocation() + "'.", e));
      }     
      _comboLanguage.select(index);
     
      label = new Label(composite, SWT.None);
      label.setText("AutoSort label files:");
     
      _chkSortLabelFiles = new Button(composite, SWT.CHECK);
      _chkSortLabelFiles.setText("enabled");
      _chkSortLabelFiles.setSelection(helper.isSortLabelFiles());
    }   
   
    return composite;
  }

  private IContainer getDesignRoot() {
    IAdaptable element = getElement();
    if (element instanceof IContainer) {
      IContainer container = (IContainer) getElement();
      if (WGADesignStructureHelper.isDesignFolder(container)) {
        return container;
      }
    }
    return null;
  }

  @Override
  public boolean performOk() {
    try {
      WGADesignStructureHelper helper = new WGADesignStructureHelper(getDesignRoot());
      helper.setDevelopmentLanguage(_comboLanguage.getText());
      helper.setSortLabelFiles(_chkSortLabelFiles.getSelection());
    } catch (Exception e) {
      Plugin.getDefault().getLog().log(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Unable to save design metadata of resource '" + getDesignRoot().getLocation() + "'.", e));
    }
    return true;
  }
 
}
TOP

Related Classes of de.innovationgate.eclipse.editors.all.WGADesignMetadataPropertyPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.