diff --git a/icons/book.gif b/icons/book.gif new file mode 100644 index 0000000000000000000000000000000000000000..f6c03e121013f1972d23b73d40ab04ecbf8fe518 Binary files /dev/null and b/icons/book.gif differ diff --git a/icons/gameboard.gif b/icons/gameboard.gif new file mode 100644 index 0000000000000000000000000000000000000000..6ed371657160f4ea90f6ee3089b675a4a2881974 Binary files /dev/null and b/icons/gameboard.gif differ diff --git a/icons/meBook.gif b/icons/meBook.gif new file mode 100644 index 0000000000000000000000000000000000000000..a8e13c27542fb5bd9c8e61c22749c6d2a5442197 Binary files /dev/null and b/icons/meBook.gif differ diff --git a/icons/movingBox.gif b/icons/movingBox.gif new file mode 100644 index 0000000000000000000000000000000000000000..04c059303a10f2907195e329c4b8a52118b91345 Binary files /dev/null and b/icons/movingBox.gif differ diff --git a/icons/newBook.gif b/icons/newBook.gif new file mode 100644 index 0000000000000000000000000000000000000000..9a3b1ad6329f0083d6a4008db8e459248473a390 Binary files /dev/null and b/icons/newBook.gif differ diff --git a/icons/remove.gif b/icons/remove.gif new file mode 100644 index 0000000000000000000000000000000000000000..6f647666d3246d97b6e5471736ad102ab4fe2d9e Binary files /dev/null and b/icons/remove.gif differ diff --git a/lib/._RXTXcomm.jar7894315756722313710.tmp b/lib/._RXTXcomm.jar7894315756722313710.tmp new file mode 100644 index 0000000000000000000000000000000000000000..e1e75034a3841c4382dc220a3ebc75a5dcc92113 Binary files /dev/null and b/lib/._RXTXcomm.jar7894315756722313710.tmp differ diff --git a/src/cbg/article/model/BoardGame.java b/src/cbg/article/model/BoardGame.java new file mode 100644 index 0000000000000000000000000000000000000000..c6b50400c1378825bcf6f7365aab6bb8bc2abce0 --- /dev/null +++ b/src/cbg/article/model/BoardGame.java @@ -0,0 +1,20 @@ +package cbg.article.model; +public class BoardGame extends Model { + + public BoardGame(String title, String authorGivenName, String authorSirName) { + super(title, authorGivenName, authorSirName); + } + + + + + + + /* + * @see Model#accept(ModelVisitorI, Object) + */ + public void accept(IModelVisitor visitor, Object passAlongArgument) { + visitor.visitBoardgame(this, passAlongArgument); + } + +} diff --git a/src/cbg/article/model/Book.java b/src/cbg/article/model/Book.java new file mode 100644 index 0000000000000000000000000000000000000000..0b66a40858d0eb2ed0bbb62355588dce4371c064 --- /dev/null +++ b/src/cbg/article/model/Book.java @@ -0,0 +1,78 @@ +package cbg.article.model; + +import java.util.ArrayList; +import java.util.List; + +public class Book extends Model { + protected static List newBooks = buildBookList(); + protected static int cursor = 0; + + public Book(String title, String authorGivenName, String authorSirName) { + super(title, authorGivenName, authorSirName); + } + + + + + public static Book newBook() { + Book newBook = (Book)newBooks.get(cursor); + cursor = ((cursor + 1) % newBooks.size()); + return newBook; + } + + + protected static List buildBookList() { + newBooks = new ArrayList(); + Book[] books = new Book[] { + new Book("Advanced Java: Idioms, Pitfalls, Styles and Programming Tips", "Chris", "Laffra"), + new Book("Programming Ruby: A Pragmatic Programmer's Guide", "David", "Thomas"), + new Book("The Pragmatic Programmer", "Andrew", "Hunt"), + new Book("Java Virtual Machine", "Jon", "Meyer"), + new Book("Using Netscape IFC", "Arun", "Rao"), + new Book("Smalltalk-80", "Adele", "Goldberg"), + new Book("Cold Mountain", "Charles", "Frazier"), + new Book("Software Development Using Eiffel", "Richard", "Wiener"), + new Book("Winter's Heart", "Robert", "Jordan"), + new Book("Ender's Game", "Orson Scott", "Card"), + new Book("Castle", "David", "Macaulay"), + new Book("Cranberry Thanksgiving", "Wende", "Devlin"), + new Book("The Biggest Bear", "Lynd", "Ward"), + new Book("The Boxcar Children", "Gertrude Chandler", "Warner"), + new Book("BASIC Fun with Adventure Games", "Susan Drake", "Lipscomb"), + new Book("Bridge to Terabithia", "Katherine", "Paterson"), + new Book("One Renegade Cell", "Robert A.", "Weinberg"), + new Book("Programming Internet Mail", "David", "Wood"), + new Book("Refactoring", "Martin", "Fowler"), + new Book("Effective Java", "Joshua", "Bloch"), + new Book("Cutting-Edge Java Game Programming", "Neil", "Bartlett"), + new Book("The C Programming Language", "Brian W.", "Kernighan"), + new Book("The Design and Analysis of Spatial Data Structures", "Hanan", "Samet"), + new Book("Object-Oriented Programming", "Brad", "Cox"), + new Book("Python Essential Reference", "David M.", "Beazley"), + new Book("The Practical SQL Handbook", "Judith S.", "Bowman"), + new Book("The Design Patterns Smalltalk Companion", "Sherman R.", "Alpert"), + new Book("Design Patterns", "Erich", "Gamma"), + new Book("Gig", "John", "Bowe"), + new Book("You Can't Be Too Careful", "David Pryce", "Jones"), + new Book("Go for Beginners", "Kaoru", "Iwamoto"), + new Book("How to Read a Book", "Mortimer J.", "Adler"), + new Book("The Message", "Eugene H.", "Peterson"), + new Book("Beyond Bumper Sticker Ethics", "Steve", "Wilkens"), + new Book("Life Together", "Dietrich", "Bonhoeffer"), + new Book("Java 2 Exam Cram", "William", "Brogden") + }; + + for (int i = 0; i < books.length; i++) { + newBooks.add(books[i]); + + } + return newBooks; + } + /* + * @see Model#accept(ModelVisitorI, Object) + */ + public void accept(IModelVisitor visitor, Object passAlongArgument) { + visitor.visitBook(this, passAlongArgument); + } + +} diff --git a/src/cbg/article/model/DeltaEvent.java b/src/cbg/article/model/DeltaEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..c7943e0f6eb3e83cd2b972c611584c0bbb6e28cf --- /dev/null +++ b/src/cbg/article/model/DeltaEvent.java @@ -0,0 +1,13 @@ +package cbg.article.model; + +public class DeltaEvent { + protected Object actedUpon; + + public DeltaEvent(Object receiver) { + actedUpon = receiver; + } + + public Object receiver() { + return actedUpon; + } +} diff --git a/src/cbg/article/model/IDeltaListener.java b/src/cbg/article/model/IDeltaListener.java new file mode 100644 index 0000000000000000000000000000000000000000..b34ef74785daea38e32e697d12013b1b3d8ac122 --- /dev/null +++ b/src/cbg/article/model/IDeltaListener.java @@ -0,0 +1,5 @@ +package cbg.article.model; +public interface IDeltaListener { + public void add(DeltaEvent event); + public void remove(DeltaEvent event); +} diff --git a/src/cbg/article/model/IModelVisitor.java b/src/cbg/article/model/IModelVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..da8ba88ab8d2850679a7bf0abab52d5e8bfdb27d --- /dev/null +++ b/src/cbg/article/model/IModelVisitor.java @@ -0,0 +1,9 @@ +package cbg.article.model; + + + +public interface IModelVisitor { + public void visitMovingBox(MovingBox box, Object passAlongArgument); + public void visitBook(Book book, Object passAlongArgument); + public void visitBoardgame(BoardGame boardgame, Object passAlongArgument); +} diff --git a/src/cbg/article/model/Model.java b/src/cbg/article/model/Model.java new file mode 100644 index 0000000000000000000000000000000000000000..c899fec5fc56af83ceeccd3097a090e3adb3fc70 --- /dev/null +++ b/src/cbg/article/model/Model.java @@ -0,0 +1,65 @@ +package cbg.article.model; +public abstract class Model { + protected MovingBox parent; + protected String name; + protected String authorGivenName, authorSirName; + protected IDeltaListener listener = NullDeltaListener.getSoleInstance(); + + protected void fireAdd(Object added) { + listener.add(new DeltaEvent(added)); + } + + protected void fireRemove(Object removed) { + listener.remove(new DeltaEvent(removed)); + } + + public void setName(String name) { + this.name = name; + } + + public MovingBox getParent() { + return parent; + } + + /* The receiver should visit the toVisit object and + * pass along the argument. */ + public abstract void accept(IModelVisitor visitor, Object passAlongArgument); + + public String getName() { + return name; + } + + public void addListener(IDeltaListener listener) { + this.listener = listener; + } + + public Model(String title, String authorGivenName, String authorSirName) { + this.name = title; + this.authorGivenName = authorGivenName; + this.authorSirName = authorSirName; + } + + public Model() { + } + + public void removeListener(IDeltaListener listener) { + if(this.listener.equals(listener)) { + this.listener = NullDeltaListener.getSoleInstance(); + } + } + + public String authorGivenName() { + return authorGivenName; + } + + + public String authorSirName() { + return authorSirName; + } + + public String getTitle() { + return name; + } + + +} diff --git a/src/cbg/article/model/MovingBox.java b/src/cbg/article/model/MovingBox.java new file mode 100644 index 0000000000000000000000000000000000000000..fcd08dcbe1e22b372ff3ab2241907fd7c363ec73 --- /dev/null +++ b/src/cbg/article/model/MovingBox.java @@ -0,0 +1,152 @@ +package cbg.article.model; + +import java.util.ArrayList; +import java.util.List; + +public class MovingBox extends Model { + protected List boxes; + protected List games; + protected List books; + + private static IModelVisitor adder = new Adder(); + private static IModelVisitor remover = new Remover(); + + public MovingBox() { + boxes = new ArrayList(); + games = new ArrayList(); + books = new ArrayList(); + } + + private static class Adder implements IModelVisitor { + + /* + * @see ModelVisitorI#visitBoardgame(BoardGame) + */ + + /* + * @see ModelVisitorI#visitBook(MovingBox) + */ + + /* + * @see ModelVisitorI#visitMovingBox(MovingBox) + */ + + /* + * @see ModelVisitorI#visitBoardgame(BoardGame, Object) + */ + public void visitBoardgame(BoardGame boardgame, Object argument) { + ((MovingBox) argument).addBoardGame(boardgame); + } + + /* + * @see ModelVisitorI#visitBook(MovingBox, Object) + */ + public void visitBook(Book book, Object argument) { + ((MovingBox) argument).addBook(book); + } + + /* + * @see ModelVisitorI#visitMovingBox(MovingBox, Object) + */ + public void visitMovingBox(MovingBox box, Object argument) { + ((MovingBox) argument).addBox(box); + } + + } + + private static class Remover implements IModelVisitor { + public void visitBoardgame(BoardGame boardgame, Object argument) { + ((MovingBox) argument).removeBoardGame(boardgame); + } + + /* + * @see ModelVisitorI#visitBook(MovingBox, Object) + */ + public void visitBook(Book book, Object argument) { + ((MovingBox) argument).removeBook(book); + } + + /* + * @see ModelVisitorI#visitMovingBox(MovingBox, Object) + */ + public void visitMovingBox(MovingBox box, Object argument) { + ((MovingBox) argument).removeBox(box); + box.addListener(NullDeltaListener.getSoleInstance()); + } + + } + + public MovingBox(String name) { + this(); + this.name = name; + } + + public List getBoxes() { + return boxes; + } + + protected void addBox(MovingBox box) { + boxes.add(box); + box.parent = this; + fireAdd(box); + } + + protected void addBook(Book book) { + books.add(book); + book.parent = this; + fireAdd(book); + } + + protected void addBoardGame(BoardGame game) { + games.add(game); + game.parent = this; + fireAdd(game); + } + + public List getBooks() { + return books; + } + + public void remove(Model toRemove) { + toRemove.accept(remover, this); + } + + protected void removeBoardGame(BoardGame boardGame) { + games.remove(boardGame); + boardGame.addListener(NullDeltaListener.getSoleInstance()); + fireRemove(boardGame); + } + + protected void removeBook(Book book) { + books.remove(book); + book.addListener(NullDeltaListener.getSoleInstance()); + fireRemove(book); + } + + protected void removeBox(MovingBox box) { + boxes.remove(box); + box.addListener(NullDeltaListener.getSoleInstance()); + fireRemove(box); + } + + public void add(Model toAdd) { + toAdd.accept(adder, this); + } + + public List getGames() { + return games; + } + + /** Answer the total number of items the + * receiver contains. */ + public int size() { + return getBooks().size() + getBoxes().size() + getGames().size(); + } + /* + * @see Model#accept(ModelVisitorI, Object) + */ + public void accept(IModelVisitor visitor, Object passAlongArgument) { + visitor.visitMovingBox(this, passAlongArgument); + } + +} diff --git a/src/cbg/article/model/NullDeltaListener.java b/src/cbg/article/model/NullDeltaListener.java new file mode 100644 index 0000000000000000000000000000000000000000..e6fca56ddbf91178074c6b38ee5368d11a29d86b --- /dev/null +++ b/src/cbg/article/model/NullDeltaListener.java @@ -0,0 +1,18 @@ +package cbg.article.model; +public class NullDeltaListener implements IDeltaListener { + protected static NullDeltaListener soleInstance = new NullDeltaListener(); + public static NullDeltaListener getSoleInstance() { + return soleInstance; + } + + /* + * @see IDeltaListener#add(DeltaEvent) + */ + public void add(DeltaEvent event) {} + + /* + * @see IDeltaListener#remove(DeltaEvent) + */ + public void remove(DeltaEvent event) {} + +} diff --git a/src/cbg/article/treeviewer/ui/BoardgameFilter.java b/src/cbg/article/treeviewer/ui/BoardgameFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..1f0fba59beedc7904bbcbfa9f6be77849d3af1e6 --- /dev/null +++ b/src/cbg/article/treeviewer/ui/BoardgameFilter.java @@ -0,0 +1,18 @@ +package cbg.article.treeviewer.ui; + +import cbg.article.model.BoardGame; +import cbg.article.model.MovingBox; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +public class BoardgameFilter extends ViewerFilter { + + /* + * @see ViewerFilter#select(Viewer, Object, Object) + */ + public boolean select(Viewer viewer, Object parentElement, Object element) { + return element instanceof BoardGame || element instanceof MovingBox; + } + +} diff --git a/src/cbg/article/treeviewer/ui/BookBoxBoardSorter.java b/src/cbg/article/treeviewer/ui/BookBoxBoardSorter.java new file mode 100644 index 0000000000000000000000000000000000000000..1c974330d4c3adc3126aa40d79a51070ff7a8463 --- /dev/null +++ b/src/cbg/article/treeviewer/ui/BookBoxBoardSorter.java @@ -0,0 +1,21 @@ +package cbg.article.treeviewer.ui; + +import cbg.article.model.Book; +import cbg.article.model.MovingBox; + +import org.eclipse.jface.viewers.ViewerSorter; + +public class BookBoxBoardSorter extends ViewerSorter { + + /* + * @see ViewerSorter#category(Object) + */ + /** Orders the items in such a way that books appear + * before moving boxes, which appear before board games. */ + public int category(Object element) { + if(element instanceof Book) return 1; + if(element instanceof MovingBox) return 2; + return 3; + } + +} diff --git a/src/cbg/article/treeviewer/ui/MovingBoxContentProvider.java b/src/cbg/article/treeviewer/ui/MovingBoxContentProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..dd386be7970706c6d79708ec7ede834510b0d5fc --- /dev/null +++ b/src/cbg/article/treeviewer/ui/MovingBoxContentProvider.java @@ -0,0 +1,138 @@ +package cbg.article.treeviewer.ui; + +import java.util.Iterator; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; + +import cbg.article.model.Book; +import cbg.article.model.DeltaEvent; +import cbg.article.model.IDeltaListener; +import cbg.article.model.Model; +import cbg.article.model.IModelVisitor; +import cbg.article.model.MovingBox; + +public class MovingBoxContentProvider implements ITreeContentProvider, IDeltaListener { + private static Object[] EMPTY_ARRAY = new Object[0]; + protected TreeViewer viewer; + + /* + * @see IContentProvider#dispose() + */ + public void dispose() {} + + /* + * @see IContentProvider#inputChanged(Viewer, Object, Object) + */ + /** + * Notifies this content provider that the given viewer's input + * has been switched to a different element. + *

+ * A typical use for this method is registering the content provider as a listener + * to changes on the new input (using model-specific means), and deregistering the viewer + * from the old input. In response to these change notifications, the content provider + * propagates the changes to the viewer. + *

+ * + * @param viewer the viewer + * @param oldInput the old input element, or null if the viewer + * did not previously have an input + * @param newInput the new input element, or null if the viewer + * does not have an input + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + this.viewer = (TreeViewer)viewer; + if(oldInput != null) { + removeListenerFrom((MovingBox)oldInput); + } + if(newInput != null) { + addListenerTo((MovingBox)newInput); + } + } + + /** Because the domain model does not have a richer + * listener model, recursively remove this listener + * from each child box of the given box. */ + protected void removeListenerFrom(MovingBox box) { + box.removeListener(this); + for (Iterator iterator = box.getBoxes().iterator(); iterator.hasNext();) { + MovingBox aBox = (MovingBox) iterator.next(); + removeListenerFrom(aBox); + } + } + + /** Because the domain model does not have a richer + * listener model, recursively add this listener + * to each child box of the given box. */ + protected void addListenerTo(MovingBox box) { + box.addListener(this); + for (Iterator iterator = box.getBoxes().iterator(); iterator.hasNext();) { + MovingBox aBox = (MovingBox) iterator.next(); + addListenerTo(aBox); + } + } + + + + + /* + * @see ITreeContentProvider#getChildren(Object) + */ + public Object[] getChildren(Object parentElement) { + if(parentElement instanceof MovingBox) { + MovingBox box = (MovingBox)parentElement; + return concat(box.getBoxes().toArray(), + box.getBooks().toArray(), box.getGames().toArray()); + } + return EMPTY_ARRAY; + } + + protected Object[] concat(Object[] object, Object[] more, Object[] more2) { + Object[] both = new Object[object.length + more.length + more2.length]; + System.arraycopy(object, 0, both, 0, object.length); + System.arraycopy(more, 0, both, object.length, more.length); + System.arraycopy(more2, 0, both, object.length + more.length, more2.length); + return both; + } + + /* + * @see ITreeContentProvider#getParent(Object) + */ + public Object getParent(Object element) { + if(element instanceof Model) { + return ((Model)element).getParent(); + } + return null; + } + + /* + * @see ITreeContentProvider#hasChildren(Object) + */ + public boolean hasChildren(Object element) { + return getChildren(element).length > 0; + } + + /* + * @see IStructuredContentProvider#getElements(Object) + */ + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + /* + * @see IDeltaListener#add(DeltaEvent) + */ + public void add(DeltaEvent event) { + Object movingBox = ((Model)event.receiver()).getParent(); + viewer.refresh(movingBox, false); + } + + /* + * @see IDeltaListener#remove(DeltaEvent) + */ + public void remove(DeltaEvent event) { + add(event); + } + +} diff --git a/src/cbg/article/treeviewer/ui/MovingBoxLabelProvider.java b/src/cbg/article/treeviewer/ui/MovingBoxLabelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..a667ffba6a0a7324714a645e8d83a88f2ba8f27e --- /dev/null +++ b/src/cbg/article/treeviewer/ui/MovingBoxLabelProvider.java @@ -0,0 +1,77 @@ +package cbg.article.treeviewer.ui; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cbg.article.model.BoardGame; +import cbg.article.model.Book; +import cbg.article.model.MovingBox; +import educationschedule.Activator; + +public class MovingBoxLabelProvider extends LabelProvider { + private Map imageCache = new HashMap(11); + + /* + * @see ILabelProvider#getImage(Object) + */ + public Image getImage(Object element) { + ImageDescriptor descriptor = null; + if (element instanceof MovingBox) { + descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/movingBox.gif"); + } else if (element instanceof Book) { + descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/book.gif"); + } else if (element instanceof BoardGame) { + descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/gameboard.gif"); + } else { + throw unknownElement(element); + } + + //obtain the cached image corresponding to the descriptor + Image image = (Image)imageCache.get(descriptor); + if (image == null) { + image = descriptor.createImage(); + imageCache.put(descriptor, image); + } + return image; + } + + /* + * @see ILabelProvider#getText(Object) + */ + public String getText(Object element) { + if (element instanceof MovingBox) { + if(((MovingBox)element).getName() == null) { + return "Box"; + } else { + return ((MovingBox)element).getName(); + } + } else if (element instanceof Book) { + return ((Book)element).getTitle(); + } else if (element instanceof BoardGame) { + return ((BoardGame)element).getTitle(); + } else { + throw unknownElement(element); + } + } + + public void dispose() { + for (Iterator i = imageCache.values().iterator(); i.hasNext();) { + ((Image) i.next()).dispose(); + } + imageCache.clear(); + } + + protected RuntimeException unknownElement(Object element) { + return new RuntimeException("Unknown type of element in tree of type " + element.getClass().getName()); + } + +} diff --git a/src/cbg/article/treeviewer/ui/MovingBoxView.java b/src/cbg/article/treeviewer/ui/MovingBoxView.java new file mode 100644 index 0000000000000000000000000000000000000000..c1b9e2fbb64840907119681522fdb5f3efdcb755 --- /dev/null +++ b/src/cbg/article/treeviewer/ui/MovingBoxView.java @@ -0,0 +1,337 @@ +package cbg.article.treeviewer.ui; + +import java.util.Iterator; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.part.ViewPart; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cbg.article.model.BoardGame; +import cbg.article.model.Book; +import cbg.article.model.Model; +import cbg.article.model.MovingBox; +import educationschedule.Activator; + +/** + * Insert the type's description here. + * @see ViewPart + */ +public class MovingBoxView extends ViewPart { + public static final String ID = "cbg.article.treeviewer.ui.MovingBoxView"; + protected TreeViewer treeViewer; + protected Text text; + protected MovingBoxLabelProvider labelProvider; + + protected Action onlyBoardGamesAction, atLeatThreeItems; + protected Action booksBoxesGamesAction, noArticleAction; + protected Action addBookAction, removeAction; + protected ViewerFilter onlyBoardGamesFilter, atLeastThreeFilter; + protected ViewerSorter booksBoxesGamesSorter, noArticleSorter; + + protected MovingBox root; + + /** + * The constructor. + */ + public MovingBoxView() { + } + + /* + * @see IWorkbenchPart#createPartControl(Composite) + */ + public void createPartControl(Composite parent) { + /* Create a grid layout object so the text and treeviewer + * are layed out the way I want. */ + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.verticalSpacing = 2; + layout.marginWidth = 0; + layout.marginHeight = 2; + parent.setLayout(layout); + + /* Create a "label" to display information in. I'm + * using a text field instead of a lable so you can + * copy-paste out of it. */ + text = new Text(parent, SWT.READ_ONLY | SWT.SINGLE | SWT.BORDER); + // layout the text field above the treeviewer + GridData layoutData = new GridData(); + layoutData.grabExcessHorizontalSpace = true; + layoutData.horizontalAlignment = GridData.FILL; + text.setLayoutData(layoutData); + + // Create the tree viewer as a child of the composite parent + treeViewer = new TreeViewer(parent); + treeViewer.setContentProvider(new MovingBoxContentProvider()); + labelProvider = new MovingBoxLabelProvider(); + treeViewer.setLabelProvider(labelProvider); + + treeViewer.setUseHashlookup(true); + + // layout the tree viewer below the text field + layoutData = new GridData(); + layoutData.grabExcessHorizontalSpace = true; + layoutData.grabExcessVerticalSpace = true; + layoutData.horizontalAlignment = GridData.FILL; + layoutData.verticalAlignment = GridData.FILL; + treeViewer.getControl().setLayoutData(layoutData); + + // Create menu, toolbars, filters, sorters. + createFiltersAndSorters(); + createActions(); + createMenus(); + createToolbar(); + hookListeners(); + + treeViewer.setInput(getInitalInput()); + treeViewer.expandAll(); + } + + protected void createFiltersAndSorters() { + atLeastThreeFilter = new ThreeItemFilter(); + onlyBoardGamesFilter = new BoardgameFilter(); + booksBoxesGamesSorter = new BookBoxBoardSorter(); + noArticleSorter = new NoArticleSorter(); + } + + protected void hookListeners() { + treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + // if the selection is empty clear the label + if(event.getSelection().isEmpty()) { + text.setText(""); + return; + } + if(event.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection)event.getSelection(); + StringBuffer toShow = new StringBuffer(); + for (Iterator iterator = selection.iterator(); iterator.hasNext();) { + Object domain = (Model) iterator.next(); + String value = labelProvider.getText(domain); + toShow.append(value); + toShow.append(", "); + } + // remove the trailing comma space pair + if(toShow.length() > 0) { + toShow.setLength(toShow.length() - 2); + } + text.setText(toShow.toString()); + } + } + }); + } + + protected void createActions() { + onlyBoardGamesAction = new Action("Only Board Games") { + public void run() { + updateFilter(onlyBoardGamesAction); + } + }; + onlyBoardGamesAction.setChecked(false); + + atLeatThreeItems = new Action("Boxes With At Least Three Items") { + public void run() { + updateFilter(atLeatThreeItems); + } + }; + atLeatThreeItems.setChecked(false); + + booksBoxesGamesAction = new Action("Books, Boxes, Games") { + public void run() { + updateSorter(booksBoxesGamesAction); + } + }; + booksBoxesGamesAction.setChecked(false); + + noArticleAction = new Action("Ignoring Articles") { + public void run() { + updateSorter(noArticleAction); + } + }; + noArticleAction.setChecked(false); + + addBookAction = new Action("Add Book") { + public void run() { + addNewBook(); + } + }; + addBookAction.setToolTipText("Add a New Book"); + addBookAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/newBook.gif")); + + removeAction = new Action("Delete") { + public void run() { + removeSelected(); + } + }; + removeAction.setToolTipText("Delete"); + removeAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/remove.gif")); + } + + /** Add a new book to the selected moving box. + * If a moving box is not selected, use the selected + * obect's moving box. + * + * If nothing is selected add to the root. */ + protected void addNewBook() { + MovingBox receivingBox; + if (treeViewer.getSelection().isEmpty()) { + receivingBox = root; + } else { + IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); + Model selectedDomainObject = (Model) selection.getFirstElement(); + if (!(selectedDomainObject instanceof MovingBox)) { + receivingBox = selectedDomainObject.getParent(); + } else { + receivingBox = (MovingBox) selectedDomainObject; + } + } + receivingBox.add(Book.newBook()); + } + + /** Remove the selected domain object(s). + * If multiple objects are selected remove all of them. + * + * If nothing is selected do nothing. */ + protected void removeSelected() { + if (treeViewer.getSelection().isEmpty()) { + return; + } + IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); + /* Tell the tree to not redraw until we finish + * removing all the selected children. */ + treeViewer.getTree().setRedraw(false); + for (Iterator iterator = selection.iterator(); iterator.hasNext();) { + Model model = (Model) iterator.next(); + MovingBox parent = model.getParent(); + parent.remove(model); + } + treeViewer.getTree().setRedraw(true); + } + + protected void createMenus() { + IMenuManager rootMenuManager = getViewSite().getActionBars().getMenuManager(); + rootMenuManager.setRemoveAllWhenShown(true); + rootMenuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + fillMenu(mgr); + } + }); + fillMenu(rootMenuManager); + } + + + protected void fillMenu(IMenuManager rootMenuManager) { + IMenuManager filterSubmenu = new MenuManager("Filters"); + rootMenuManager.add(filterSubmenu); + filterSubmenu.add(onlyBoardGamesAction); + filterSubmenu.add(atLeatThreeItems); + + IMenuManager sortSubmenu = new MenuManager("Sort By"); + rootMenuManager.add(sortSubmenu); + sortSubmenu.add(booksBoxesGamesAction); + sortSubmenu.add(noArticleAction); + } + + + + protected void updateSorter(Action action) { + if(action == booksBoxesGamesAction) { + noArticleAction.setChecked(!booksBoxesGamesAction.isChecked()); + if(action.isChecked()) { + treeViewer.setSorter(booksBoxesGamesSorter); + } else { + treeViewer.setSorter(null); + } + } else if(action == noArticleAction) { + booksBoxesGamesAction.setChecked(!noArticleAction.isChecked()); + if(action.isChecked()) { + treeViewer.setSorter(noArticleSorter); + } else { + treeViewer.setSorter(null); + } + } + + } + + /* Multiple filters can be enabled at a time. */ + protected void updateFilter(Action action) { + if(action == atLeatThreeItems) { + if(action.isChecked()) { + treeViewer.addFilter(atLeastThreeFilter); + } else { + treeViewer.removeFilter(atLeastThreeFilter); + } + } else if(action == onlyBoardGamesAction) { + if(action.isChecked()) { + treeViewer.addFilter(onlyBoardGamesFilter); + } else { + treeViewer.removeFilter(onlyBoardGamesFilter); + } + } + } + + protected void createToolbar() { + IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager(); + toolbarManager.add(addBookAction); + toolbarManager.add(removeAction); + } + + + public MovingBox getInitalInput() { + root = new MovingBox(); + MovingBox someBooks = new MovingBox("Books"); + MovingBox games = new MovingBox("Games"); + MovingBox books = new MovingBox("More books"); + MovingBox games2 = new MovingBox("More games"); + + root.add(someBooks); + root.add(games); + root.add(new MovingBox()); + + someBooks.add(books); + games.add(games2); + + books.add(new Book("The Lord of the Rings", "J.R.R.", "Tolkien")); + books.add(new BoardGame("Taj Mahal", "Reiner", "Knizia")); + books.add(new Book("Cryptonomicon", "Neal", "Stephenson")); + books.add(new Book("Smalltalk, Objects, and Design", "Chamond", "Liu")); + books.add(new Book("A Game of Thrones", "George R. R.", " Martin")); + books.add(new Book("The Hacker Ethic", "Pekka", "Himanen")); + //books.add(new MovingBox()); + + books.add(new Book("The Code Book", "Simon", "Singh")); + books.add(new Book("The Chronicles of Narnia", "C. S.", "Lewis")); + books.add(new Book("The Screwtape Letters", "C. S.", "Lewis")); + books.add(new Book("Mere Christianity ", "C. S.", "Lewis")); + games.add(new BoardGame("Tigris & Euphrates", "Reiner", "Knizia")); + games.add(new BoardGame("La Citta", "Gerd", "Fenchel")); + games.add(new BoardGame("El Grande", "Wolfgang", "Kramer")); + games.add(new BoardGame("The Princes of Florence", "Richard", "Ulrich")); + games.add(new BoardGame("The Traders of Genoa", "Rudiger", "Dorn")); + games2.add(new BoardGame("Tikal", "M.", "Kiesling")); + games2.add(new BoardGame("Modern Art", "Reiner", "Knizia")); + return root; + } + + /* + * @see IWorkbenchPart#setFocus() + */ + public void setFocus() {} + +} diff --git a/src/cbg/article/treeviewer/ui/NoArticleSorter.java b/src/cbg/article/treeviewer/ui/NoArticleSorter.java new file mode 100644 index 0000000000000000000000000000000000000000..969e022fd44eba2985db9d49ca8e4b89e96d2922 --- /dev/null +++ b/src/cbg/article/treeviewer/ui/NoArticleSorter.java @@ -0,0 +1,52 @@ +package cbg.article.treeviewer.ui; + +import org.eclipse.jface.viewers.ContentViewer; +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; + +public class NoArticleSorter extends ViewerSorter { /* + * @see ViewerSorter#compare(Viewer, Object, Object) + */ + public int compare(Viewer viewer, Object e1, Object e2) { + int cat1 = category(e1); + int cat2 = category(e2); + if (cat1 != cat2) return cat1 - cat2; + String name1, name2; + if (viewer == null || !(viewer instanceof ContentViewer)) { + name1 = e1.toString(); + name2 = e2.toString(); + } else { + IBaseLabelProvider prov = ((ContentViewer)viewer).getLabelProvider(); + if (prov instanceof ILabelProvider) { + ILabelProvider lprov = (ILabelProvider)prov; + name1 = lprov.getText(e1); + name2 = lprov.getText(e2); + } else { + name1 = e1.toString(); + name2 = e2.toString(); + } + } + if(name1 == null) name1 = ""; + if(name2 == null) name2 = ""; + name1 = stripArticles(name1); + name2 = stripArticles(name2); + return collator.compare(name1, name2); + } + + protected String stripArticles(String name) { + String test = name.toLowerCase(); + if(test.startsWith("the ") && test.length() > 3) { + return name.substring(4); + } else if(test.startsWith("a ") && test.length() > 1) { + return name.substring(2); + } else if(test.startsWith("el ") && test.length() > 2) { + return name.substring(3); + } else if(test.startsWith("la ") && test.length() > 2) { + return name.substring(3); + } + return name; + } + +} diff --git a/src/cbg/article/treeviewer/ui/ThreeItemFilter.java b/src/cbg/article/treeviewer/ui/ThreeItemFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..26a7915c5052d9f4f1f32f6e303c195d1d7f7586 --- /dev/null +++ b/src/cbg/article/treeviewer/ui/ThreeItemFilter.java @@ -0,0 +1,18 @@ +package cbg.article.treeviewer.ui; + +import cbg.article.model.BoardGame; +import cbg.article.model.MovingBox; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +public class ThreeItemFilter extends ViewerFilter { + + /* + * @see ViewerFilter#select(Viewer, Object, Object) + */ + public boolean select(Viewer viewer, Object parentElement, Object element) { + return parentElement instanceof MovingBox && ((MovingBox)parentElement).size() >= 3; + } + +} diff --git a/src/cn/edu/hit/education/action/AddCollegeAction.java b/src/cn/edu/hit/education/action/AddCollegeAction.java index b44db96166e4cfae298263344201a67540263b8a..ccdadd756d4712aa7abd342ff96eb687f1cf098f 100644 --- a/src/cn/edu/hit/education/action/AddCollegeAction.java +++ b/src/cn/edu/hit/education/action/AddCollegeAction.java @@ -39,7 +39,7 @@ public class AddCollegeAction extends Action { college.setUniversityId(universityId); int count = collegeService.insert(college); if(count > 0){ - viewPart.refreshData(college); + viewPart.refreshNewData(college); } } super.run(); diff --git a/src/cn/edu/hit/education/action/AddSpecialtyAction.java b/src/cn/edu/hit/education/action/AddSpecialtyAction.java index 89c8a9a18db6a2f151cde7ff81398778fe49c779..e5ebf21d8d496113a1132611039ab5275de53459 100644 --- a/src/cn/edu/hit/education/action/AddSpecialtyAction.java +++ b/src/cn/edu/hit/education/action/AddSpecialtyAction.java @@ -38,7 +38,7 @@ public class AddSpecialtyAction extends Action { specialty.setCollegeId(collegeId); int count = specialtyService.insert(specialty); if(count > 0){ - viewPart.refreshData(specialty); + viewPart.refreshNewData(specialty); } } super.run(); diff --git a/src/cn/edu/hit/education/action/AddUniversityAction.java b/src/cn/edu/hit/education/action/AddUniversityAction.java index 2b598428734000116dc59887ba53b3a8ef3d80ae..f0191d974d5b6820608b412894269dc3450fa5d4 100644 --- a/src/cn/edu/hit/education/action/AddUniversityAction.java +++ b/src/cn/edu/hit/education/action/AddUniversityAction.java @@ -33,7 +33,7 @@ public class AddUniversityAction extends Action { if(IDialogConstants.OK_ID == universityDialog.open()){ int count = universityService.insert(university); if(count > 0){ - viewPart.refreshData(university); + viewPart.refreshNewData(university); } } super.run(); diff --git a/src/cn/edu/hit/education/action/UpdateCollegeAction.java b/src/cn/edu/hit/education/action/UpdateCollegeAction.java new file mode 100644 index 0000000000000000000000000000000000000000..add081033b3b20293d72e5667c15ee78c0703e49 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateCollegeAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.CollegeDialog; +import cn.edu.hit.education.pojo.College; +import cn.edu.hit.education.service.ICollegeService; +import cn.edu.hit.education.view.DepartmentExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateCollegeAction extends Action { + private DepartmentExploreView viewPart; + ICollegeService collegeService = (ICollegeService)Application.applicationContext.getBean("collegeServiceImpl"); + private int collegeId; + + public UpdateCollegeAction(DepartmentExploreView viewPart,int collegeId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改学院"); + this.setText("修改学院"); + this.viewPart = viewPart; + this.collegeId = collegeId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + CollegeDialog collegeDialog = new CollegeDialog(parentShell); + College college = collegeService.queryCollegeByPrimaryKey(collegeId); + collegeDialog.setCollege(college); + if(IDialogConstants.OK_ID == collegeDialog.open()){ + int count = collegeService.update(college); + if(count > 0){ + viewPart.refreshUpdateData(college); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/UpdateSpecialtyAction.java b/src/cn/edu/hit/education/action/UpdateSpecialtyAction.java new file mode 100644 index 0000000000000000000000000000000000000000..3dbad3d73d4e2acb63bc6e3549018b0edae5ed99 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateSpecialtyAction.java @@ -0,0 +1,45 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.SpecialtyDialog; +import cn.edu.hit.education.pojo.Specialty; +import cn.edu.hit.education.service.ISpecialtyService; +import cn.edu.hit.education.view.DepartmentExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateSpecialtyAction extends Action { + ISpecialtyService specialtyService = (ISpecialtyService)Application.applicationContext.getBean("specialtyServiceImpl"); + private int specialtyId; + private DepartmentExploreView viewPart; + /** + * @wbp.parser.entryPoint + */ + public UpdateSpecialtyAction(DepartmentExploreView viewPart,int specialtyId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改专业"); + this.setText("修改专业"); + this.viewPart = viewPart; + this.specialtyId = specialtyId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + SpecialtyDialog specialtyDialog = new SpecialtyDialog(parentShell); + Specialty specialty = specialtyService.queryByPrimaryKey(specialtyId); + specialtyDialog.setSpecialty(specialty); + if(IDialogConstants.OK_ID == specialtyDialog.open()){ + int count = specialtyService.update(specialty); + if(count > 0){ + viewPart.refreshUpdateData(specialty); + } + } + super.run(); + } +} diff --git a/src/cn/edu/hit/education/action/UpdateUniversityAction.java b/src/cn/edu/hit/education/action/UpdateUniversityAction.java new file mode 100644 index 0000000000000000000000000000000000000000..cb4d496e87006ae09f66c155375ce7961ba46ac2 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateUniversityAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.UniversityDialog; +import cn.edu.hit.education.pojo.University; +import cn.edu.hit.education.service.IUniversityService; +import cn.edu.hit.education.view.DepartmentExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateUniversityAction extends Action { + private DepartmentExploreView viewPart; + IUniversityService universityService = (IUniversityService)Application.applicationContext.getBean("universityServiceImpl"); + private int unversityId; + + public UpdateUniversityAction(DepartmentExploreView viewPart,int unversityId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改学校"); + this.setText("修改学校"); + this.viewPart = viewPart; + this.unversityId = unversityId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + UniversityDialog universityDialog = new UniversityDialog(parentShell); + University university = universityService.queryUniversityByPrimaryKey(unversityId); + universityDialog.setUniversity(university); + if(IDialogConstants.OK_ID == universityDialog.open()){ + int count = universityService.update(university); + if(count > 0){ + viewPart.refreshUpdateData(university); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/contentprovider/ExScheduleContentProvider.java b/src/cn/edu/hit/education/contentprovider/ExScheduleContentProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..02543dd7acbbf4509bc37ec4fa755034995af5a3 --- /dev/null +++ b/src/cn/edu/hit/education/contentprovider/ExScheduleContentProvider.java @@ -0,0 +1,28 @@ +package cn.edu.hit.education.contentprovider; + +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +public class ExScheduleContentProvider implements IStructuredContentProvider{ + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method stub + + } + + @Override + public Object[] getElements(Object inputElement) { + // TODO Auto-generated method stub + return ((List) inputElement).toArray(); + } + +} diff --git a/src/cn/edu/hit/education/labelprovider/CourseInformationLabelProvider.java b/src/cn/edu/hit/education/labelprovider/CourseInformationLabelProvider.java index a7365e651bf39e63da6437a3ab1e2d9e156274d8..f44cfd3cc9b4f25239488912508c7305d515e600 100644 --- a/src/cn/edu/hit/education/labelprovider/CourseInformationLabelProvider.java +++ b/src/cn/edu/hit/education/labelprovider/CourseInformationLabelProvider.java @@ -23,19 +23,19 @@ public class CourseInformationLabelProvider extends LabelProvider implements }else if (columnIndex == 2) { return String.valueOf(data.getCredits()); }else if (columnIndex == 3) { - if(data.getMethod() != null && data.getMethod().trim().equals("��ɢ")){ + if(data.getMethod() != null && data.getMethod().trim().equals("分散")){ return "(" + String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + ") " + unitName; }else{ return String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + " " + unitName; } }else if (columnIndex == 4) { - if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("��ɢ")){ + if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){ return "(" + String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + ") " + unitName; }else{ return String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + " " + unitName; } }else if (columnIndex == 5) { - if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("��ɢ")){ + if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){ return "(" + String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + ") " + unitName; }else{ return String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + " " + unitName; diff --git a/src/cn/edu/hit/education/labelprovider/CourseScheduleLabelProvider.java b/src/cn/edu/hit/education/labelprovider/CourseScheduleLabelProvider.java index 28c6fbd62c7a7bb60f0071d77b5034e645f0d81a..4576163786d398d2507f9e4916a0f4655dab1732 100644 --- a/src/cn/edu/hit/education/labelprovider/CourseScheduleLabelProvider.java +++ b/src/cn/edu/hit/education/labelprovider/CourseScheduleLabelProvider.java @@ -1,57 +1,57 @@ -package cn.edu.hit.education.labelprovider; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -import cn.edu.hit.education.pojo.Course; - -public class CourseScheduleLabelProvider extends LabelProvider implements - ITableLabelProvider { - /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );*/ - - @Override - public String getColumnText(Object element, int columnIndex) { - // TODO Auto-generated method stub - Course data = (Course) element; - String unitName = data.getUnit() == null ? "" : data.getUnit(); - if (columnIndex == 0) { - return data.getNumber()==null?"":data.getNumber(); - }else if (columnIndex == 1) { - return data.getName(); - }else if (columnIndex == 2) { - return String.valueOf(data.getCredits()); - }else if (columnIndex == 3) { - if(data.getMethod() != null && data.getMethod().trim().equals("·ÖÉ¢")){ - return "(" + String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + ") " + unitName; - }else{ - return String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + " " + unitName; - } - }else if (columnIndex == 4) { - if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("·ÖÉ¢")){ - return "(" + String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + ") " + unitName; - }else{ - return String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + " " + unitName; - } - }else if (columnIndex == 5) { - if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("·ÖÉ¢")){ - return "(" + String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + ") " + unitName; - }else{ - return String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + " " + unitName; - } - }else{ - return ""; - } - } - - public Image getColumnImage(Object obj, int index) { - return null; - } - - public Image getImage(Object obj) { - return PlatformUI.getWorkbench().getSharedImages() - .getImage(ISharedImages.IMG_OBJ_ELEMENT); - } +package cn.edu.hit.education.labelprovider; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +import cn.edu.hit.education.pojo.Course; + +public class CourseScheduleLabelProvider extends LabelProvider implements + ITableLabelProvider { + /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );*/ + + @Override + public String getColumnText(Object element, int columnIndex) { + // TODO Auto-generated method stub + Course data = (Course) element; + String unitName = data.getUnit() == null ? "" : data.getUnit(); + if (columnIndex == 0) { + return data.getNumber()==null?"":data.getNumber(); + }else if (columnIndex == 1) { + return data.getName(); + }else if (columnIndex == 2) { + return String.valueOf(data.getCredits()); + }else if (columnIndex == 3) { + if(data.getMethod() != null && data.getMethod().trim().equals("分散")){ + return "(" + String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + ") " + unitName; + }else{ + return String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + " " + unitName; + } + }else if (columnIndex == 4) { + if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){ + return "(" + String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + ") " + unitName; + }else{ + return String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + " " + unitName; + } + }else if (columnIndex == 5) { + if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){ + return "(" + String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + ") " + unitName; + }else{ + return String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + " " + unitName; + } + }else{ + return ""; + } + } + + public Image getColumnImage(Object obj, int index) { + return null; + } + + public Image getImage(Object obj) { + return PlatformUI.getWorkbench().getSharedImages() + .getImage(ISharedImages.IMG_OBJ_ELEMENT); + } } \ No newline at end of file diff --git a/src/cn/edu/hit/education/labelprovider/ExScheduleLabelProvider.java b/src/cn/edu/hit/education/labelprovider/ExScheduleLabelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..996a576da0e6dc9fc9716c68f759a00b1bc05bd4 --- /dev/null +++ b/src/cn/edu/hit/education/labelprovider/ExScheduleLabelProvider.java @@ -0,0 +1,60 @@ +package cn.edu.hit.education.labelprovider; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.pojo.ExSchedule; + +public class ExScheduleLabelProvider extends LabelProvider implements + ITableLabelProvider { + /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );*/ + + @Override + public String getColumnText(Object element, int columnIndex) { + // TODO Auto-generated method stub + ExSchedule data = (ExSchedule) element; + Course course = data.getCourse(); + + String unitName = course.getUnit() == null ? "" : course.getUnit(); + if (columnIndex == 0) { + return course.getNumber()==null?"":course.getNumber(); + }else if (columnIndex == 1) { + return course.getName(); + }else if (columnIndex == 2) { + return String.valueOf(data.getCredits()); + }else if (columnIndex == 3) { + if(course.getMethod() != null && course.getMethod().trim().equals("分散")){ + return "(" + String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + ") " + unitName; + }else{ + return String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + " " + unitName; + } + }else if (columnIndex == 4) { + if(course.getMethod() != null && course.getMethod() != null && course.getMethod().trim().equals("分散")){ + return "(" + String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + ") " + unitName; + }else{ + return String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + " " + unitName; + } + }else if (columnIndex == 5) { + if(course.getMethod() != null && course.getMethod() != null && course.getMethod().trim().equals("分散")){ + return "(" + String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + ") " + unitName; + }else{ + return String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + " " + unitName; + } + }else{ + return ""; + } + } + + public Image getColumnImage(Object obj, int index) { + return null; + } + + public Image getImage(Object obj) { + return PlatformUI.getWorkbench().getSharedImages() + .getImage(ISharedImages.IMG_OBJ_ELEMENT); + } +} \ No newline at end of file diff --git a/src/cn/edu/hit/education/pojo/ExSchedule.java b/src/cn/edu/hit/education/pojo/ExSchedule.java new file mode 100644 index 0000000000000000000000000000000000000000..57dcb5ea5eaafcee1549d02ad367d6e8dc21f704 --- /dev/null +++ b/src/cn/edu/hit/education/pojo/ExSchedule.java @@ -0,0 +1,13 @@ +package cn.edu.hit.education.pojo; + +public class ExSchedule extends Schedule { + private Course course; + + public Course getCourse() { + return course; + } + + public void setCourse(Course course) { + this.course = course; + } +} diff --git a/src/cn/edu/hit/education/service/CollegeServiceImpl.java b/src/cn/edu/hit/education/service/CollegeServiceImpl.java index b2de18d1ede317fb575b73fb34256fa8fea364c5..be467a6d6d08e18cb903027c812efd8cc0a329c3 100644 --- a/src/cn/edu/hit/education/service/CollegeServiceImpl.java +++ b/src/cn/edu/hit/education/service/CollegeServiceImpl.java @@ -1,109 +1,93 @@ -/** -*

title £º CollegeServiceImpl.java

-*

package £º cn.edu.hit.education.service

-*

description £ºTODO

-*

copyright £º ¹þ¶û±õ¹¤Òµ´óѧ(C) 2019

-*

company £º ¹þ¶û±õ¹¤Òµ´óѧAS&MT

-*

author £º ½ðÑ©ËÉ jinxuesong@163.com

-*

date £º 2021Äê4ÔÂ21ÈÕ ÏÂÎç4:36:36

-*

version £º v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021Äê4ÔÂ21ÈÕ ½ðÑ©ËÉ 1.0 1.0 -* Why & What is modified: <ÐÞ¸ÄÔ­ÒòÃèÊö> -*/ -package cn.edu.hit.education.service; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import cn.edu.hit.education.dao.CollegeMapper; -import cn.edu.hit.education.pojo.College; -import cn.edu.hit.education.pojo.CollegeExample; - -/** - *

classname £º CollegeServiceImpl

- *

description £ºTODO

- *

author £º ½ðÑ©ËÉ jinxuesong@163.com

- *

date £º 2021Äê4ÔÂ21ÈÕ ÏÂÎç4:36:36

- */ -@Service -public class CollegeServiceImpl implements ICollegeService { - - @Autowired - CollegeMapper collegeMapper; - - @Override - public int insert(College college) { - // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù - return collegeMapper.insert(college); - } - - /* (·Ç Javadoc) - *

Title: deleteByPrimaryKey

- *

Description:

- * @param id - * @return - * @see cn.edu.hit.education.service.ICollegeService#deleteByPrimaryKey(int) - */ - - @Override - public int deleteByPrimaryKey(int id) { - // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù - return collegeMapper.deleteByPrimaryKey(id); - } - - /* (·Ç Javadoc) - *

Title: update

- *

Description:

- * @param college - * @return - * @see cn.edu.hit.education.service.ICollegeService#update(cn.edu.hit.education.pojo.College) - */ - - @Override - public int update(College college) { - // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù - return collegeMapper.updateByPrimaryKey(college); - } - - /* (·Ç Javadoc) - *

Title: queryAllCollege

- *

Description:

- * @return - * @see cn.edu.hit.education.service.ICollegeService#queryAllCollege() - */ - - @Override - public List queryAllCollege() { - // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù - CollegeExample example = new CollegeExample(); - CollegeExample.Criteria criteria = example.createCriteria(); - criteria.andIdGreaterThan(0); - - return collegeMapper.selectByExample(example); - } - - /* (·Ç Javadoc) - *

Title: queryCollegesByUniversityId

- *

Description:

- * @param universityId - * @return - * @see cn.edu.hit.education.service.ICollegeService#queryCollegesByUniversityId(int) - */ - - @Override - public List queryCollegesByUniversityId(int universityId) { - // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù - CollegeExample example = new CollegeExample(); - CollegeExample.Criteria criteria = example.createCriteria(); - criteria.andUniversityIdEqualTo(universityId); - - return collegeMapper.selectByExample(example); - } - -} +/** +*

title �� CollegeServiceImpl.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:36:36

+*

version �� v1.0

+* +* Modification History: +* Date Author Version Discription +* ----------------------------------------------------------------------------------- +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> +*/ +package cn.edu.hit.education.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import cn.edu.hit.education.dao.CollegeMapper; +import cn.edu.hit.education.pojo.College; +import cn.edu.hit.education.pojo.CollegeExample; +import cn.edu.hit.education.pojo.Specialty; + +@Service +public class CollegeServiceImpl implements ICollegeService { + + @Autowired + CollegeMapper collegeMapper; + @Autowired + ISpecialtyService specialtyService; + + @Override + public int insert(College college) { + return collegeMapper.insert(college); + } + + + @Override + public int deleteByPrimaryKey(int id) { + return collegeMapper.deleteByPrimaryKey(id); + } + + + @Override + public int update(College college) { + return collegeMapper.updateByPrimaryKey(college); + } + + @Override + public List queryAllCollege() { + CollegeExample example = new CollegeExample(); + CollegeExample.Criteria criteria = example.createCriteria(); + criteria.andIdGreaterThan(0); + + return collegeMapper.selectByExample(example); + } + + @Override + public List queryCollegesByUniversityId(int universityId) { + CollegeExample example = new CollegeExample(); + CollegeExample.Criteria criteria = example.createCriteria(); + criteria.andUniversityIdEqualTo(universityId); + + return collegeMapper.selectByExample(example); + } + + @Override + public College queryCollegeByPrimaryKey(int id) { + // TODO Auto-generated method stub + return collegeMapper.selectByPrimaryKey(id); + } + + + @Override + public int deleteByPrimaryKeyCascade(int id) { + // TODO Auto-generated method stub + List specialties = specialtyService.querySpecialtiesByCollegeId(id); + if(specialties != null && specialties.size() > 0){ + for (Specialty specialty : specialties) { + specialtyService.deleteByPrimaryKey(specialty.getId()); + } + } + + + return collegeMapper.deleteByPrimaryKey(id); + } + +} diff --git a/src/cn/edu/hit/education/service/ICollegeService.java b/src/cn/edu/hit/education/service/ICollegeService.java index f29323dab5c31ca390ab078a84501bb1e2ab27ce..fc22e344f7a027c1b5b596dcf3a327bbda438d2f 100644 --- a/src/cn/edu/hit/education/service/ICollegeService.java +++ b/src/cn/edu/hit/education/service/ICollegeService.java @@ -1,39 +1,37 @@ -/** -*

title £º ICollegeService.java

-*

package £º cn.edu.hit.education.service

-*

description £ºTODO

-*

copyright £º ¹þ¶û±õ¹¤Òµ´óѧ(C) 2019

-*

company £º ¹þ¶û±õ¹¤Òµ´óѧAS&MT

-*

author £º ½ðÑ©ËÉ jinxuesong@163.com

-*

date £º 2021Äê4ÔÂ21ÈÕ ÏÂÎç2:59:45

-*

version £º v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021Äê4ÔÂ21ÈÕ ½ðÑ©ËÉ 1.0 1.0 -* Why & What is modified: <ÐÞ¸ÄÔ­ÒòÃèÊö> -*/ -package cn.edu.hit.education.service; - -import java.util.List; - -import cn.edu.hit.education.pojo.College; - -/** - *

classname £º ICollegeService

- *

description £ºTODO

- *

author £º ½ðÑ©ËÉ jinxuesong@163.com

- *

date £º 2021Äê4ÔÂ21ÈÕ ÏÂÎç2:59:45

- */ -public interface ICollegeService { - int insert(College college); - - int deleteByPrimaryKey(int id); - - int update(College college); - - List queryAllCollege(); - - List queryCollegesByUniversityId(int universityId); -} +/** +*

title �� ICollegeService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����2:59:45

+*

version �� v1.0

+* +* Modification History: +* Date Author Version Discription +* ----------------------------------------------------------------------------------- +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> +*/ +package cn.edu.hit.education.service; + +import java.util.List; + +import cn.edu.hit.education.pojo.College; + +public interface ICollegeService { + int insert(College college); + + int deleteByPrimaryKey(int id); + + int update(College college); + + int deleteByPrimaryKeyCascade(int id); + + College queryCollegeByPrimaryKey(int id); + + List queryAllCollege(); + + List queryCollegesByUniversityId(int universityId); +} diff --git a/src/cn/edu/hit/education/service/IScheduleService.java b/src/cn/edu/hit/education/service/IScheduleService.java index cd188520449bf91146dc12ae15f3c3d75010fd94..fca93472260adef719e766aa3aa8ed7e1f48a9a7 100644 --- a/src/cn/edu/hit/education/service/IScheduleService.java +++ b/src/cn/edu/hit/education/service/IScheduleService.java @@ -1,56 +1,53 @@ -/** -*

title �� IScheduleService.java

-*

package �� cn.edu.hit.education.service

-*

description ��TODO

-*

copyright �� ��������ҵ��ѧ(C) 2019

-*

company �� ��������ҵ��ѧAS&MT

-*

author �� ��ѩ�� jinxuesong@163.com

-*

date �� 2021��4��21�� ����3:00:32

-*

version �� v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021��4��21�� ��ѩ�� 1.0 1.0 -* Why & What is modified: <�޸�ԭ������> -*/ -package cn.edu.hit.education.service; - -import java.util.List; - -import cn.edu.hit.education.pojo.Schedule; - -/** - *

classname �� IScheduleService

- *

description ��TODO

- *

author �� ��ѩ�� jinxuesong@163.com

- *

date �� 2021��4��21�� ����3:00:32

- */ -public interface IScheduleService { - - int insert(Schedule schedule); - - int deleteByPrimaryKey(int id); - - int update(Schedule schedule); - - Schedule qurySchedule(int courseId); - - List queryAllSchedule(); - - List querySchedulesBySpecialtyId(int specialtyId,int opened); - - List querySchedulesBySpecialtySemesterId(int specialtyId, int semesterId); - - List querySchedulesBySpecialtySemesterCourseId(int specialtyId, int semesterId,int courseId); - - List querySchedulesBySpecialtyCourseId(int specialtyId, int courseId); - - void statisticsSchedule(int specialtyId,int opened); - - List querySchedulesBySemesterCourseId(Integer semesterId, Integer courseId); - - List querySchedulesBySemesterId(int semesterId); - - List querySchedulesBySCourseId(Integer courseId); -} +/** +*

title �� IScheduleService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����3:00:32

+*

version �� v1.0

+* +* Modification History: +* Date Author Version Discription +* ----------------------------------------------------------------------------------- +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> +*/ +package cn.edu.hit.education.service; + +import java.util.List; + +import cn.edu.hit.education.pojo.ExSchedule; +import cn.edu.hit.education.pojo.Schedule; + +public interface IScheduleService { + + int insert(Schedule schedule); + + int deleteByPrimaryKey(int id); + + int update(Schedule schedule); + + Schedule qurySchedule(int courseId); + + List queryAllSchedule(); + + List querySchedulesBySpecialtyId(int specialtyId,int opened); + + List querySchedulesBySpecialtySemesterId(int specialtyId, int semesterId); + + List querySchedulesBySpecialtySemesterCourseId(int specialtyId, int semesterId,int courseId); + + List querySchedulesBySpecialtyCourseId(int specialtyId, int courseId); + + void statisticsSchedule(int specialtyId,int opened); + + List querySchedulesBySemesterCourseId(Integer semesterId, Integer courseId); + + List querySchedulesBySemesterId(int semesterId); + + List querySchedulesBySCourseId(Integer courseId); + + List queryExSchedulesBySpecialtySemesterId(int specialtyId, int semesterId); +} diff --git a/src/cn/edu/hit/education/service/ISpecialtyService.java b/src/cn/edu/hit/education/service/ISpecialtyService.java index 76c2b8e2ad1c9f0cbede8476a2299ea46471edd5..b8e084f9ddab9fb52bd6877d519eaa464552c985 100644 --- a/src/cn/edu/hit/education/service/ISpecialtyService.java +++ b/src/cn/edu/hit/education/service/ISpecialtyService.java @@ -1,44 +1,38 @@ -/** -*

title �� ISpecialtyService.java

-*

package �� cn.edu.hit.education.service

-*

description ��TODO

-*

copyright �� ��������ҵ��ѧ(C) 2019

-*

company �� ��������ҵ��ѧAS&MT

-*

author �� ��ѩ�� jinxuesong@163.com

-*

date �� 2021��4��21�� ����2:59:59

-*

version �� v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021��4��21�� ��ѩ�� 1.0 1.0 -* Why & What is modified: <�޸�ԭ������> -*/ -package cn.edu.hit.education.service; - -import java.util.List; - -import cn.edu.hit.education.pojo.Specialty; - -/** - *

classname �� ISpecialtyService

- *

description ��TODO

- *

author �� ��ѩ�� jinxuesong@163.com

- *

date �� 2021��4��21�� ����2:59:59

- */ -public interface ISpecialtyService { - - int insert(Specialty specialty); - - int deleteByPrimaryKey(int id); - - int update(Specialty specialty); - - Specialty queryByPrimaryKey(int id); - - List queryAllSpecialty(); - - List querySpecialtiesByCollegeId(int collegeId); - - List queryRelativeSpecialty(List ids); -} +/** +*

title �� ISpecialtyService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����2:59:59

+*

version �� v1.0

+* +* Modification History: +* Date Author Version Discription +* ----------------------------------------------------------------------------------- +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> +*/ +package cn.edu.hit.education.service; + +import java.util.List; + +import cn.edu.hit.education.pojo.Specialty; + +public interface ISpecialtyService { + + int insert(Specialty specialty); + + int deleteByPrimaryKey(int id); + + int update(Specialty specialty); + + Specialty queryByPrimaryKey(int id); + + List queryAllSpecialty(); + + List querySpecialtiesByCollegeId(int collegeId); + + List queryRelativeSpecialty(List ids); +} diff --git a/src/cn/edu/hit/education/service/IUniversityService.java b/src/cn/edu/hit/education/service/IUniversityService.java index abf4f7cbb59280ce61053d2f2196697a2ca2f941..afad92a78433e1dd1ce6fd5f51f154eae184ac4b 100644 --- a/src/cn/edu/hit/education/service/IUniversityService.java +++ b/src/cn/edu/hit/education/service/IUniversityService.java @@ -26,6 +26,8 @@ public interface IUniversityService { int deleteByPrimaryKey(int id); + int deleteByPrimaryKeyCascade(int id); + int update(University university); List queryAllUniversity(); diff --git a/src/cn/edu/hit/education/service/ScheduleServiceImpl.java b/src/cn/edu/hit/education/service/ScheduleServiceImpl.java index 36ef1351888b053577b3e23d7fe1b209d235af10..f18c8dba45a9821a27e06dc89a121cf95ac8dbc1 100644 --- a/src/cn/edu/hit/education/service/ScheduleServiceImpl.java +++ b/src/cn/edu/hit/education/service/ScheduleServiceImpl.java @@ -1,195 +1,204 @@ -/** -*

title �� ScheduleServiceImpl.java

-*

package �� cn.edu.hit.education.service

-*

description ��TODO

-*

copyright �� ��������ҵ��ѧ(C) 2019

-*

company �� ��������ҵ��ѧAS&MT

-*

author �� ��ѩ�� jinxuesong@163.com

-*

date �� 2021��4��21�� ����4:40:39

-*

version �� v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021��4��21�� ��ѩ�� 1.0 1.0 -* Why & What is modified: <�޸�ԭ������> -*/ -package cn.edu.hit.education.service; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import cn.edu.hit.education.dao.ScheduleMapper; -import cn.edu.hit.education.pojo.Course; -import cn.edu.hit.education.pojo.Schedule; -import cn.edu.hit.education.pojo.ScheduleExample; -import cn.edu.hit.education.utils.StatisticsUtil; - -/** - *

classname �� ScheduleServiceImpl

- *

description ��TODO

- *

author �� ��ѩ�� jinxuesong@163.com

- *

date �� 2021��4��21�� ����4:40:39

- */ -@Service -public class ScheduleServiceImpl implements IScheduleService { - - @Autowired - ScheduleMapper scheduleMapper; - @Autowired - ICourseService courseService; - - @Override - public int insert(Schedule schedule) { - // TODO �Զ����ɵķ������ - return scheduleMapper.insert(schedule); - } - @Override - public int deleteByPrimaryKey(int id) { - // TODO �Զ����ɵķ������ - return scheduleMapper.deleteByPrimaryKey(id); - } - - @Override - public int update(Schedule schedule) { - // TODO �Զ����ɵķ������ - return scheduleMapper.updateByPrimaryKey(schedule); - } - - @Override - public List queryAllSchedule() { - // TODO �Զ����ɵķ������ - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andIdGreaterThan(0); - - return scheduleMapper.selectByExample(example); - } - - @Override - public List querySchedulesBySpecialtySemesterId(int specialtyId, - int semesterId) { - // TODO �Զ����ɵķ������ - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andSpecialtyIdEqualTo(specialtyId); - criteria.andSemesterIdEqualTo(semesterId); - - return scheduleMapper.selectByExample(example); - } - - @Override - public List querySchedulesBySpecialtySemesterCourseId( - int specialtyId, int semesterId, int courseId) { - // TODO �Զ����ɵķ������ - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andSpecialtyIdEqualTo(specialtyId); - criteria.andSemesterIdEqualTo(semesterId); - criteria.andCourseIdEqualTo(courseId); - - return scheduleMapper.selectByExample(example); - } - - @Override - public List querySchedulesBySpecialtyCourseId(int specialtyId,int courseId) { - // TODO �Զ����ɵķ������ - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andSpecialtyIdEqualTo(specialtyId); - criteria.andCourseIdEqualTo(courseId); - - return scheduleMapper.selectByExample(example); - } - - @Override - public List querySchedulesBySpecialtyId(int specialtyId,int opened) { - // TODO �Զ����ɵķ������ - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andSpecialtyIdEqualTo(specialtyId); - criteria.andOpenedEqualTo(opened); - - return scheduleMapper.selectByExample(example); - } - - @Override - public void statisticsSchedule(int specialtyId,int opened) { - // TODO �Զ����ɵķ������ - List schedules = querySchedulesBySpecialtyId(specialtyId,opened); - - List courses0 = new ArrayList(); - List courses1 = new ArrayList(); - List courses2 = new ArrayList(); - List courses3 = new ArrayList(); - - for (Schedule schedule : schedules) { - Course course = courseService.queryCourseByPrimaryKey(schedule.getCourseId()); - if(course.getSelected().trim().equals("���޿�")){ - if(course.getPropertyId() <= 6){// ��ʵ���� - courses0.add(course); - }else{ - courses1.add(course); - } - }else{ - if(course.getPropertyId() <= 6){// ʵ���� - courses2.add(course); - }else{ - courses3.add(course); - } - } - } - - StatisticsUtil.processCourseScheduleData(courses0); - StatisticsUtil.printTotal(courses0); - StatisticsUtil.processCourseScheduleData(courses1); - StatisticsUtil.printTotal(courses1); - StatisticsUtil.processCourseScheduleData(courses2); - StatisticsUtil.printTotal(courses2); - StatisticsUtil.processCourseScheduleData(courses3); - StatisticsUtil.printTotal(courses3); - } - - @Override - public Schedule qurySchedule(int courseId) { - // TODO Auto-generated method stub - - - return (scheduleMapper.queryCourseByCourseId(courseId)); - } - @Override - public List querySchedulesBySemesterCourseId(Integer semesterId, - Integer courseId) { - // TODO Auto-generated method stub - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andSemesterIdEqualTo(semesterId); - criteria.andCourseIdEqualTo(courseId); - - return scheduleMapper.selectByExample(example); - } - @Override - public List querySchedulesBySemesterId(int semesterId) { - // TODO Auto-generated method stub - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - criteria.andSemesterIdEqualTo(semesterId); - - return scheduleMapper.selectByExample(example); - } - @Override - public List querySchedulesBySCourseId(Integer courseId) { - // TODO Auto-generated method stub - ScheduleExample example = new ScheduleExample(); - ScheduleExample.Criteria criteria = example.createCriteria(); - - criteria.andCourseIdEqualTo(courseId); - - return scheduleMapper.selectByExample(example); - } - - -} +/** +*

title �� ScheduleServiceImpl.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:40:39

+*

version �� v1.0

+* +* Modification History: +* Date Author Version Discription +* ----------------------------------------------------------------------------------- +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> +*/ +package cn.edu.hit.education.service; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import cn.edu.hit.education.dao.ScheduleMapper; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.pojo.ExSchedule; +import cn.edu.hit.education.pojo.Schedule; +import cn.edu.hit.education.pojo.ScheduleExample; +import cn.edu.hit.education.utils.StatisticsUtil; + +@Service +public class ScheduleServiceImpl implements IScheduleService { + + @Autowired + ScheduleMapper scheduleMapper; + @Autowired + ICourseService courseService; + + @Override + public int insert(Schedule schedule) { + return scheduleMapper.insert(schedule); + } + @Override + public int deleteByPrimaryKey(int id) { + return scheduleMapper.deleteByPrimaryKey(id); + } + + @Override + public int update(Schedule schedule) { + return scheduleMapper.updateByPrimaryKey(schedule); + } + + @Override + public List queryAllSchedule() { + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andIdGreaterThan(0); + + return scheduleMapper.selectByExample(example); + } + + @Override + public List querySchedulesBySpecialtySemesterId(int specialtyId, + int semesterId) { + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andSpecialtyIdEqualTo(specialtyId); + criteria.andSemesterIdEqualTo(semesterId); + + return scheduleMapper.selectByExample(example); + } + + @Override + public List querySchedulesBySpecialtySemesterCourseId( + int specialtyId, int semesterId, int courseId) { + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andSpecialtyIdEqualTo(specialtyId); + criteria.andSemesterIdEqualTo(semesterId); + criteria.andCourseIdEqualTo(courseId); + + return scheduleMapper.selectByExample(example); + } + + @Override + public List querySchedulesBySpecialtyCourseId(int specialtyId,int courseId) { + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andSpecialtyIdEqualTo(specialtyId); + criteria.andCourseIdEqualTo(courseId); + + return scheduleMapper.selectByExample(example); + } + + @Override + public List querySchedulesBySpecialtyId(int specialtyId,int opened) { + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andSpecialtyIdEqualTo(specialtyId); + criteria.andOpenedEqualTo(opened); + + return scheduleMapper.selectByExample(example); + } + + @Override + public void statisticsSchedule(int specialtyId,int opened) { + List schedules = querySchedulesBySpecialtyId(specialtyId,opened); + + List courses0 = new ArrayList(); + List courses1 = new ArrayList(); + List courses2 = new ArrayList(); + List courses3 = new ArrayList(); + + for (Schedule schedule : schedules) { + Course course = courseService.queryCourseByPrimaryKey(schedule.getCourseId()); + if(course.getSelected().trim().equals("���޿�")){ + if(course.getPropertyId() <= 6){// + courses0.add(course); + }else{ + courses1.add(course); + } + }else{ + if(course.getPropertyId() <= 6){// + courses2.add(course); + }else{ + courses3.add(course); + } + } + } + + StatisticsUtil.processCourseScheduleData(courses0); + StatisticsUtil.printTotal(courses0); + StatisticsUtil.processCourseScheduleData(courses1); + StatisticsUtil.printTotal(courses1); + StatisticsUtil.processCourseScheduleData(courses2); + StatisticsUtil.printTotal(courses2); + StatisticsUtil.processCourseScheduleData(courses3); + StatisticsUtil.printTotal(courses3); + } + + @Override + public Schedule qurySchedule(int courseId) { + // TODO Auto-generated method stub + + + return (scheduleMapper.queryCourseByCourseId(courseId)); + } + @Override + public List querySchedulesBySemesterCourseId(Integer semesterId, + Integer courseId) { + // TODO Auto-generated method stub + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andSemesterIdEqualTo(semesterId); + criteria.andCourseIdEqualTo(courseId); + + return scheduleMapper.selectByExample(example); + } + @Override + public List querySchedulesBySemesterId(int semesterId) { + // TODO Auto-generated method stub + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + criteria.andSemesterIdEqualTo(semesterId); + + return scheduleMapper.selectByExample(example); + } + @Override + public List querySchedulesBySCourseId(Integer courseId) { + // TODO Auto-generated method stub + ScheduleExample example = new ScheduleExample(); + ScheduleExample.Criteria criteria = example.createCriteria(); + + criteria.andCourseIdEqualTo(courseId); + + return scheduleMapper.selectByExample(example); + } + + @Override + public List queryExSchedulesBySpecialtySemesterId( + int specialtyId, int semesterId) { + List exSchedules = new ArrayList(); + List schedules = querySchedulesBySpecialtySemesterId(specialtyId, semesterId); + for (Schedule schedule : schedules) { + ExSchedule exSchedule = new ExSchedule(); + exSchedule.setId(schedule.getId()); + exSchedule.setSpecialtyId(schedule.getSpecialtyId()); + exSchedule.setSemesterId(schedule.getSemesterId()); + exSchedule.setCourseId(schedule.getCourseId()); + exSchedule.setOpened(schedule.getOpened()); + exSchedule.setCredits(schedule.getCredits()); + exSchedule.setPeriod(schedule.getPeriod()); + exSchedule.setTheoretical(schedule.getTheoretical()); + exSchedule.setExperiment(schedule.getExperiment()); + exSchedule.setNote(schedule.getNote()); + exSchedule.setCourse(courseService.queryCourseByPrimaryKey(schedule.getCourseId())); + exSchedules.add(exSchedule); + } + return exSchedules; + } + + +} diff --git a/src/cn/edu/hit/education/service/UniversityServiceImpl.java b/src/cn/edu/hit/education/service/UniversityServiceImpl.java index a9d9cc0fe11536289884a378a3772c409ced9f74..d32a5f908984b080b12680adfce5b1315fe82e02 100644 --- a/src/cn/edu/hit/education/service/UniversityServiceImpl.java +++ b/src/cn/edu/hit/education/service/UniversityServiceImpl.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import cn.edu.hit.education.dao.UniversityMapper; +import cn.edu.hit.education.pojo.College; import cn.edu.hit.education.pojo.University; import cn.edu.hit.education.pojo.UniversityExample; @@ -29,6 +30,8 @@ import cn.edu.hit.education.pojo.UniversityExample; public class UniversityServiceImpl implements IUniversityService { @Autowired UniversityMapper universityMapper; + @Autowired + ICollegeService collegeService; @Override public int insert(University university) { @@ -60,4 +63,16 @@ public class UniversityServiceImpl implements IUniversityService { return universityMapper.selectByPrimaryKey(id); } + @Override + public int deleteByPrimaryKeyCascade(int id) { + // TODO Auto-generated method stub + List colleges = collegeService.queryCollegesByUniversityId(id); + if(colleges != null && colleges.size() > 0){ + for (College college : colleges) { + collegeService.deleteByPrimaryKeyCascade(college.getId()); + } + } + return universityMapper.deleteByPrimaryKey(id); + } + } diff --git a/src/cn/edu/hit/education/view/CourseScheduleView.java b/src/cn/edu/hit/education/view/CourseScheduleView.java index b76fc689bcbf7937c42059abfb1a2f90d6a937e5..96e563c6e7b34e5f83bcdfd25af2003a21ac892f 100644 --- a/src/cn/edu/hit/education/view/CourseScheduleView.java +++ b/src/cn/edu/hit/education/view/CourseScheduleView.java @@ -217,9 +217,6 @@ public class CourseScheduleView extends ViewPart implements ISelectionProvider{ initSemesterCombo(); // /////////////// refreshData(); - - - } @Override diff --git a/src/cn/edu/hit/education/view/DepartmentExploreView.java b/src/cn/edu/hit/education/view/DepartmentExploreView.java index ea68be49ca7a9d314794210afa00c5f1f92d90bd..5b4781e2f6d8029e0a33501755fbc1a1b1f8e1f8 100644 --- a/src/cn/edu/hit/education/view/DepartmentExploreView.java +++ b/src/cn/edu/hit/education/view/DepartmentExploreView.java @@ -15,6 +15,9 @@ import org.springframework.stereotype.Component; import cn.edu.hit.education.action.AddCollegeAction; import cn.edu.hit.education.action.AddSpecialtyAction; import cn.edu.hit.education.action.AddUniversityAction; +import cn.edu.hit.education.action.UpdateCollegeAction; +import cn.edu.hit.education.action.UpdateSpecialtyAction; +import cn.edu.hit.education.action.UpdateUniversityAction; import cn.edu.hit.education.contentprovider.DepartmentContentProvider; import cn.edu.hit.education.labelprovider.DepartmentLabelProvider; import cn.edu.hit.education.model.CollegeNode; @@ -72,10 +75,12 @@ public class DepartmentExploreView extends ViewPart { menuMgr.add(new AddUniversityAction(DepartmentExploreView.this)); }else if(currentNode instanceof UniversityNode){ menuMgr.add(new AddCollegeAction(DepartmentExploreView.this,currentNode.getId())); + menuMgr.add(new UpdateUniversityAction(DepartmentExploreView.this,currentNode.getId())); }else if(currentNode instanceof CollegeNode){ menuMgr.add(new AddSpecialtyAction(DepartmentExploreView.this,currentNode.getId())); + menuMgr.add(new UpdateCollegeAction(DepartmentExploreView.this,currentNode.getId())); }else{ - + menuMgr.add(new UpdateSpecialtyAction(DepartmentExploreView.this,currentNode.getId())); } } } @@ -85,27 +90,46 @@ public class DepartmentExploreView extends ViewPart { } - public void refreshData(Object obj){ + public void refreshNewData(Object obj){ if(obj instanceof University){ University university = (University)obj; UniversityNode universityNode = new UniversityNode(university.getId(),university.getName()); - treeViewer.add(currentNode, universityNode); + currentNode.addChild(universityNode); + //treeViewer.add(currentNode, universityNode); }else if(obj instanceof College){ College college = (College)obj; CollegeNode collegeNode = new CollegeNode(college.getId(),college.getName()); - treeViewer.add(currentNode, collegeNode); + currentNode.addChild(collegeNode); + //treeViewer.add(currentNode, collegeNode); }else if(obj instanceof Specialty){ Specialty specialty = (Specialty)obj; SpecialtyNode specialtyNode = new SpecialtyNode(specialty.getId(),specialty.getName()); - treeViewer.add(currentNode, specialtyNode); + currentNode.addChild(specialtyNode); + //treeViewer.add(currentNode, specialtyNode); }else{ } - Object nodes = treeViewer.getInput(); - //treeViewer.refresh(); + treeViewer.refresh(currentNode,true); treeViewer.setExpandedState(currentNode, true); + } + + public void refreshUpdateData(Object obj){ + if(obj instanceof University){ + University university = (University)obj; + currentNode.setName(university.getName()); + }else if(obj instanceof College){ + College college = (College)obj; + currentNode.setName(college.getName()); + }else if(obj instanceof Specialty){ + Specialty specialty = (Specialty)obj; + currentNode.setName(specialty.getName()); + }else{ + + } + treeViewer.refresh(currentNode,true); + treeViewer.setExpandedState(currentNode, true); } /** diff --git a/src/educationschedule/Activator.java b/src/educationschedule/Activator.java index d9ccc8fd50b6f7c8572132f431de3723d65e1e5b..9e77176b5f39d11b7d94e1c3757c2713ee271a8e 100644 --- a/src/educationschedule/Activator.java +++ b/src/educationschedule/Activator.java @@ -1,61 +1,62 @@ -package educationschedule; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "EducationSchedule"; //$NON-NLS-1$ - - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - - /** - * Returns an image descriptor for the image file at the given - * plug-in relative path - * - * @param path the path - * @return the image descriptor - */ - public static ImageDescriptor getImageDescriptor(String path) { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } -} +package educationschedule; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "EducationSchedule"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + +} diff --git a/src/educationschedule/Perspective.java b/src/educationschedule/Perspective.java index 314ee9d3994c69b7800fad89cb4c56a7f611790d..db5635d0aefba69130eb3eac401352c18664304a 100644 --- a/src/educationschedule/Perspective.java +++ b/src/educationschedule/Perspective.java @@ -4,6 +4,7 @@ import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; +import cbg.article.treeviewer.ui.MovingBoxView; import cn.edu.hit.education.view.CourseExploreView; import cn.edu.hit.education.view.CourseInformationView; import cn.edu.hit.education.view.CourseScheduleView; @@ -23,7 +24,7 @@ public class Perspective implements IPerspectiveFactory { IFolderLayout mainArea = layout.createFolder("mainArea", IPageLayout.LEFT, 0.8f, editorArea); mainArea.addView(CourseScheduleView.ID); mainArea.addView(CourseInformationView.ID); - //mainArea.addView(View.ID); + mainArea.addView(MovingBoxView.ID); } }