it.tidalwave.netbeans.examples.nodes.example4.view.ShowCardinalityAction Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* OpenBlueSky - NetBeans Platform Enhancements
* Copyright (C) 2006-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed 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.
*
***********************************************************************************************************************
*
* WWW: http://openbluesky.kenai.com
* SCM: https://kenai.com/hg/openbluesky~src
*
**********************************************************************************************************************/
package it.tidalwave.netbeans.examples.nodes.example4.view;
import it.tidalwave.util.NotFoundException;
import javax.annotation.Nonnull;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import it.tidalwave.netbeans.examples.nodes.example1.roles.CardinalityVisitor;
import it.tidalwave.netbeans.examples.nodes.example1.roles.CompositeTraverser;
import static it.tidalwave.role.Displayable.Displayable;
import static it.tidalwave.netbeans.util.EnhancedLookups.lookup;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class ShowCardinalityAction extends AbstractAction
{
@Nonnull
private final Object object;
public ShowCardinalityAction (final @Nonnull Object object)
{
this.object = object;
super.putValue(Action.NAME, "Show cardinality");
}
@Override
public void actionPerformed (final @Nonnull ActionEvent event)
{
final SwingWorker swingWorker = new SwingWorker()
{
@Override @Nonnull
protected Integer doInBackground()
throws NotFoundException
{
return CompositeTraverser.accept(object, new CardinalityVisitor());
}
@Override
protected void done()
{
try
{
final String displayName = lookup(object, Displayable).getDisplayName();
final String message = String.format("File count for %s is %d", displayName, get());
JOptionPane.showMessageDialog(null, message, "Title", JOptionPane.INFORMATION_MESSAGE);
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
swingWorker.execute();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy