diff options
author | Kainan Wang <knwang@google.com> | 2022-03-07 10:50:49 -0800 |
---|---|---|
committer | Kainan Wang <knwang@google.com> | 2022-03-09 22:16:06 +0000 |
commit | 3010ae04ac7a48058deca2edf54fb5c40053a072 (patch) | |
tree | 703e5f6b384d849a251b03a8366c4caa6f9198d7 | |
parent | cc6eca8b8ef2399c2907e4ac0c56cb35d31a2c1f (diff) | |
download | idea-3010ae04ac7a48058deca2edf54fb5c40053a072.tar.gz |
Add a basic interception rules table for network inspector
The table contains a toolbar that supports add, delete, move up
and down. The first column also supports checkbox for boolean.
The component is under a flag without editing functionality.
Bug: 192492298
Test: Intermediate CL, Manual Test
Change-Id: I01cd6ca7b3f5b56f8c003a33248ec66320451739
5 files changed, 125 insertions, 9 deletions
diff --git a/app-inspection/inspectors/network/model/src/com/android/tools/idea/appinspection/inspectors/network/model/rules/RulesTableModel.kt b/app-inspection/inspectors/network/model/src/com/android/tools/idea/appinspection/inspectors/network/model/rules/RulesTableModel.kt new file mode 100644 index 00000000000..b418250f6d4 --- /dev/null +++ b/app-inspection/inspectors/network/model/src/com/android/tools/idea/appinspection/inspectors/network/model/rules/RulesTableModel.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed 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 com.android.tools.idea.appinspection.inspectors.network.model.rules + +import com.intellij.util.ui.ColumnInfo +import com.intellij.util.ui.ListTableModel +import javax.swing.JTable + +class RulesTableModel : ListTableModel<RulesTableModel.Row>() { + class Row { + var name: String = "New Rule" + var isActive: Boolean = true + } + + init { + columnInfos = arrayOf( + object : ColumnInfo<Row, Boolean>("Active") { + override fun valueOf(item: Row): Boolean { + return item.isActive + } + + override fun setValue(item: Row, value: Boolean) { + item.isActive = value + } + override fun getWidth(table: JTable) = 60 + override fun isCellEditable(item: Row) = true + override fun getColumnClass() = Boolean::class.java + }, + object : ColumnInfo<Row, String>("Name") { + override fun valueOf(item: Row): String { + return item.name + } + }) + } +} diff --git a/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/NetworkInspectorView.kt b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/NetworkInspectorView.kt index d70836d7a1b..e3dfe2fe278 100644 --- a/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/NetworkInspectorView.kt +++ b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/NetworkInspectorView.kt @@ -64,6 +64,8 @@ import com.android.tools.idea.appinspection.inspectors.network.view.constants.TI import com.android.tools.idea.appinspection.inspectors.network.view.constants.TOOLTIP_BACKGROUND import com.android.tools.idea.appinspection.inspectors.network.view.constants.Y_AXIS_TOP_MARGIN import com.android.tools.idea.appinspection.inspectors.network.view.details.ConnectionDetailsView +import com.android.tools.idea.appinspection.inspectors.network.view.rules.RulesTableView +import com.android.tools.idea.flags.StudioFlags import com.intellij.ui.JBColor import com.intellij.ui.JBSplitter import com.intellij.ui.components.JBPanel @@ -157,7 +159,13 @@ class NetworkInspectorView( threadsViewScrollPane.border = JBUI.Borders.empty() connectionsTab.addTab("Connection View", connectionScrollPane) connectionsTab.addTab("Thread View", threadsViewScrollPane) - // The toolbar overlays the tab panel so we have to make sure we repaint the parent panel when switching tabs. + if (StudioFlags.ENABLE_NETWORK_INTERCEPTION.get()) { + val rulesView = RulesTableView() + val rulesViewScrollPane = JBScrollPane(rulesView.component) + rulesViewScrollPane.border = JBUI.Borders.empty() + connectionsTab.addTab("Rules", rulesViewScrollPane) + } + // The toolbar overlays the tab panel, so we have to make sure we repaint the parent panel when switching tabs. connectionsTab.addChangeListener { mainPanel.repaint() } connectionsPanel.add(connectionsTab, CARD_CONNECTIONS) val infoPanel = JPanel(BorderLayout()) diff --git a/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/details/ResponseTabContent.kt b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/details/ResponseTabContent.kt index b4cf85019d0..408967fbd8d 100644 --- a/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/details/ResponseTabContent.kt +++ b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/details/ResponseTabContent.kt @@ -59,14 +59,6 @@ class ResponseTabContent( val headersComponent = httpDataComponentFactory.createHeaderComponent(HttpDataComponentFactory.ConnectionType.RESPONSE) panel.add(createHideablePanel(SECTION_TITLE_HEADERS, headersComponent, null)) panel.add(httpDataComponentFactory.createBodyComponent(componentsProvider, HttpDataComponentFactory.ConnectionType.RESPONSE)) - if (ENABLE_NETWORK_INTERCEPTION.get()) { - val button = JButton("Intercept") - button.addActionListener { - val dialog: DialogWrapper = ResponseInterceptDialog(data, inspectorServices, scope) - dialog.show() - } - panel.add(button) - } } @VisibleForTesting diff --git a/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/rules/DecoratedTable.kt b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/rules/DecoratedTable.kt new file mode 100644 index 00000000000..f6a58fc00ff --- /dev/null +++ b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/rules/DecoratedTable.kt @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed 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 com.android.tools.idea.appinspection.inspectors.network.view.rules + +import com.android.tools.adtui.TabularLayout +import com.intellij.ui.ToolbarDecorator +import com.intellij.ui.table.TableView +import com.intellij.util.ui.ListTableModel +import javax.swing.BorderFactory +import javax.swing.JPanel + +/** + * A Table class with decorated toolbar for network inspector. + */ +class DecoratedTable<Item>(model: ListTableModel<Item>) { + val component = JPanel(TabularLayout("*", "Fit,Fit,*")) + + init { + val table = TableView(model) + val decorator = ToolbarDecorator.createDecorator(table) + component.add(decorator.createPanel().apply { + border = BorderFactory.createEmptyBorder() + }, TabularLayout.Constraint(0, 0)) + component.add(table.tableHeader, TabularLayout.Constraint(1, 0)) + component.add(table, TabularLayout.Constraint(2, 0)) + } +} diff --git a/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/rules/RulesTableView.kt b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/rules/RulesTableView.kt new file mode 100644 index 00000000000..daa080e36f6 --- /dev/null +++ b/app-inspection/inspectors/network/view/src/com/android/tools/idea/appinspection/inspectors/network/view/rules/RulesTableView.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed 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 com.android.tools.idea.appinspection.inspectors.network.view.rules + +import com.android.tools.idea.appinspection.inspectors.network.model.rules.RulesTableModel +import javax.swing.JComponent + +class RulesTableView { + val component: JComponent + private val tableModel = RulesTableModel() + + init { + component = DecoratedTable(tableModel).component + } +} |