Package hidb2.gui.action

Source Code of hidb2.gui.action.DeleteFolderDescr

/**
* 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.Application;
import hidb2.gui.DBStructView;
import hidb2.gui.node.DefaultNode;
import hidb2.gui.node.FolderDescrNode;
import hidb2.kern.StatusCycle;
import hidb2.kern.FolderDescription;

import java.util.logging.Logger;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
* Delete a Folder Description.
*/
public class DeleteFolderDescr implements IViewActionDelegate
  {
  final static Logger log = Logger.getLogger("hidb2.gui.action");

  private ISelection _selection;

  public void init(IViewPart view)
    {
    }

  public DeleteFolderDescr()
    {

    }

  public void run(IAction action)
    {
    if (_selection != null)
      {
      Object obj = ((IStructuredSelection) _selection).getFirstElement();
      IWorkbenchWindow wbwin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

      // For Tests of editor
      IWorkbenchPage page = wbwin.getActivePage();
      IWorkbenchPart iwp = page.getActivePart();

      // Control Destination Class
      if (obj instanceof FolderDescrNode)
        {
        FolderDescrNode on = (FolderDescrNode) obj;

        FolderDescription fd = (FolderDescription) on.getDescr();

        fd.updateStats(Application.getDataStore());

        // Calculate Impact + Confirmation window
        boolean rb = MessageDialog.openConfirm(wbwin.getShell(), "Delete Folder Description",
            "Do you confirm the deletion of :" + fd.getName() + "\nHaving : " + fd.getNbInstance() + " folders");

        if (rb)
          {
          fd.setStatus(StatusCycle.DELETED);

          fd.write(Application.getDataStore());

          DefaultNode p = on.getParent();
         
          p.removeChild(on);

          // Update the tree view
          if (iwp instanceof DBStructView)
            {
            ((DBStructView) iwp).getTree().refresh(p, true);
            }
          }
        }
      }
    }

  public void selectionChanged(IAction action, ISelection selection)
    {
    _selection = selection;
    }

  }
TOP

Related Classes of hidb2.gui.action.DeleteFolderDescr

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.