ConfigurationTree.java from PovClipse at Krugle
Show ConfigurationTree.java syntax highlighted
/*
* PovClipse - Eclipse plugin for editing and rendering Povray sceene files.
* Copyright (C) 2006-2007 Wolfgang Moestl wmoestl@web.de
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package com.wm.povclipse.actionsets.render.settings.tree;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
import com.wm.povclipse.PovClipseEditorPlugin;
import com.wm.povclipse.actionsets.render.RenderConfiguration;
import com.wm.povclipse.actionsets.render.RenderConfigurationStore;
import com.wm.povclipse.actionsets.render.settings.IActionCmd;
import com.wm.povclipse.i18n.I18nRenderAS;
/**
* Widget providing the handling of render configurations.
*
* @author Wolfgang Möstl
*/
public class ConfigurationTree extends AbstractConfigurationTree {
private static Image treeIcon = PovClipseEditorPlugin.getDefault().getImageRegistry().get(PovClipseEditorPlugin.IMAGE_ICON_RENDER_CONFIG);
private MenuItem popupItemSaveAsTemplate;
/**
* Constructor
* @param parent The parent <code>Composite</code>.
* @param style The widget style bits.
* @param listener The lestner to receive the tree selection eventes.
*/
public ConfigurationTree (Composite parent, int style, SelectionListener listener) {
super(parent, style, listener);
rootItem.setText(I18nRenderAS.tree_root_item);
rootItem.setImage(treeIcon);
}
/**
* Reads all render configurations and adds them to the tree's root item.
*/
protected void addAllRenderConfigs() {
List list = RenderConfigurationStore.getAllRenderConfigurations(true);
Iterator it = list.iterator();
while (it.hasNext()) {
RenderConfiguration config = (RenderConfiguration)it.next();
addItem(config);
}
expandFullTree();
}
/**
* @see com.wm.povclipse.actionsets.render.settings.tree.AbstractConfigurationTree#generatePopupMenu(org.eclipse.swt.widgets.Shell, org.eclipse.swt.events.SelectionListener)
*/
protected Menu generatePopupMenu(Shell shell, SelectionListener listener) {
Menu menu = super.generatePopupMenu(shell, listener);
new MenuItem(menu, SWT.SEPARATOR);
popupItemSaveAsTemplate = new MenuItem(menu, SWT.PUSH);
popupItemSaveAsTemplate.setData(IActionCmd.COMMAND, IActionCmd.CMD_SAVE_AS_TEMPLATE);
popupItemSaveAsTemplate.setData(MENU_ITEM_DATA_TREE, this);
popupItemSaveAsTemplate.addSelectionListener(listener);
popupItemSaveAsTemplate.setText(I18nRenderAS.button_save_as_template);
popupItemSaveAsTemplate.setEnabled(hasSelection());
popupItemSaveAsTemplate.setImage(new Image(shell.getDisplay(), getClass().getClassLoader().
getResourceAsStream("icons/copy_config_as_template.gif")));
return menu;
}
/**
* @see com.wm.povclipse.actionsets.render.settings.tree.AbstractConfigurationTree#setPopupMenuConfigEnabled(boolean)
*/
public void setPopupMenuConfigEnabled(boolean enabled) {
super.setPopupMenuConfigEnabled(enabled);
popupItemSaveAsTemplate.setEnabled(enabled);
}
/**
* @see com.wm.povclipse.actionsets.render.settings.tree.IConfigurationTree#isTemplateTree()
*/
public boolean isTemplateTree() {
return false;
}
/**
* @see com.wm.povclipse.actionsets.render.settings.tree.AbstractConfigurationTree#setTreeItemIcon(org.eclipse.swt.widgets.TreeItem)
*/
protected void setTreeItemIcon(TreeItem treeItem) {
treeItem.setImage(treeIcon);
}
}
See more files for this project here