Exemplo n.º 1
0
 def __init__(self, jtp):
     aevent.MouseAdapter.__init__(self)
     self.jtp = jtp
     self.ccp = swing.JPopupMenu()
     cut = swing.JMenuItem("Cut")
     cut.actionPerformed = lambda event: jtp.cut()
     self.ccp.add(cut)
     copy = swing.JMenuItem("Copy")
     copy.actionPerformed = lambda event: jtp.copy()
     self.ccp.add(copy)
     paste = swing.JMenuItem("Paste")
     paste.actionPerformed = lambda event: jtp.paste()
     self.ccp.add(paste)
     jtp.addMouseListener(self)
Exemplo n.º 2
0
 def __init__( self, jtcomponent ):
     
     self.jtcomponent = jtcomponent
     self.popup = popup = swing.JPopupMenu()
     i1 = swing.JMenuItem( "Cut" )
     i1.actionPerformed = lambda event: jtcomponent.cut()
     popup.add( i1 )
     i2 = swing.JMenuItem( "Copy" )
     i2.actionPerformed = lambda event: jtcomponent.copy()
     popup.add( i2 )
     i3 = swing.JMenuItem( "Paste" )
     i3.actionPerformed = lambda event: jtcomponent.paste()
     popup.add( i3 )
     i4 = swing.JMenuItem( "Select All" )
     i4.actionPerformed = lambda event: jtcomponent.selectAll()
     popup.add( i4 )
     jtcomponent.addMouseListener( self )
Exemplo n.º 3
0
    def trigger(self, x, y):
        menu = swing.JPopupMenu()
        menu.setInvoker(self.thing)

        for a in self.thing.attrKeys:
            if a in self.thing.editable.keys():
                choices = self.thing.editable[a]
                if choices == ():
                    menu.add(
                        swing.JMenuItem('Select %s' % a,
                                        actionPerformed=lambda x, self=self, a=
                                        a: self.setAttrUnknown(a)))
                else:
                    m2 = swing.JMenu('Choose %s' % a)
                    for c in choices:
                        m2.add(
                            swing.JMenuItem(
                                '%s' % c,
                                actionPerformed=lambda x, server=self.thing.
                                parent.server, id=self.thing.id, a=a, choice=c:
                                server.trySetValue(id, a, choice)))
                    menu.add(m2)

        list = [(name, id) for id, name in self.thing.actions.items()]
        list.sort()
        for name, id in list:
            menu.add(
                swing.JMenuItem(name,
                                actionPerformed=lambda x, self=self, id=id:
                                self.doAction(id)))

        if menu.componentCount > 0:
            s = self.thing.getLocationOnScreen()
            x = s.x + x - 10
            y = s.y + y - 5
            sizeP = menu.preferredSize
            sizeS = getScreenBounds()
            if x + sizeP.width > sizeS.width + sizeS.x:
                x = sizeS.width + sizeS.x - sizeP.width
            if y + sizeP.height > sizeS.height + sizeS.y:
                y = sizeS.height + sizeS.y - sizeP.height
            menu.setLocation(x, y)
            menu.setVisible(1)
Exemplo n.º 4
0
    def registerExtenderCallbacks(self, callbacks):
        # for error handling
        sys.stdout = callbacks.getStdout()
        sys.stderr = callbacks.getStderr()

        self._callbacks = callbacks
        self._helpers = callbacks.getHelpers()

        jsonFilter = FileNameExtensionFilter("JSON files", ['json'])

        basePath = self._callbacks.loadExtensionSetting(SETTING_LAST_PATH)
        # print("got last path {}".format(basePath))

        self._collectionChooser = swing.JFileChooser(basePath)
        self._collectionChooser.setFileFilter(jsonFilter)

        self._environmentChooser = swing.JFileChooser(basePath)
        self._environmentChooser.setFileFilter(jsonFilter)

        # ### Top "buttons" pane
        controlPane = swing.JPanel()
        controlPane.setBorder(EmptyBorder(10, 20, 0, 10))
        controlPane.setLayout(
            swing.BoxLayout(controlPane, swing.BoxLayout.PAGE_AXIS))
        controlPane.setAlignmentX(swing.Box.LEFT_ALIGNMENT)

        box1 = swing.Box.createHorizontalBox()
        box1.setAlignmentX(swing.Box.LEFT_ALIGNMENT)
        box1.add(
            swing.JButton('Load Collection',
                          actionPerformed=self.loadCollection))
        self._collectionLabel = swing.JLabel("Choose a collection file")
        box1.add(self._collectionLabel)
        controlPane.add(box1)

        box2 = swing.Box.createHorizontalBox()
        box2.setAlignmentX(swing.Box.LEFT_ALIGNMENT)
        box2.add(
            swing.JButton('Load Environment',
                          actionPerformed=self.loadEnvironment))
        self._environmentLabel = swing.JLabel("Choose an environment file")
        box2.add(self._environmentLabel)
        controlPane.add(box2)

        # ### end Top "controls" pane

        # ### instructions
        instructionsPane = swing.JPanel(BorderLayout())
        instructions = swing.JLabel()
        instructions.setText("""<html><body>
<h3>Usage:</h3>
<ol>
<li>Select the Collection Postman JSON file. This should extract all discovered environment variables.</li>
<li>(Optional) Select an Environment Postman JSON file. This can be the same as the Collection file.</li>
<li>Set environment variables below.</li>
<li>Choose 'Create Requests' to create Repeater tabs.</li>
</ol>
</body></html>""")
        instructionsPane.add(instructions, BorderLayout.NORTH)
        # ### end instructions

        # ### environment variables
        envTablePane = swing.JPanel(BorderLayout())
        envLabel = swing.JLabel("Environment Variables")
        envLabel.setBorder(EmptyBorder(5, 5, 5, 5))
        envLabel.setFont(
            Font(envLabel.getFont().getName(), Font.BOLD,
                 envLabel.getFont().getSize() + 2))
        envTablePane.add(envLabel, BorderLayout.NORTH)

        self._envTable = swing.JTable(DefaultTableModel([], self._envCols))
        self._envTable.setAutoCreateRowSorter(True)
        self._envTable.getTableHeader().setReorderingAllowed(False)
        tableMenu = swing.JPopupMenu()
        tableMenu.add(swing.JMenuItem("Add New", actionPerformed=self._addEnv))
        tableMenu.add(
            swing.JMenuItem("Clear All", actionPerformed=self._clearEnv))
        deleteMenuItem = swing.JMenuItem("Delete Row",
                                         actionPerformed=self._deleteEnv)
        deleteMenuItem.setEnabled(False)
        tableMenu.add(deleteMenuItem)
        self._envTable.setComponentPopupMenu(tableMenu)
        listener = self._envTableListener(self)
        self._envTable.addMouseListener(listener)
        renderer = self._envTableRenderer()
        self._envTable.setDefaultRenderer(Class.forName('java.lang.Object'),
                                          renderer)

        envTablePaneMenu = swing.JPopupMenu()
        envTablePaneMenu.add(
            swing.JMenuItem("Add New", actionPerformed=self._addEnv))
        envTablePaneMenu.add(
            swing.JMenuItem("Clear All", actionPerformed=self._clearEnv))
        scrl = swing.JScrollPane(self._envTable)
        scrl.setComponentPopupMenu(envTablePaneMenu)
        envTablePane.add(scrl)
        # ### end environment variables

        # ### requests
        reqTablePane = swing.JPanel(BorderLayout())
        reqLabel = swing.JLabel("Requests")
        reqLabel.setBorder(EmptyBorder(5, 5, 5, 5))
        reqLabel.setFont(envLabel.getFont())
        reqTablePane.add(reqLabel, BorderLayout.NORTH)

        self._reqTable = self._reqTableClass(
            DefaultTableModel([], self._reqCols))
        self._reqTable.setAutoCreateRowSorter(True)
        self._reqTable.getTableHeader().setReorderingAllowed(False)
        self._reqTable.setAutoResizeMode(swing.JTable.AUTO_RESIZE_LAST_COLUMN)
        self._reqTable.getTableHeader().setReorderingAllowed(False)
        self._reqTable.getColumnModel().getColumn(0).setMaxWidth(150)
        self._reqTable.getColumnModel().getColumn(0).setMinWidth(150)
        self._reqTable.getColumnModel().getColumn(2).setMaxWidth(150)
        self._reqTable.getColumnModel().getColumn(2).setMinWidth(150)
        scrl2 = swing.JScrollPane(self._reqTable)
        reqTablePane.add(scrl2)
        # ### end requests

        # ### Logs
        logPane = swing.JPanel(BorderLayout())

        buttonBox = swing.JPanel(FlowLayout(FlowLayout.LEFT, 20, 0))
        requestButtonBox = swing.Box.createHorizontalBox()
        self._selectButtons = [
            swing.JButton('Select All', actionPerformed=self.selectAll),
            swing.JButton('Select None', actionPerformed=self.selectNone),
            swing.JButton('Invert Selection',
                          actionPerformed=self.selectInvert)
        ]
        for btn in self._selectButtons:
            requestButtonBox.add(btn)
            btn.setEnabled(False)

        buttonBox.add(requestButtonBox)

        self._createRequestsButton = swing.JButton(
            'Create Requests', actionPerformed=self.createRequests)
        self._createRequestsButton.setEnabled(False)
        requestButtonBox.add(self._createRequestsButton)

        buttonBox.add(self._createRequestsButton)

        self._logButton = swing.JButton('Clear Log',
                                        actionPerformed=self.clearLog)
        self._logButton.setEnabled(False)
        buttonBox.add(self._logButton)

        logPane.add(buttonBox, BorderLayout.NORTH)

        self._log = swing.JTextPane()
        self._log.setEditable(False)
        self._log.setFont(Font("monospaced", Font.PLAIN, 12))
        logPane.add(swing.JScrollPane(self._log))
        # ### end Logs

        # ### add panels
        self._topControlsPane = swing.JSplitPane(
            swing.JSplitPane.HORIZONTAL_SPLIT, controlPane, instructionsPane)
        p1 = swing.JSplitPane(swing.JSplitPane.VERTICAL_SPLIT,
                              self._topControlsPane, envTablePane)
        p2 = swing.JSplitPane(swing.JSplitPane.VERTICAL_SPLIT, p1,
                              reqTablePane)
        p2.setResizeWeight(0.5)
        self._panel = swing.JSplitPane(swing.JSplitPane.VERTICAL_SPLIT, p2,
                                       logPane)
        self._panel.setResizeWeight(0.6)
        # ### end add panels

        callbacks.setExtensionName(NAME)
        callbacks.addSuiteTab(self)