Example #1
0
    def __private_init__(self,
                         text="Property Editor",
                         columns=None,
                         data=None,
                         empty=None,
                         add_actions=True,
                         actions=None):
        if not actions: actions = []
        if not columns: columns = []
        if data == None: data = []
        if not empty: empty = []

        self._text = text
        self.this = JFrame(text)
        self._table = JTable()
        self._dtm = DefaultTableModel(0, 0)
        self._dtm.setColumnIdentifiers(columns)
        self._table.setModel(self._dtm)
        self._data = data
        for d in data:
            self._dtm.addRow(d)
        self._pane = JScrollPane(self._table)
        self.this.add(self._pane)
        self._empty = empty

        self.this.addWindowListener(self)

        self._dtm.addTableModelListener(lambda _: self._update_model())
        self.this.setLocation(PropertyEditor.NEW_WINDOW_OFFSET,
                              PropertyEditor.NEW_WINDOW_OFFSET)

        if add_actions:
            self._popup = JPopupMenu()
            self._pane.setComponentPopupMenu(self._popup)
            inherits_popup_menu(self._pane)

            self._actions = actions
            self._actions.append(
                ExecutorAction('Remove Selected Rows',
                               action=lambda e: self._remove_row()))
            self._actions.append(
                ExecutorAction('Add New Row',
                               action=lambda e: self._add_row()))

            for action in self._actions:
                self._popup.add(action.menuitem)

        self.this.setForeground(Color.black)
        self.this.setBackground(Color.lightGray)
        self.this.pack()
        self.this.setVisible(True)
        self.this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE)

        return self
Example #2
0
 def _setup(self):
     """
     Setup callback
     :return: None
     """
     PropertyEditor.get_instance(text="Configure InQL",
                                 columns=['Property', 'Value'],
                                 data=self._run_config,
                                 actions=[
                                     ExecutorAction(
                                         "Setup Load Headers",
                                         lambda _: self._setup_headers()),
                                     ExecutorAction("Reset",
                                                    lambda _: self._reset())
                                 ])
Example #3
0
    def __init__(self,
                 actions=[],
                 restore=None,
                 proxy=None,
                 http_mutator=None,
                 texteditor_factory=None,
                 requests=None,
                 stub_responses=None):
        self._requests = requests if requests is not None else {}
        self._stub_responses = stub_responses if stub_responses is not None else {}
        self._actions = actions
        self._load_headers = []
        self._run_config = [['Proxy', proxy], ['Authorization Key', None],
                            ['Load Placeholders', True],
                            ['Generate HTML DOC', True],
                            ['Generate Schema DOC', False],
                            ['Generate Stub Queries', True],
                            ['Accept Invalid SSL Certificate', True],
                            ['Generate Cycles Report', False],
                            ['Cycles Report Timeout', 60],
                            ['Generate TSV', False]]
        self._init_config = json.loads(json.dumps(self._run_config))
        self._default_config = {}
        for k, v in self._run_config:
            self._default_config[k] = v
        self._old_config_hash = None
        self._actions.insert(0, BrowserAction())
        self._actions.insert(
            0, ExecutorAction("Configure", lambda _: self._setup()))
        self._actions.insert(0, ExecutorAction("Load", self._loadurl))
        self._http_mutator = http_mutator

        self.this = JPanel()
        self.this.setLayout(BorderLayout())
        self._omnibar = Omnibar(hint=DEFAULT_LOAD_URL,
                                label="Load",
                                action=self._loadurl)
        self.this.add(BorderLayout.PAGE_START, self._omnibar.this)
        self._fileview = FileView(
            dir=os.getcwd(),
            filetree_label="Queries, Mutations and Subscriptions",
            texteditor_factory=texteditor_factory)
        self.this.add(BorderLayout.CENTER, self._fileview.this)
        self._fileview.addTreeListener(self._tree_listener)
        self._fileview.addPayloadListener(self._payload_listener)

        self._popup = JPopupMenu()
        self.this.setComponentPopupMenu(self._popup)
        inherits_popup_menu(self.this)

        for action in self._actions:
            self._popup.add(action.menuitem)

        self._state = {'runs': []}
        try:
            if restore:
                cfg = json.loads(restore)
                if 'runs' in cfg:
                    for target, key, proxy, headers, load_placeholer, generate_html, generate_schema, generate_queries, generate_cycles, cycles_timeout, generate_tsv, accept_invalid_certificate, flag in cfg[
                            'runs']:
                        self._run(target=target,
                                  key=key,
                                  proxy=proxy,
                                  headers=headers,
                                  load_placeholer=load_placeholer,
                                  generate_html=generate_html,
                                  generate_schema=generate_schema,
                                  generate_queries=generate_queries,
                                  generate_cycles=generate_cycles,
                                  cycles_timeout=cycles_timeout,
                                  generate_tsv=generate_tsv,
                                  accept_invalid_certificate=
                                  accept_invalid_certificate,
                                  flag=flag)
                self._run_config = cfg['config']
        except Exception as ex:
            print(
                "Cannot Load old configuration: starting with a clean state: %s"
                % ex)
            sys.stdout.flush()
        self._state['config'] = self._run_config
Example #4
0
    def __init__(self, actions=[], restore=None):
        self._actions = actions
        self._load_headers = []
        self._run_config = [['Proxy', None], ['Authorization Key', None],
                            ['Load Placeholders', True],
                            ['Generate HTML DOC', False],
                            ['Generate Schema DOC', False],
                            ['Generate Stub Queries', True],
                            ['Accept Invalid SSL Certificate', False]]
        self._default_config = {}
        for k, v in self._run_config:
            self._default_config[k] = v
        self._old_config_hash = None
        self._actions.append(BrowserAction())
        self._actions.append(
            ExecutorAction("Configure", lambda _: self._setup()))
        self._actions.append(ExecutorAction("Load", self._loadurl))
        self._actions = [a for a in reversed(self._actions)]

        self.this = JPanel()
        self.this.setLayout(BorderLayout())
        self._omnibar = Omnibar(hint=DEFAULT_LOAD_URL,
                                label="Load",
                                action=self._loadurl)
        self.this.add(BorderLayout.PAGE_START, self._omnibar.this)
        self._fileview = FileView(
            dir=os.getcwd(),
            filetree_label="Queries, Mutations and Subscriptions",
            payloadview_label="Query Template")
        self.this.add(BorderLayout.CENTER, self._fileview.this)
        self._fileview.addTreeListener(self._tree_listener)
        self._fileview.addPayloadListener(self._payload_listener)

        self._popup = JPopupMenu()
        self.this.setComponentPopupMenu(self._popup)
        inherits_popup_menu(self.this)

        for action in self._actions:
            self._popup.add(action.menuitem)

        self._state = {'runs': []}
        try:
            if restore:
                cfg = json.loads(restore)
                for target, key, proxy, headers, load_placeholer, generate_html, generate_schema, generate_queries, accept_invalid_certificate, flag in cfg[
                        'runs']:
                    self._run(
                        target=target,
                        key=key,
                        proxy=proxy,
                        headers=headers,
                        load_placeholer=load_placeholer,
                        generate_html=generate_html,
                        generate_schema=generate_schema,
                        generate_queries=generate_queries,
                        accept_invalid_certificate=accept_invalid_certificate,
                        flag=flag)
                self._run_config = cfg['config']
        except Exception as ex:
            print(
                "Cannot Load old configuration: starting with a clean state: %s"
                % ex)
            sys.stdout.flush()
        self._state['config'] = self._run_config