Search in sources :

Example 6 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class RpcUtils method getBranchFeeds.

/**
	 * Retrieves a list of available branch feeds in the Gitblit server.
	 *
	 * @param serverUrl
	 * @param account
	 * @param password
	 * @return
	 * @throws IOException
	 */
public static List<FeedModel> getBranchFeeds(String serverUrl, String account, char[] password) throws IOException {
    List<FeedModel> feeds = new ArrayList<FeedModel>();
    Map<String, Collection<String>> allBranches = getBranches(serverUrl, account, password);
    for (Map.Entry<String, Collection<String>> entry : allBranches.entrySet()) {
        for (String branch : entry.getValue()) {
            FeedModel feed = new FeedModel();
            feed.repository = entry.getKey();
            feed.branch = branch;
            feeds.add(feed);
        }
    }
    return feeds;
}
Also used : FeedModel(com.gitblit.models.FeedModel) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Map(java.util.Map)

Example 7 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class SubscriptionsDialog method initialize.

private void initialize() {
    NameRenderer nameRenderer = new NameRenderer();
    model = new FeedsTableModel(feeds);
    feedsTable = Utils.newTable(model, Utils.DATE_FORMAT);
    feedsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            int viewRow = feedsTable.getSelectedRow();
            if (viewRow == -1) {
                return;
            }
            int modelRow = feedsTable.convertRowIndexToModel(viewRow);
            FeedModel feed = model.get(modelRow);
            feed.subscribed = !feed.subscribed;
            model.fireTableDataChanged();
        }
    });
    String repository = feedsTable.getColumnName(FeedsTableModel.Columns.Repository.ordinal());
    feedsTable.getColumn(repository).setCellRenderer(nameRenderer);
    String branch = feedsTable.getColumnName(FeedsTableModel.Columns.Branch.ordinal());
    feedsTable.getColumn(branch).setCellRenderer(new BranchRenderer());
    String subscribed = feedsTable.getColumnName(FeedsTableModel.Columns.Subscribed.ordinal());
    feedsTable.getColumn(subscribed).setCellRenderer(new BooleanCellRenderer());
    feedsTable.getColumn(subscribed).setMinWidth(30);
    feedsTable.getColumn(subscribed).setMaxWidth(30);
    Utils.packColumns(feedsTable, 5);
    final JButton cancel = new JButton(Translation.get("gb.cancel"));
    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            setVisible(false);
        }
    });
    final JButton save = new JButton(Translation.get("gb.save"));
    save.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            save();
        }
    });
    feedsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
        }
    });
    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    controls.add(cancel);
    controls.add(save);
    final Insets insets = new Insets(5, 5, 5, 5);
    JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return insets;
        }
    };
    centerPanel.add(new HeaderPanel(Translation.get("gb.subscribe") + "...", "feed_16x16.png"), BorderLayout.NORTH);
    centerPanel.add(new JScrollPane(feedsTable), BorderLayout.CENTER);
    centerPanel.add(controls, BorderLayout.SOUTH);
    getContentPane().setLayout(new BorderLayout(5, 5));
    getContentPane().add(centerPanel, BorderLayout.CENTER);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) ListSelectionListener(javax.swing.event.ListSelectionListener) FeedModel(com.gitblit.models.FeedModel) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Example 8 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class GitblitManager method loadFeedCache.

private void loadFeedCache(GitblitRegistration reg) {
    File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.toString()) + ".cache");
    if (!feedCache.exists()) {
        // no cache for this registration
        return;
    }
    try {
        BufferedReader reader = new BufferedReader(new FileReader(feedCache));
        Map<String, Date> cache = new HashMap<String, Date>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        String line = null;
        while ((line = reader.readLine()) != null) {
            String[] kvp = line.split("=");
            cache.put(kvp[0], df.parse(kvp[1]));
        }
        reader.close();
        for (FeedModel feed : reg.feeds) {
            String name = feed.toString();
            if (cache.containsKey(name)) {
                feed.currentRefreshDate = cache.get(name);
            }
        }
    } catch (Exception e) {
        Utils.showException(GitblitManager.this, e);
    }
}
Also used : FeedModel(com.gitblit.models.FeedModel) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ForbiddenException(com.gitblit.GitBlitException.ForbiddenException)

Example 9 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class GitblitManager method writeFeedCache.

private void writeFeedCache(GitblitRegistration reg) {
    try {
        File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.toString()) + ".cache");
        FileWriter writer = new FileWriter(feedCache);
        for (FeedModel feed : reg.feeds) {
            writer.append(MessageFormat.format("{0}={1,date,yyyy-MM-dd'T'HH:mm:ss}\n", feed.toString(), feed.currentRefreshDate));
        }
        writer.close();
    } catch (Exception e) {
        Utils.showException(GitblitManager.this, e);
    }
}
Also used : FeedModel(com.gitblit.models.FeedModel) FileWriter(java.io.FileWriter) File(java.io.File) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ForbiddenException(com.gitblit.GitBlitException.ForbiddenException)

Example 10 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class FeedsTableModel method getValueAt.

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    FeedModel model = list.get(rowIndex);
    Columns col = Columns.values()[columnIndex];
    switch(col) {
        case Repository:
            return model.repository;
        case Branch:
            return model.branch;
        case Subscribed:
            return model.subscribed;
    }
    return null;
}
Also used : FeedModel(com.gitblit.models.FeedModel)

Aggregations

FeedModel (com.gitblit.models.FeedModel)11 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ForbiddenException (com.gitblit.GitBlitException.ForbiddenException)2 File (java.io.File)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1