it.tidalwave.hierarchy.explorer.impl.HExplorerTopComponent Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* OpenBlueSky - NetBeans Platform Enhancements
* ============================================
*
* Copyright (C) 2007-2010 by Tidalwave s.a.s.
* Project home page: http://openbluesky.kenai.com
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* $Id: HExplorerTopComponent.java,v f17245cd751a 2010/03/14 17:14:28 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.hierarchy.explorer.impl;
import javax.annotation.Nonnull;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.hierarchy.explorer.HExplorerPresentation;
import it.tidalwave.netbeans.windows.EnhancedTopComponent;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: HExplorerTopComponent.java,v f17245cd751a 2010/03/14 17:14:28 fabrizio $
*
**********************************************************************************************************************/
public class HExplorerTopComponent extends EnhancedTopComponent implements HExplorerPresentation
{
private static final String CLASS = HExplorerTopComponent.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
private static HExplorerTopComponent instance;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
protected HExplorerTopComponent()
{
setName(NbBundle.getMessage(HExplorerTopComponent.class, "CTL_HExplorerTopComponent"));
// PropertyManager.configure(this, "GeoExplorerTopComponent");
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public String preferredID()
{
return PREFERRED_ID;
}
/*******************************************************************************************************************
*
* Gets default instance. Do not use directly: reserved for *.settings files only, i.e. deserialization routines;
* otherwise you could get a non-deserialized instance. To obtain the singleton instance, use {@link findInstance}.
*
******************************************************************************************************************/
@Nonnull
public static synchronized HExplorerTopComponent getDefault()
{
if (instance == null)
{
instance = new HExplorerTopComponent();
}
return instance;
}
/*******************************************************************************************************************
*
* Obtain the GeoExplorerTopComponent instance. Never call {@link #getDefault} directly!
*
******************************************************************************************************************/
@Nonnull
public static synchronized HExplorerTopComponent findInstance()
{
final TopComponent component = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (component == null)
{
logger.warning("Cannot find %s component. It will not be located properly in the window system.",
PREFERRED_ID);
return getDefault();
}
if (component instanceof HExplorerTopComponent)
{
return (HExplorerTopComponent)component;
}
logger.warning("There seem to be multiple components with the '%s' ID. That is a potential source of errors and " +
"unexpected behavior.", PREFERRED_ID);
return getDefault();
}
}