blob: 7c0b892f32fe6f55ca0927b25d5faa755cd92da7 [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.
*/
package org.netbeans.modules.xml.multiview;
import org.netbeans.core.spi.multiview.CloseOperationState;
import org.netbeans.core.spi.multiview.MultiViewFactory;
import org.netbeans.modules.xml.multiview.ui.SectionView;
import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor;
import org.openide.loaders.DataObject;
import org.openide.util.WeakListeners;
import org.openide.util.lookup.ProxyLookup;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
/**
* An implementation of <code>MultiViewElement</code> that is specific to
* <code>XmlMultiViewDataObject</code>.
*
* @see org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor
*
* Created on October 5, 2004, 1:35 PM
* @author mkuchtiak
*/
public abstract class ToolBarMultiViewElement extends AbstractMultiViewElement {
private ToolBarDesignEditor editor;
private PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && editor != null) {
Utils.runInAwtDispatchThread(new Runnable() {
public void run() {
if (null != callback){
callback.getTopComponent().setDisplayName(dObj.getEditorSupport().messageName());
callback.getTopComponent().setHtmlDisplayName(dObj.getEditorSupport().messageHtmlName());
callback.getTopComponent().setToolTipText(dObj.getEditorSupport().messageToolTip());
}
}
});
}
}
};
public ToolBarMultiViewElement(final XmlMultiViewDataObject dObj) {
super(dObj);
dObj.addPropertyChangeListener(WeakListeners.propertyChange(listener, dObj));
}
protected void setVisualEditor(ToolBarDesignEditor editor) {
this.editor=editor;
}
public CloseOperationState canCloseElement() {
if (!editorValidate()) {
return MultiViewFactory.createUnsafeCloseState(ToolBarDesignEditor.PROPERTY_FLUSH_DATA, null, null);
} else {
return super.canCloseElement();
}
}
private boolean editorValidate() {
try {
editor.fireVetoableChange(ToolBarDesignEditor.PROPERTY_FLUSH_DATA, this, null);
return true;
} catch (PropertyVetoException e) {
return false;
}
}
public void componentActivated() {
editor.componentActivated();
}
public void componentClosed() {
editor.componentClosed();
}
public void componentDeactivated() {
editor.componentDeactivated();
}
public void componentHidden() {
editor.componentHidden();
dObj.setActiveMultiViewElement(null);
}
public void componentOpened() {
editor.componentOpened();
}
public void componentShowing() {
if (editorValidate()) {
editor.componentShowing();
dObj.setActiveMultiViewElement(this);
}
}
public org.openide.util.Lookup getLookup() {
return new ProxyLookup(new org.openide.util.Lookup[] {
dObj.getNodeDelegate().getLookup()
});
}
public javax.swing.JComponent getToolbarRepresentation() {
return editor.getStructureView();
}
public javax.swing.JComponent getVisualRepresentation() {
return editor;
}
/** Enable to get the SectionView included in this MultiView Element
*/
public abstract SectionView getSectionView();
}