Package de.innovationgate.eclipse.editors.tml

Source Code of de.innovationgate.eclipse.editors.tml.TMLFileMetadataPropertyPage

/*******************************************************************************
* 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.tml;


import java.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.part.FileEditorInput;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.ui.GenesisBoundPropertyPage;
import de.innovationgate.eclipse.utils.ui.WidgetFactory;
import de.innovationgate.eclipse.utils.ui.model.TMLFileMetadataModel;
import de.innovationgate.wga.model.Model;

public class TMLFileMetadataPropertyPage extends GenesisBoundPropertyPage {

  private TMLFileMetadataModel _model;
  private Button _chkCachable;
  private Button _chkDirectAccess;
  private Text _txtDescription;

  public TMLFileMetadataPropertyPage() {
    setDescription("This page allows modification of tml file metadata.");
  }
 
  private boolean hasMDHeader() {
    boolean hasMDHeader = false;
    try {
      IAdaptable element = getElement();
      if (element instanceof IFile) {
        IFile tmlFile = (IFile) getElement();
        TMLDocumentProvider provider = new TMLDocumentProvider();   
        IFileEditorInput input = new FileEditorInput(tmlFile);     
        provider.connect(input);
       
        if (provider.getDocument(input).getContentType(0).equals(TMLPartitionScanner.TML_METAHEADER)) {
          hasMDHeader = true;
        }
        provider.disconnect(input);
      }
    } catch (Exception e) {
      Plugin.getDefault().getLog().log(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Unable to check relyable for MD headers.", e));
    }
    return hasMDHeader;
  }

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

    if (hasMDHeader()) {
      Label label = new Label(composite, SWT.None);
      label.setText("Note:");
      label = new Label(composite, SWT.None);
      label.setText("Metadata headers are present in this tml file. Editing metadata with this editor is not possible. Please remove metadata headers first.");
      noDefaultAndApplyButton();
    } else {
      Label label = new Label(composite, SWT.None);
      label.setText("Description:");
      label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
      _txtDescription = new Text(composite, SWT.MULTI|SWT.BORDER);
      _txtDescription.setData("description");
      GridData descriptionLayout = new GridData(SWT.FILL, SWT.FILL, true, false);
      descriptionLayout.heightHint = WidgetFactory.computeFontHeight(_txtDescription) * 5;
        _txtDescription.setLayoutData(descriptionLayout);
     
     
      label = new Label(composite, SWT.None);
      label.setText("DirectAccess:");
      _chkDirectAccess = new Button(composite, SWT.CHECK);
      _chkDirectAccess.setText("enabled");
      _chkDirectAccess.setData("directAccess");
     
      label = new Label(composite, SWT.None);
      label.setText("Caching:");
      _chkCachable = new Button(composite, SWT.CHECK);
      _chkCachable.setText("enabled");
      _chkCachable.setData("cachable");
     
     
      Label filler = new Label(composite, SWT.None);
      GridData fillerLayout = new GridData(SWT.FILL, SWT.FILL, true, true);
      fillerLayout.horizontalSpan = 2;
      filler.setLayoutData(fillerLayout);
       
      bind(composite);           
    }
    return composite;
  }

  @Override
  public Model getModel() {
    if (_model == null) {
      IAdaptable element = getElement();
      if (element instanceof IFile) {
        IFile tmlFile = (IFile) getElement()
        _model = new TMLFileMetadataModel(tmlFile);
      }
    }
    return _model;
  }

  @Override
  public boolean performOk() {
    if (!hasMDHeader()) {
      if (_model != null) {
        try {
          _model.saveChanges();
          return true;
        } catch (IOException e) {
          Plugin.getDefault().getLog().log(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Unable to save tml file metadata.", e));
        }
      }
      return false;
    } else {
      return true;
    }   
  }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.tml.TMLFileMetadataPropertyPage

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.