/** Next that is driven by visibility. It continues to next not yet visible difference. */ private void onNextButton() { if (showingFileTable()) { currentIndex = fileTable.getSelectedIndex(); currentModelIndex = fileTable.getSelectedModelIndex(); } DiffController view = setups[currentModelIndex].getView(); int currentDifferenceIndex = view != null ? view.getDifferenceIndex() : -1; if (view != null) { int visibleDiffernce = view.getDifferenceIndex(); if (visibleDiffernce < view.getDifferenceCount() - 1) { currentDifferenceIndex = Math.max(currentDifferenceIndex, visibleDiffernce); } if (++currentDifferenceIndex >= view.getDifferenceCount()) { if (++currentIndex >= setups.length) { currentIndex--; } else { setDiffIndex(currentIndex, 0); } } else { view.setLocation( DiffController.DiffPane.Modified, DiffController.LocationType.DifferenceIndex, currentDifferenceIndex); } } else { if (++currentIndex >= setups.length) { currentIndex = 0; } setDiffIndex(currentIndex, 0); } refreshComponents(); }
private void updateSplitLocation() { if (dividerSet) { return; } JComponent parent = (JComponent) getParent(); Dimension dim = parent == null ? new Dimension() : parent.getSize(); if (dim.width <= 0 || dim.height <= 0) { SwingUtilities.invokeLater( new Runnable() { public void run() { updateSplitLocation(); } }); } dividerSet = true; JTable jt = fileTable.getTable(); int optimalLocation = jt.getPreferredSize().height + jt.getTableHeader().getPreferredSize().height; if (optimalLocation > dim.height / 3) { optimalLocation = dim.height / 3; } if (optimalLocation <= jt.getTableHeader().getPreferredSize().height) { optimalLocation = jt.getTableHeader().getPreferredSize().height * 3; } splitPane.setDividerLocation(optimalLocation); }
private void setupComponents() { fileTable = new DiffFileTable(this); splitPane.setTopComponent(fileTable.getComponent()); splitPane.setBottomComponent( new NoContentPanel(NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoContent"))); commitButton.addActionListener(this); commitButton.setToolTipText( NbBundle.getMessage(MultiDiffPanel.class, "MSG_CommitDiff_Tooltip", contextName)); updateButton.setToolTipText( NbBundle.getMessage(MultiDiffPanel.class, "MSG_UpdateDiff_Tooltip", contextName)); ButtonGroup grp = new ButtonGroup(); nextAction = new AbstractAction( null, new javax.swing.ImageIcon( getClass().getResource("/org/nbgit/resources/icons/diff-next.png"))) { // NOI18N { putValue( Action.SHORT_DESCRIPTION, java.util.ResourceBundle.getBundle("org/nbgit/ui/diff/Bundle") .getString("CTL_DiffPanel_Next_Tooltip")); } public void actionPerformed(ActionEvent e) { onNextButton(); } }; prevAction = new AbstractAction( null, new javax.swing.ImageIcon( getClass().getResource("/org/nbgit/resources/icons/diff-prev.png"))) { // NOI18N { putValue( Action.SHORT_DESCRIPTION, java.util.ResourceBundle.getBundle("org/nbgit/ui/diff/Bundle") .getString("CTL_DiffPanel_Prev_Tooltip")); } public void actionPerformed(ActionEvent e) { onPrevButton(); } }; nextButton.setAction(nextAction); prevButton.setAction(prevAction); }
/** * Construct diff component showing just one file. It hides All, Local, Remote toggles and file * chooser combo. */ public MultiDiffPanel(File file, String rev1, String rev2) { context = null; contextName = file.getName(); initComponents(); setupComponents(); fileTable.getComponent().setVisible(false); commitButton.setVisible(false); // mimics refreshSetups() setups = new Setup[] {new Setup(file, rev1, rev2)}; setDiffIndex(0, 0); dpt = new DiffPrepareTask(setups); prepareTask = RequestProcessor.getDefault().post(dpt); }
private void refreshSetups() { if (dpt != null) { prepareTask.cancel(); } File[] files; switch (currentType) { case Setup.DIFFTYPE_LOCAL: displayStatuses = StatusInfo.STATUS_LOCAL_CHANGE; break; case Setup.DIFFTYPE_REMOTE: displayStatuses = StatusInfo.STATUS_REMOTE_CHANGE; break; case Setup.DIFFTYPE_ALL: displayStatuses = StatusInfo.STATUS_LOCAL_CHANGE | StatusInfo.STATUS_REMOTE_CHANGE; break; default: throw new IllegalStateException("Unknown DIFF type:" + currentType); // NOI18N } files = GitUtils.getModifiedFiles(context, displayStatuses); setups = computeSetups(files); boolean propertyColumnVisible = false; for (Setup setup : setups) { if (setup.getPropertyName() != null) { propertyColumnVisible = true; break; } } fileTable.setColumns( propertyColumnVisible ? new String[] { DiffNode.COLUMN_NAME_NAME, DiffNode.COLUMN_NAME_PROPERTY, DiffNode.COLUMN_NAME_STATUS, DiffNode.COLUMN_NAME_LOCATION } : new String[] { DiffNode.COLUMN_NAME_NAME, DiffNode.COLUMN_NAME_STATUS, DiffNode.COLUMN_NAME_LOCATION }); fileTable.setTableModel(setupToNodes(setups)); if (setups.length == 0) { String noContentLabel; switch (currentType) { case Setup.DIFFTYPE_LOCAL: noContentLabel = NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoLocalChanges"); break; case Setup.DIFFTYPE_REMOTE: noContentLabel = NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoRemoteChanges"); break; case Setup.DIFFTYPE_ALL: noContentLabel = NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoAllChanges"); break; default: throw new IllegalStateException("Unknown DIFF type:" + currentType); // NOI18N } setups = null; fileTable.setTableModel(new Node[0]); fileTable.getComponent().setEnabled(false); fileTable.getComponent().setPreferredSize(null); Dimension dim = fileTable.getComponent().getPreferredSize(); fileTable.getComponent().setPreferredSize(new Dimension(dim.width + 1, dim.height)); diffView = null; diffView = new NoContentPanel(noContentLabel); setBottomComponent(); nextAction.setEnabled(false); prevAction.setEnabled(false); revalidate(); repaint(); } else { fileTable.getComponent().setEnabled(true); fileTable.getComponent().setPreferredSize(null); Dimension dim = fileTable.getComponent().getPreferredSize(); fileTable.getComponent().setPreferredSize(new Dimension(dim.width + 1, dim.height)); setDiffIndex(0, 0); dpt = new DiffPrepareTask(setups); prepareTask = RequestProcessor.getDefault().post(dpt); } }
private boolean showingFileTable() { return fileTable.getComponent().isVisible(); }
private void setDiffIndex(int idx, int location) { currentIndex = idx; DiffController view = null; if (currentIndex != -1) { currentModelIndex = showingFileTable() ? fileTable.getModelIndex(currentIndex) : 0; view = setups[currentModelIndex].getView(); // enable Select in .. action TopComponent tc = (TopComponent) getClientProperty(TopComponent.class); if (tc != null) { Node node = Node.EMPTY; File baseFile = setups[currentModelIndex].getBaseFile(); if (baseFile != null) { FileObject fo = FileUtil.toFileObject(baseFile); if (fo != null) { node = new AbstractNode(Children.LEAF, Lookups.singleton(fo)); } } tc.setActivatedNodes(new Node[] {node}); } diffView = null; boolean focus = false; if (view != null) { if (showingFileTable()) { fileTableSetSelectedIndexContext = true; fileTable.setSelectedIndex(currentIndex); fileTableSetSelectedIndexContext = false; } diffView = view.getJComponent(); diffView.getActionMap().put("jumpNext", nextAction); // NOI18N diffView.getActionMap().put("jumpPrev", prevAction); // NOI18N setBottomComponent(); if (location == -1) { location = view.getDifferenceCount() - 1; } if (location >= 0 && location < view.getDifferenceCount()) { view.setLocation( DiffController.DiffPane.Modified, DiffController.LocationType.DifferenceIndex, location); } Component toc = WindowManager.getDefault().getRegistry().getActivated(); if (SwingUtilities.isDescendingFrom(this, toc)) { // focus = true; } } else { diffView = new NoContentPanel( NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoContent")); } } else { currentModelIndex = -1; diffView = new NoContentPanel( NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoFileSelected")); setBottomComponent(); } delegatingUndoRedo.setDiffView(diffView); refreshComponents(); // if (focus) { // diffView.requestFocusInWindow(); // } }