Package hidb2.gui.action

Source Code of hidb2.gui.action.DeleteAttributAction

/**
* This file is part of HIDB2.
*
* HIDB2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HIDB2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with HIDB2.  If not, see <http://www.gnu.org/licenses/>.
*/
package hidb2.gui.action;

import hidb2.gui.ressources.RscMan;
import hidb2.gui.util.PoserTableViewer;
import hidb2.kern.Attribut;
import hidb2.kern.AttributedDescription;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.ui.ISharedImages;

public class DeleteAttributAction extends Action
  {
  private TableViewer viewer;

  private AttributedDescription _descr;

  public DeleteAttributAction(PoserTableViewer viewer)
    {
    this.viewer = viewer;
    setText("Delete Attribut");
    setToolTipText("Edit Selected Channel");
    setImageDescriptor(RscMan.getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE));
    }

  public void run(AttributedDescription attrDescr)
    {
    _descr = attrDescr;
    run();
    }

  public void run()
    {
    if (viewer != null)
      {
      try
        {
        ISelection selection = viewer.getSelection();
        Object obj = ((IStructuredSelection) selection).getFirstElement();

        Attribut attr = (Attribut) obj;

        // Get confirmation
        boolean rb = MessageDialog.openConfirm(viewer.getControl().getShell(), "Delete Attribute",
            "Do you confirm the deletion of Attribut:" + attr.getName() + "\nType:" + attr.getType().name);

        if (rb)
          {
          // Execute the deletion
          _descr.removeAttribut(attr);

          viewer.refresh();
          }

        }

      catch (/*PartInit*/Exception e)
        {
        MessageDialog.openError(viewer.getControl().getShell(), "Error", "Error : " + e.getMessage());
        e.printStackTrace();
        }
      }
    }

  }
TOP

Related Classes of hidb2.gui.action.DeleteAttributAction

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.