com.siemens.ct.mp3m.actions.RemoveMusicFolderAction.java Source code

Java tutorial

Introduction

Here is the source code for com.siemens.ct.mp3m.actions.RemoveMusicFolderAction.java

Source

/*******************************************************************************
 * Copyright (c) 2009 Siemens AG
 * 
 * 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:
 *    Kai Tdter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import com.siemens.ct.mp3m.ModelInitializer;
import com.siemens.ct.mp3m.model.physical.Mp3Directory;
import com.siemens.ct.mp3m.model.physical.MusicFolders;

public class RemoveMusicFolderAction implements IWorkbenchWindowActionDelegate {

    private String selectedDirectory;

    public void run(IAction action) {
        MusicFolders.removeMusicFolder(selectedDirectory);
        ModelInitializer.createTree();
    }

    public void dispose() {
        // TODO Auto-generated method stub
    }

    public void init(IWorkbenchWindow window) {
    }

    public void selectionChanged(IAction action, ISelection selection) {
        if (!selection.isEmpty()) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;
            if (structuredSelection.getFirstElement() instanceof Mp3Directory) {
                String folder = ((Mp3Directory) structuredSelection.getFirstElement()).getName();
                if (MusicFolders.contains(folder)) {
                    action.setEnabled(true);
                    selectedDirectory = folder;
                    return;
                } else {
                    action.setEnabled(false);
                }
            }
        }
        action.setEnabled(false);
    }
}