blob: df66fce25af476f8304e049183ce1b53b4716fa1 [file] [log] [blame]
//
// 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.
//
= DevFaqToggleActionAddToEditorToolbar
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqToggleActionAddToEditorToolbar
:description: Apache NetBeans wiki DevFaqToggleActionAddToEditorToolbar
:toc: left
:toc-title:
:syntax: true
== How do I add a toggle-able action to the toolbar/main menu?
* extend from link:http://bits.netbeans.org/dev/javadoc/org-openide-util-ui/org/openide/util/actions/BooleanStateAction.html[org.openide.util.actions.BooleanStateAction]
* in the constructor add a property-change listener to the action itself and let the action implement `PropertyChangeListener `
* within `PropertyChangeListener#propertyChange` check for the propertyName `PROP_BOOLEAN_STATE` to distinguish the toggle event from other events
Example
[source,java]
----
package de.markiewb.netbeans.plugins.debuggerutils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.Action;
import org.netbeans.api.annotations.common.StaticResource;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.*;
import org.openide.util.NbBundle.Messages;
import org.openide.util.actions.BooleanStateAction;
@ActionID(
category = "Debug",
id = "de.markiewb.netbeans.plugins.debuggerutils.SkipAllBreakpoints"
)
@ActionRegistration(
lazy = false,
displayName = "#CTL_SkipAllBreakpoints"
)
@ActionReferences({
@ActionReference(path = "Toolbars/Debug", position = 1050),
@ActionReference(path = "Menu/RunProject", position = 2350)
}
)
@Messages("CTL_SkipAllBreakpoints=Skip all breakpoin&ts")
public final class SkipAllBreakpoints extends BooleanStateAction implements PropertyChangeListener {
@StaticResource
private static final String iconpath = "de/markiewb/netbeans/plugins/debuggerutils/Breakpoint_stroke.png";
public SkipAllBreakpoints() {
addPropertyChangeListener(this);
setBooleanState(false); //initially unchecked
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(PROP_BOOLEAN_STATE)) {
/* your action here, get the state by getBooleanState()*/
}
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
@Override
public String getName() {
return Bundle.CTL_SkipAllBreakpoints();
}
@Override
protected String iconResource() {
return iconpath;
}
}
----
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqToggleActionAddToEditorToolbar[http://wiki.netbeans.org/DevFaqToggleActionAddToEditorToolbar] ,
that was last modified by NetBeans user Markiewb
on 2016-06-02T21:50:34Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.