Beispiel #1
0
  private JComponent getLibrariesTable() {
    myLibraryTableModel = new LibraryTableModel();
    final JBTable librariesTable = new JBTable(myLibraryTableModel);
    librariesTable.setTableHeader(null);
    librariesTable.setDefaultRenderer(String.class, new MyPathRenderer());
    librariesTable.setShowHorizontalLines(false);
    librariesTable.setShowVerticalLines(false);
    librariesTable.setAutoCreateRowSorter(false);
    librariesTable.setAutoscrolls(true);

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(librariesTable);
    decorator
        .setAddAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton anActionButton) {
                List<ModelRootDescriptor> modelRoots =
                    new ArrayList<ModelRootDescriptor>(
                        myJavaModuleFacet
                            .getModule()
                            .getModuleDescriptor()
                            .getModelRootDescriptors());
                StubRootChooser stubRootChooser =
                    new StubRootChooser(
                        modelRoots,
                        (myJavaModuleFacet.getModule() instanceof Language ? true : false));
                myLibraryTableModel.addAll(stubRootChooser.compute());
              }
            })
        .setRemoveAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton anActionButton) {
                TableUtil.removeSelectedItems(librariesTable);
                myLibraryTableModel.fireTableDataChanged();
              }
            });
    decorator.setToolbarBorder(IdeBorderFactory.createBorder());
    decorator.setPreferredSize(new Dimension(500, 100));

    JPanel table = decorator.createPanel();
    table.setBorder(
        IdeBorderFactory.createTitledBorder(
            PropertiesBundle.message("mps.properties.configurable.module.javatab.librariesborder"),
            false));
    return table;
  }
Beispiel #2
0
  private JComponent getSourcePathsTable() {
    myPathsTableModel = new PathsTableModel();
    final JBTable sourcePathTable = new JBTable(myPathsTableModel);
    sourcePathTable.setTableHeader(null);
    sourcePathTable.setDefaultRenderer(String.class, new MyPathRenderer());
    sourcePathTable.setShowHorizontalLines(false);
    sourcePathTable.setShowVerticalLines(false);
    sourcePathTable.setAutoCreateRowSorter(false);
    sourcePathTable.setAutoscrolls(true);

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(sourcePathTable);
    decorator
        .setAddAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton anActionButton) {
                myPathsTableModel.add((new PathChooser()).compute());
              }
            })
        .setRemoveAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton anActionButton) {
                TableUtil.removeSelectedItems(sourcePathTable);
                myPathsTableModel.fireTableDataChanged();
              }
            });
    decorator.setToolbarBorder(IdeBorderFactory.createBorder());
    decorator.setPreferredSize(new Dimension(500, 100));

    JPanel table = decorator.createPanel();
    table.setBorder(
        IdeBorderFactory.createTitledBorder(
            PropertiesBundle.message("mps.properties.configurable.module.javatab.sourcepathborder"),
            false));
    return table;
  }
  public ClasspathPanelImpl(ModuleConfigurationState state) {
    super(new BorderLayout());

    myState = state;
    myModel = new ClasspathTableModel(state, getStructureConfigurableContext());
    myEntryTable =
        new JBTable(myModel) {
          @Override
          protected TableRowSorter<TableModel> createRowSorter(TableModel model) {
            return new DefaultColumnInfoBasedRowSorter(model) {
              @Override
              public void toggleSortOrder(int column) {
                if (isSortable(column)) {
                  SortKey oldKey = ContainerUtil.getFirstItem(getSortKeys());
                  SortOrder oldOrder;
                  if (oldKey == null || oldKey.getColumn() != column) {
                    oldOrder = SortOrder.UNSORTED;
                  } else {
                    oldOrder = oldKey.getSortOrder();
                  }
                  setSortKeys(
                      Collections.singletonList(new SortKey(column, getNextSortOrder(oldOrder))));
                }
              }
            };
          }
        };
    myEntryTable.setShowGrid(false);
    myEntryTable.setDragEnabled(false);
    myEntryTable.setIntercellSpacing(new Dimension(0, 0));

    myEntryTable.setDefaultRenderer(
        ClasspathTableItem.class, new TableItemRenderer(getStructureConfigurableContext()));
    myEntryTable.setDefaultRenderer(
        Boolean.class, new ExportFlagRenderer(myEntryTable.getDefaultRenderer(Boolean.class)));

    JComboBox scopeEditor =
        new ComboBox(new EnumComboBoxModel<DependencyScope>(DependencyScope.class));
    myEntryTable.setDefaultEditor(DependencyScope.class, new DefaultCellEditor(scopeEditor));
    myEntryTable.setDefaultRenderer(
        DependencyScope.class,
        new ComboBoxTableRenderer<DependencyScope>(DependencyScope.values()) {
          @Override
          protected String getTextFor(@NotNull final DependencyScope value) {
            return value.getDisplayName();
          }
        });

    myEntryTable.setTransferHandler(
        new TransferHandler() {
          @Nullable
          @Override
          protected Transferable createTransferable(JComponent c) {
            OrderEntry entry = getSelectedEntry();
            if (entry == null) return null;
            String text = entry.getPresentableName();
            return new TextTransferable(text);
          }

          @Override
          public int getSourceActions(JComponent c) {
            return COPY;
          }
        });

    myEntryTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    new SpeedSearchBase<JBTable>(myEntryTable) {
      @Override
      public int getSelectedIndex() {
        return myEntryTable.getSelectedRow();
      }

      @Override
      protected int convertIndexToModel(int viewIndex) {
        return myEntryTable.convertRowIndexToModel(viewIndex);
      }

      @Override
      public Object[] getAllElements() {
        final int count = myModel.getRowCount();
        Object[] elements = new Object[count];
        for (int idx = 0; idx < count; idx++) {
          elements[idx] = myModel.getItem(idx);
        }
        return elements;
      }

      @Override
      public String getElementText(Object element) {
        return getCellAppearance(
                (ClasspathTableItem<?>) element, getStructureConfigurableContext(), false)
            .getText();
      }

      @Override
      public void selectElement(Object element, String selectedText) {
        final int count = myModel.getRowCount();
        for (int row = 0; row < count; row++) {
          if (element.equals(myModel.getItem(row))) {
            final int viewRow = myEntryTable.convertRowIndexToView(row);
            myEntryTable.getSelectionModel().setSelectionInterval(viewRow, viewRow);
            TableUtil.scrollSelectionToVisible(myEntryTable);
            break;
          }
        }
      }
    };
    setFixedColumnWidth(ClasspathTableModel.EXPORT_COLUMN);
    setFixedColumnWidth(ClasspathTableModel.SCOPE_COLUMN); // leave space for combobox border

    myEntryTable.registerKeyboardAction(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final int[] selectedRows = myEntryTable.getSelectedRows();
            boolean currentlyMarked = true;
            for (final int selectedRow : selectedRows) {
              final ClasspathTableItem<?> item = getItemAt(selectedRow);
              if (selectedRow < 0 || !item.isExportable()) {
                return;
              }
              currentlyMarked &= item.isExported();
            }
            for (final int selectedRow : selectedRows) {
              getItemAt(selectedRow).setExported(!currentlyMarked);
            }
            myModel.fireTableDataChanged();
            TableUtil.selectRows(myEntryTable, selectedRows);
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
        WHEN_FOCUSED);

    myEditButton =
        new AnActionButton(
            ProjectBundle.message("module.classpath.button.edit"), null, IconUtil.getEditIcon()) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            doEdit();
          }

          @Override
          public boolean isEnabled() {
            ClasspathTableItem<?> selectedItem = getSelectedItem();
            return selectedItem != null && selectedItem.isEditable();
          }

          @Override
          public boolean isDumbAware() {
            return true;
          }
        };
    add(createTableWithButtons(), BorderLayout.CENTER);

    if (myEntryTable.getRowCount() > 0) {
      myEntryTable.getSelectionModel().setSelectionInterval(0, 0);
    }

    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent e) {
        navigate(true);
        return true;
      }
    }.installOn(myEntryTable);

    DefaultActionGroup actionGroup = new DefaultActionGroup();
    final AnAction navigateAction =
        new AnAction(ProjectBundle.message("classpath.panel.navigate.action.text")) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            navigate(false);
          }

          @Override
          public void update(@NotNull AnActionEvent e) {
            final Presentation presentation = e.getPresentation();
            presentation.setEnabled(false);
            final OrderEntry entry = getSelectedEntry();
            if (entry != null && entry.isValid()) {
              if (!(entry instanceof ModuleSourceOrderEntry)) {
                presentation.setEnabled(true);
              }
            }
          }
        };
    navigateAction.registerCustomShortcutSet(
        ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(),
        myEntryTable);
    actionGroup.add(myEditButton);
    actionGroup.add(myRemoveButton);
    actionGroup.add(navigateAction);
    actionGroup.add(new InlineModuleDependencyAction(this));
    actionGroup.add(new MyFindUsagesAction());
    actionGroup.add(new AnalyzeDependencyAction());
    addChangeLibraryLevelAction(actionGroup, LibraryTablesRegistrar.PROJECT_LEVEL);
    addChangeLibraryLevelAction(actionGroup, LibraryTablesRegistrar.APPLICATION_LEVEL);
    addChangeLibraryLevelAction(actionGroup, LibraryTableImplUtil.MODULE_LEVEL);
    PopupHandler.installPopupHandler(
        myEntryTable, actionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
  }
  public DirDiffPanel(DirDiffTableModel model, DirDiffWindow wnd) {
    myModel = model;
    myDiffWindow = wnd;
    mySourceDirField.setText(model.getSourceDir().getPath());
    myTargetDirField.setText(model.getTargetDir().getPath());
    mySourceDirField.setBorder(JBUI.Borders.emptyRight(8));
    myTargetDirField.setBorder(JBUI.Borders.emptyRight(12));
    mySourceDirLabel.setIcon(model.getSourceDir().getIcon());
    myTargetDirLabel.setIcon(model.getTargetDir().getIcon());
    myTargetDirLabel.setBorder(JBUI.Borders.emptyLeft(8));
    myModel.setTable(myTable);
    myModel.setPanel(this);
    Disposer.register(this, myModel);
    myTable.setModel(myModel);
    new TableSpeedSearch(myTable);

    final DirDiffTableCellRenderer renderer = new DirDiffTableCellRenderer();
    myTable.setExpandableItemsEnabled(false);
    myTable.setDefaultRenderer(Object.class, renderer);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final Project project = myModel.getProject();
    myTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                final int lastIndex = e.getLastIndex();
                final int firstIndex = e.getFirstIndex();
                final DirDiffElementImpl last = myModel.getElementAt(lastIndex);
                final DirDiffElementImpl first = myModel.getElementAt(firstIndex);
                if (last == null || first == null) {
                  update(false);
                  return;
                }
                if (last.isSeparator()) {
                  final int ind = lastIndex + ((lastIndex < firstIndex) ? 1 : -1);
                  myTable.getSelectionModel().addSelectionInterval(ind, ind);
                } else if (first.isSeparator()) {
                  final int ind = firstIndex + ((firstIndex < lastIndex) ? 1 : -1);
                  myTable.getSelectionModel().addSelectionInterval(ind, ind);
                } else {
                  update(false);
                }
                myDiffWindow.setTitle(myModel.getTitle());
              }
            });
    if (model.isOperationsEnabled()) {
      new AnAction("Change diff operation") {
        @Override
        public void actionPerformed(AnActionEvent e) {
          changeOperationForSelection();
        }
      }.registerCustomShortcutSet(CustomShortcutSet.fromString("SPACE"), myTable);
      new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
          if (e.getButton() == MouseEvent.BUTTON3) return false;
          if (myTable.getRowCount() > 0) {
            final int row = myTable.rowAtPoint(e.getPoint());
            final int col = myTable.columnAtPoint(e.getPoint());

            if (row != -1 && col == ((myTable.getColumnCount() - 1) / 2)) {
              changeOperationForSelection();
            }
          }
          return true;
        }
      }.installOn(myTable);
    }
    myTable.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();

            int row;
            if (keyCode == KeyEvent.VK_DOWN) {
              row = getNextRow();
            } else if (keyCode == KeyEvent.VK_UP) {
              row = getPrevRow();
            } else {
              row = -1;
            }

            if (row != -1) {
              selectRow(row, e.isShiftDown());
              e.consume();
            }
          }
        });
    final TableColumnModel columnModel = myTable.getColumnModel();
    final TableColumn operationColumn =
        columnModel.getColumn((columnModel.getColumnCount() - 1) / 2);
    operationColumn.setMaxWidth(JBUI.scale(25));
    operationColumn.setMinWidth(JBUI.scale(25));
    for (int i = 0; i < columnModel.getColumnCount(); i++) {
      final String name = myModel.getColumnName(i);
      final TableColumn column = columnModel.getColumn(i);
      if (DirDiffTableModel.COLUMN_DATE.equals(name)) {
        column.setMaxWidth(JBUI.scale(90));
        column.setMinWidth(JBUI.scale(90));
      } else if (DirDiffTableModel.COLUMN_SIZE.equals(name)) {
        column.setMaxWidth(JBUI.scale(120));
        column.setMinWidth(JBUI.scale(120));
      }
    }
    final DirDiffToolbarActions actions = new DirDiffToolbarActions(myModel, myDiffPanel);
    final ActionManager actionManager = ActionManager.getInstance();
    final ActionToolbar toolbar = actionManager.createActionToolbar("DirDiff", actions, true);
    registerCustomShortcuts(actions, myTable);
    myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER);
    final JBLabel label =
        new JBLabel(
            "Use Space button or mouse click to change operation for the selected elements."
                + " Enter to perform.",
            SwingConstants.CENTER);
    label.setForeground(UIUtil.getInactiveTextColor());
    UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label);
    DataManager.registerDataProvider(myFilesPanel, this);
    myTable.addMouseListener(
        new PopupHandler() {
          @Override
          public void invokePopup(Component comp, int x, int y) {
            final JPopupMenu popupMenu =
                actionManager
                    .createActionPopupMenu(
                        "DirDiffPanel", (ActionGroup) actionManager.getAction("DirDiffMenu"))
                    .getComponent();
            popupMenu.show(comp, x, y);
          }
        });
    myFilesPanel.add(label, BorderLayout.SOUTH);
    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable());
    loadingPanel.addListener(
        new JBLoadingPanelListener.Adapter() {
          boolean showHelp = true;

          @Override
          public void onLoadingFinish() {
            if (showHelp && myModel.isOperationsEnabled() && myModel.getRowCount() > 0) {
              final long count =
                  PropertiesComponent.getInstance().getOrInitLong("dir.diff.space.button.info", 0);
              if (count < 3) {
                JBPopupFactory.getInstance()
                    .createBalloonBuilder(new JLabel(" Use Space button to change operation"))
                    .setFadeoutTime(5000)
                    .setContentInsets(JBUI.insets(15))
                    .createBalloon()
                    .show(
                        new RelativePoint(myTable, new Point(myTable.getWidth() / 2, 0)),
                        Balloon.Position.above);
                PropertiesComponent.getInstance()
                    .setValue("dir.diff.space.button.info", String.valueOf(count + 1));
              }
            }
            showHelp = false;
          }
        });
    loadingPanel.add(myComponent, BorderLayout.CENTER);
    myTable.putClientProperty(myModel.DECORATOR, loadingPanel);
    myTable.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentShown(ComponentEvent e) {
            myTable.removeComponentListener(this);
            myModel.reloadModel(false);
          }
        });
    myRootPanel.removeAll();
    myRootPanel.add(loadingPanel, BorderLayout.CENTER);
    myFilter =
        new FilterComponent("dir.diff.filter", 15, false) {
          @Override
          public void filter() {
            fireFilterUpdated();
          }

          @Override
          protected void onEscape(KeyEvent e) {
            e.consume();
            focusTable();
          }

          @Override
          protected JComponent getPopupLocationComponent() {
            return UIUtil.findComponentOfType(
                super.getPopupLocationComponent(), JTextComponent.class);
          }
        };

    myModel.addModelListener(
        new DirDiffModelListener() {
          @Override
          public void updateStarted() {
            myFilter.setEnabled(false);
          }

          @Override
          public void updateFinished() {
            myFilter.setEnabled(true);
          }
        });
    myFilter.getTextEditor().setColumns(10);
    myFilter.setFilter(myModel.getSettings().getFilter());
    // oldFilter = myFilter.getText();
    oldFilter = myFilter.getFilter();
    myFilterPanel.add(myFilter, BorderLayout.CENTER);
    myFilterLabel.setLabelFor(myFilter);
    final Callable<DiffElement> srcChooser = myModel.getSourceDir().getElementChooser(project);
    final Callable<DiffElement> trgChooser = myModel.getTargetDir().getElementChooser(project);
    mySourceDirField.setEditable(false);
    myTargetDirField.setEditable(false);

    if (srcChooser != null && myModel.getSettings().enableChoosers) {
      mySourceDirField.setButtonEnabled(true);
      mySourceDirField.addActionListener(
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                final Callable<DiffElement> chooser =
                    myModel.getSourceDir().getElementChooser(project);
                if (chooser == null) return;
                final DiffElement newElement = chooser.call();
                if (newElement != null) {
                  if (!StringUtil.equals(mySourceDirField.getText(), newElement.getPath())) {
                    myModel.setSourceDir(newElement);
                    mySourceDirField.setText(newElement.getPath());
                    String shortcutsText =
                        KeymapUtil.getShortcutsText(
                            RefreshDirDiffAction.REFRESH_SHORTCUT.getShortcuts());
                    myModel.clearWithMessage(
                        "Source or Target has been changed."
                            + " Please run Refresh ("
                            + shortcutsText
                            + ")");
                  }
                }
              } catch (Exception ignored) {
              }
            }
          });
    } else {
      Dimension preferredSize = mySourceDirField.getPreferredSize();
      mySourceDirField.setButtonEnabled(false);
      mySourceDirField.getButton().setVisible(false);
      mySourceDirField.setPreferredSize(preferredSize);
    }

    if (trgChooser != null && myModel.getSettings().enableChoosers) {
      myTargetDirField.setButtonEnabled(true);
      myTargetDirField.addActionListener(
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                final Callable<DiffElement> chooser =
                    myModel.getTargetDir().getElementChooser(project);
                if (chooser == null) return;
                final DiffElement newElement = chooser.call();
                if (newElement != null) {
                  myModel.setTargetDir(newElement);
                  myTargetDirField.setText(newElement.getPath());
                }
              } catch (Exception ignored) {
              }
            }
          });
    } else {
      Dimension preferredSize = myTargetDirField.getPreferredSize();
      myTargetDirField.setButtonEnabled(false);
      myTargetDirField.getButton().setVisible(false);
      myTargetDirField.setPreferredSize(preferredSize);
    }

    myDiffRequestProcessor = new MyDiffRequestProcessor(project);
    Disposer.register(this, myDiffRequestProcessor);
    myDiffPanel.add(myDiffRequestProcessor.getComponent(), BorderLayout.CENTER);

    myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable();
  }
  /**
   * The constructor
   *
   * @param project the project
   * @param target the target configuration
   * @param allChanges the all changes
   * @param roots the collection of roots
   * @param remoteBranch the remote branch
   * @param config the configuration
   * @param isModify the modify flag
   * @throws VcsException if there is a problem with detecting the current state
   */
  protected SwitchBranchesDialog(
      Project project,
      final BranchConfiguration target,
      final List<Change> allChanges,
      List<VirtualFile> roots,
      String remoteBranch,
      final BranchConfigurations config,
      boolean isModify)
      throws VcsException {
    super(project, true);
    setTitle(isModify ? "Modify Branch Configuration" : "Checkout Branch Configuration");
    assert (remoteBranch == null) || (target == null)
        : "There should be no target for remote branch";
    myTarget = target;
    myConfig = config;
    myModify = isModify;
    myProject = project;
    VirtualFile baseDir = project.getBaseDir();
    myBaseFile = baseDir == null ? null : new File(baseDir.getPath());
    myExistingConfigNames = myConfig.getConfigurationNames();
    myChangesTree =
        new ChangesTreeList<Change>(
            myProject,
            Collections.<Change>emptyList(),
            !myModify,
            true,
            null,
            RemoteRevisionsCache.getInstance(project).getChangesNodeDecorator()) {
          protected DefaultTreeModel buildTreeModel(
              final List<Change> changes, ChangeNodeDecorator changeNodeDecorator) {
            TreeModelBuilder builder = new TreeModelBuilder(myProject, false);
            return builder.buildModel(changes, changeNodeDecorator);
          }

          protected List<Change> getSelectedObjects(final ChangesBrowserNode<Change> node) {
            return node.getAllChangesUnder();
          }

          @Nullable
          protected Change getLeadSelectedObject(final ChangesBrowserNode node) {
            final Object o = node.getUserObject();
            if (o instanceof Change) {
              return (Change) o;
            }
            return null;
          }
        };
    if (remoteBranch != null) {
      myBranches = prepareBranchesForRemote(remoteBranch, roots);
    } else {
      myBranches = prepareBranchDescriptors(target, roots);
    }
    Collections.sort(
        myBranches,
        new Comparator<BranchDescriptor>() {
          @Override
          public int compare(BranchDescriptor o1, BranchDescriptor o2) {
            return o1.getRoot().compareTo(o2.getRoot());
          }
        });
    if (target == null) {
      myNameTextField.setText(generateNewConfigurationName());
    } else {
      myNameTextField.setText(target.getName());
    }
    myChangesTree.setChangesToDisplay(allChanges);
    myChangesTree.setIncludedChanges(Collections.<Change>emptyList());
    myChangesPanel.add(myChangesTree, BorderLayout.CENTER);
    myChangesLabel.setLabelFor(myChangesTree);
    if (myModify) {
      myChangesLabel.setText("Changes in the current configuration");
    }
    RootTableModel tableModel = new RootTableModel();
    myBranchesTable.setModel(tableModel);
    myBranchesTable.setDefaultRenderer(Pair.class, new PairTableRenderer());
    final TableColumnModel columns = myBranchesTable.getColumnModel();
    final PairTableRenderer renderer = new PairTableRenderer();
    for (Enumeration<TableColumn> cs = columns.getColumns(); cs.hasMoreElements(); ) {
      cs.nextElement().setCellRenderer(renderer);
    }
    TableColumn revisionColumn = columns.getColumn(RootTableModel.REVISION_COLUMN);
    revisionColumn.setCellEditor(new ReferenceEditor());
    TableColumn branchColumn = columns.getColumn(RootTableModel.NEW_BRANCH_COLUMN);
    branchColumn.setCellEditor(new BranchNameEditor());
    myNameTextField
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              @Override
              protected void textChanged(DocumentEvent e) {
                verify();
              }
            });
    tableModel.addTableModelListener(
        new TableModelListener() {
          @Override
          public void tableChanged(TableModelEvent e) {
            verify();
          }
        });
    verify();
    init();
  }
Beispiel #6
0
  public MyDeviceChooser(
      boolean multipleSelection,
      @NotNull final Action okAction,
      @NotNull AndroidFacet facet,
      @NotNull IAndroidTarget projectTarget,
      @Nullable Condition<IDevice> filter) {

    myFacet = facet;
    myFilter = filter;
    myMinSdkVersion = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
    myProjectTarget = projectTarget;
    if (new IsWatchFeatureRequiredCompat(facet).get()) {
      myRequiredHardwareFeatures = EnumSet.of(IDevice.HardwareFeature.WATCH);
    } else {
      myRequiredHardwareFeatures = EnumSet.noneOf(IDevice.HardwareFeature.class);
    }

    myDeviceTable = new JBTable();
    myPanel = ScrollPaneFactory.createScrollPane(myDeviceTable);
    myPanel.setPreferredSize(new Dimension(450, 220));

    myDeviceTable.setModel(new MyDeviceTableModel(EMPTY_DEVICE_ARRAY));
    myDeviceTable.setSelectionMode(
        multipleSelection
            ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
            : ListSelectionModel.SINGLE_SELECTION);
    myDeviceTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (myProcessSelectionFlag) {
                  hadUserInteraction = true;
                  fireSelectedDevicesChanged();
                }
              }
            });
    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent e) {
        if (myDeviceTable.isEnabled() && okAction.isEnabled()) {
          okAction.actionPerformed(null);
          return true;
        }
        return false;
      }
    }.installOn(myDeviceTable);

    myDeviceTable.setDefaultRenderer(LaunchCompatibility.class, new LaunchCompatibilityRenderer());
    myDeviceTable.setDefaultRenderer(
        IDevice.class, new DeviceRenderer.DeviceNameRenderer(facet.getAvdManagerSilently()));
    myDeviceTable.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && okAction.isEnabled()) {
              okAction.actionPerformed(null);
            }
          }
        });

    setColumnWidth(
        myDeviceTable, DEVICE_NAME_COLUMN_INDEX, "Samsung Galaxy Nexus Android 4.1 (API 17)");
    setColumnWidth(myDeviceTable, SERIAL_COLUMN_INDEX, "0000-0000-00000");
    setColumnWidth(myDeviceTable, DEVICE_STATE_COLUMN_INDEX, "offline");
    setColumnWidth(myDeviceTable, COMPATIBILITY_COLUMN_INDEX, "yes");

    // Do not recreate columns on every model update - this should help maintain the column sizes
    // set above
    myDeviceTable.setAutoCreateColumnsFromModel(false);

    // Allow sorting by columns (in lexicographic order)
    myDeviceTable.setAutoCreateRowSorter(true);

    myRefreshingAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this);
    myBridge = AndroidSdkUtils.getDebugBridge(myFacet.getModule().getProject());
  }