Fixed feed ordering
This commit is contained in:
parent
d9aad12b82
commit
93d691dafd
5 changed files with 57 additions and 24 deletions
|
@ -75,7 +75,17 @@ public class Feed {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void addArticle(Article a){
|
||||
public boolean hasAricle(Article a){
|
||||
for (Article art:articleList) {
|
||||
if(a.getURL().equals(a.getURL()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addArticle(Article a)
|
||||
{
|
||||
if(!hasAricle(a))
|
||||
articleList.add(a);
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,11 @@ public class FeedData extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
public void setLocation(Feed f,int index){
|
||||
feeds.remove(f);
|
||||
feeds.add(index,f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FeedData{" +
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package eu.toldi.rss;
|
||||
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import javax.naming.ldap.SortKey;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
|
@ -17,7 +19,6 @@ import java.util.ArrayList;
|
|||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
//TODO: Hírcsatornák rendezése
|
||||
//TODO: Keresés cikkek között
|
||||
//TODO: Automatikus frissítés
|
||||
|
||||
|
@ -217,22 +218,18 @@ public class FeedFrame extends JFrame {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// Do not allow MOVE-action drops if a non-leaf node is
|
||||
// selected unless all of its children are also selected.
|
||||
int action = support.getDropAction();
|
||||
if (action == MOVE) {
|
||||
return haveCompleteNode(tree);
|
||||
}
|
||||
// Do not allow a non-leaf node to be copied to a level
|
||||
// which is less than its source level.
|
||||
|
||||
TreePath dest = dl.getPath();
|
||||
DefaultMutableTreeNode target =
|
||||
(DefaultMutableTreeNode) dest.getLastPathComponent();
|
||||
DefaultMutableTreeNode target = (DefaultMutableTreeNode) dest.getLastPathComponent();
|
||||
TreePath path = tree.getPathForRow(selRows[0]);
|
||||
DefaultMutableTreeNode firstNode =
|
||||
(DefaultMutableTreeNode) path.getLastPathComponent();
|
||||
if (firstNode.getChildCount() > 0 &&
|
||||
target.getLevel() < firstNode.getLevel()) {
|
||||
DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode) path.getLastPathComponent();
|
||||
if (firstNode.getChildCount() > 0 && target.getLevel() < firstNode.getLevel()) {
|
||||
return false;
|
||||
}
|
||||
if(target.isLeaf() && target.getLevel() > 1)
|
||||
return false;
|
||||
if (action == MOVE && !firstNode.isLeaf()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -320,7 +317,7 @@ public class FeedFrame extends JFrame {
|
|||
return COPY_OR_MOVE;
|
||||
}
|
||||
|
||||
public List<DefaultMutableTreeNode> getParents(DefaultMutableTreeNode[] nodes, TreePath[] paths) {
|
||||
private List<DefaultMutableTreeNode> getParents(DefaultMutableTreeNode[] nodes, TreePath[] paths) {
|
||||
ArrayList<DefaultMutableTreeNode> results = new ArrayList<DefaultMutableTreeNode>();
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
for (int j = 0; j < paths.length; j++) {
|
||||
|
@ -332,6 +329,15 @@ public class FeedFrame extends JFrame {
|
|||
return results;
|
||||
}
|
||||
|
||||
private int getChildIndex(DefaultMutableTreeNode parent, DefaultMutableTreeNode child){
|
||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
||||
System.out.println(parent.getChildAt(i));
|
||||
if(parent.getChildAt(i).toString().equals(child.toString()))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean importData(TransferHandler.TransferSupport support) {
|
||||
if (!canImport(support)) {
|
||||
return false;
|
||||
|
@ -366,9 +372,6 @@ public class FeedFrame extends JFrame {
|
|||
DefaultMutableTreeNode newParent = fg.getTreeNode();
|
||||
data.removeFeed((Feed) parent.getUserObject());
|
||||
model.insertNodeInto(newParent, (MutableTreeNode) parent.getParent(), parent.getParent().getChildCount());
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
fg.addFeed((Feed) nodes[i].getUserObject());
|
||||
}
|
||||
data.addFeed(fg);
|
||||
model.removeNodeFromParent(parent);
|
||||
parent = newParent;
|
||||
|
@ -385,13 +388,24 @@ public class FeedFrame extends JFrame {
|
|||
} else {
|
||||
data.removeFeed((Feed) nodes[i].getUserObject());
|
||||
}
|
||||
if(parent.isRoot()){
|
||||
data.addFeed((Feed) nodes[i].getUserObject());
|
||||
}else{
|
||||
FeedGroup fg = (FeedGroup) parent.getUserObject();
|
||||
fg.addFeed((Feed) nodes[i].getUserObject());
|
||||
}
|
||||
if(parents.get(i).getChildCount() == 1){
|
||||
model.removeNodeFromParent(parents.get(i));
|
||||
data.limitTo(null);
|
||||
data.removeFeed((Feed) parent.getUserObject());
|
||||
|
||||
data.removeFeed((FeedGroup) parents.get(i).getUserObject());
|
||||
}
|
||||
}
|
||||
if(parent.isRoot()){
|
||||
data.setLocation((Feed)nodes[i].getUserObject(),getChildIndex(parent,nodes[i]));
|
||||
}else{
|
||||
FeedGroup fg = (FeedGroup) parent.getUserObject();
|
||||
fg.setLocation((Feed)nodes[i].getUserObject(),getChildIndex(parent,nodes[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -88,5 +88,9 @@ public class FeedGroup extends Feed {
|
|||
articleList = different;
|
||||
}
|
||||
}
|
||||
public void setLocation(Feed f,int index){
|
||||
feedList.remove(f);
|
||||
feedList.add(index,f);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ public class FeedLoader {
|
|||
if(url == null) return null;
|
||||
}
|
||||
Feed feed = new Feed(new URL(url));
|
||||
System.out.println(articleList.size());
|
||||
for (int k = 0; k < articleList.size(); k++) {
|
||||
feed.addArticle(articleList.get(k));
|
||||
}
|
||||
|
@ -69,10 +68,10 @@ public class FeedLoader {
|
|||
NodeList feedGroupprops = feeds.item(i).getChildNodes();
|
||||
String name = null;
|
||||
FeedGroup fg = null;
|
||||
int feedCounter = 0;
|
||||
for (int j = 1; j < feedGroupprops.getLength(); j+=2) {
|
||||
Node node = feedGroupprops.item(j);
|
||||
String tagName = node.getNodeName();
|
||||
|
||||
switch (tagName){
|
||||
case "name":
|
||||
fg = new FeedGroup(node.getTextContent());
|
||||
|
@ -84,10 +83,11 @@ public class FeedLoader {
|
|||
Node f = feedList1.item(k);
|
||||
Feed feed = getFeed(f.getChildNodes());
|
||||
fg.addFeed(feed);
|
||||
feedCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fg != null)
|
||||
if(fg != null && feedCounter != 0)
|
||||
data.addFeed(fg);
|
||||
}else
|
||||
System.out.println(feeds.item(i).getNodeName());
|
||||
|
|
Reference in a new issue