001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.control.gui;
020:
021: import java.awt.BorderLayout;
022: import java.util.Collection;
023:
024: import javax.swing.JMenu;
025: import javax.swing.JPopupMenu;
026:
027: import org.apache.jmeter.gui.AbstractJMeterGuiComponent;
028: import org.apache.jmeter.gui.action.ActionNames;
029: import org.apache.jmeter.gui.util.MenuFactory;
030: import org.apache.jmeter.testelement.TestElement;
031: import org.apache.jmeter.testelement.WorkBench;
032: import org.apache.jmeter.util.JMeterUtils;
033:
034: /**
035: * JMeter GUI component representing a work bench where users can make
036: * preparations for the test plan.
037: *
038: */
039: public class WorkBenchGui extends AbstractJMeterGuiComponent {
040: /**
041: * Create a new WorkbenchGui.
042: */
043: public WorkBenchGui() {
044: super ();
045: init();
046: }
047:
048: /**
049: * This is the list of menu categories this gui component will be available
050: * under. This implementation returns null, since the WorkBench appears at
051: * the top level of the tree and cannot be added elsewhere.
052: *
053: * @return a Collection of Strings, where each element is one of the
054: * constants defined in MenuFactory
055: */
056: public Collection getMenuCategories() {
057: return null;
058: }
059:
060: /* Implements JMeterGUIComponent.createTestElement() */
061: public TestElement createTestElement() {
062: WorkBench wb = new WorkBench();
063: modifyTestElement(wb);
064: return wb;
065: }
066:
067: /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
068: public void modifyTestElement(TestElement wb) {
069: super .configureTestElement(wb);
070: }
071:
072: /**
073: * When a user right-clicks on the component in the test tree, or selects
074: * the edit menu when the component is selected, the component will be asked
075: * to return a JPopupMenu that provides all the options available to the
076: * user from this component.
077: * <p>
078: * The WorkBench returns a popup menu allowing you to add anything.
079: *
080: * @return a JPopupMenu appropriate for the component.
081: */
082: public JPopupMenu createPopupMenu() {
083: JPopupMenu menu = new JPopupMenu();
084: JMenu addMenu = MenuFactory.makeMenus(new String[] {
085: MenuFactory.NON_TEST_ELEMENTS, MenuFactory.CONTROLLERS,
086: MenuFactory.CONFIG_ELEMENTS, MenuFactory.TIMERS,
087: MenuFactory.PRE_PROCESSORS, MenuFactory.SAMPLERS,
088: MenuFactory.ASSERTIONS, MenuFactory.POST_PROCESSORS,
089: MenuFactory.LISTENERS, }, JMeterUtils
090: .getResString("add"), // $NON-NLS-1$
091: ActionNames.ADD);
092: menu.add(addMenu);
093: MenuFactory.addPasteResetMenu(menu);
094: MenuFactory.addFileMenu(menu);
095: return menu;
096: }
097:
098: public String getLabelResource() {
099: return "workbench_title"; // $NON-NLS-1$
100: }
101:
102: /**
103: * Initialize the components and layout of this component.
104: */
105: private void init() {
106: setLayout(new BorderLayout());
107: setBorder(makeBorder());
108:
109: add(makeTitlePanel(), BorderLayout.NORTH);
110: }
111: }
|