Package org.apache.ivyde.eclipse.ui.console

Source Code of org.apache.ivyde.eclipse.ui.console.IvyConsoleFilterAction

/*
*  Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  See the NOTICE file distributed with
*  this work for additional information regarding copyright ownership.
*  The ASF licenses this file to You under the Apache License, Version 2.0
*  (the "License"); you may not use this file except in compliance with
*  the License.  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*
*/
package org.apache.ivyde.eclipse.ui.console;

import org.apache.ivyde.eclipse.IvyPlugin;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;

public class IvyConsoleFilterAction extends Action implements IMenuCreator {

    private static final String[] LOG_LEVEL_MESSAGES = {"error", "warning", "info", "verbose",
            "debug"};

    private Menu fMenu;

    private IvyConsole console;

    public IvyConsoleFilterAction(IvyConsole console) {
        this.console = console;
        setText("Log filter");
        setToolTipText("Filter the log level of the Ivy console");
        setImageDescriptor(IvyPlugin.getImageDescriptor("/icons/log_level.png"));
        setMenuCreator(this);
    }

    public void dispose() {
        if (fMenu != null) {
            fMenu.dispose();
        }
        console = null;
    }

    public Menu getMenu(Menu parent) {
        return null;
    }

    public Menu getMenu(Control parent) {
        if (fMenu != null) {
            fMenu.dispose();
        }

        fMenu = new Menu(parent);
        for (int i = 0; i < LOG_LEVEL_MESSAGES.length; i++) {
            final int logLevel = i;
            Action action = new Action(LOG_LEVEL_MESSAGES[i]) {
                public void run() {
                    console.setLogLevel(logLevel);
                }
            };
            action.setChecked(console.getLogLevel() == i);
            addActionToMenu(fMenu, action);
        }
        return fMenu;
    }

    private void addActionToMenu(Menu parent, Action action) {
        ActionContributionItem item = new ActionContributionItem(action);
        item.fill(parent, -1);
    }

    public void run() {
        // nothing to do
    }

}
TOP

Related Classes of org.apache.ivyde.eclipse.ui.console.IvyConsoleFilterAction

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.