001: /**
002: * Miroslav Popov, Aug 5, 2005
003: */package org.enhydra.jawe.base.recentfiles;
004:
005: import java.util.List;
006: import java.util.Observable;
007: import java.util.Observer;
008:
009: import org.enhydra.jawe.JaWEComponent;
010: import org.enhydra.jawe.JaWEComponentSettings;
011: import org.enhydra.jawe.JaWEComponentView;
012: import org.enhydra.jawe.JaWEManager;
013: import org.enhydra.jawe.XPDLElementChangeInfo;
014: import org.enhydra.shark.xpdl.XMLCollection;
015: import org.enhydra.shark.xpdl.XMLElement;
016: import org.enhydra.shark.xpdl.XMLElementChangeInfo;
017: import org.enhydra.shark.xpdl.elements.Package;
018:
019: /**
020: * @author Miroslav Popov
021: *
022: */
023: public class RecentFilesManager implements Observer, JaWEComponent {
024:
025: protected String type = JaWEComponent.OTHER_COMPONENT;
026:
027: protected RecentFilesMenu menu;
028:
029: protected RecentFilesSettings settings;
030:
031: public RecentFilesManager(JaWEComponentSettings settings)
032: throws Exception {
033: this .settings = (RecentFilesSettings) settings;
034: this .settings.init(this );
035: JaWEManager.getInstance().getJaWEController().addObserver(this );
036: init();
037: }
038:
039: public JaWEComponentSettings getSettings() {
040: return settings;
041: }
042:
043: protected void init() {
044: menu = new RecentFilesMenu(this );
045: menu.configure();
046: menu.init();
047: }
048:
049: public JaWEComponentView getView() {
050: return menu;
051: }
052:
053: public String getType() {
054: return type;
055: }
056:
057: public void setType(String type) {
058: this .type = type;
059: }
060:
061: public String getName() {
062: return "RecentFilesComponent";
063: }
064:
065: public boolean adjustXPDL(Package pkg) {
066: return false;
067: }
068:
069: public List checkValidity(XMLElement el, boolean fullCheck) {
070: return null;
071: }
072:
073: public boolean canCreateElement(XMLCollection col) {
074: return true;
075: }
076:
077: public boolean canInsertElement(XMLCollection col, XMLElement el) {
078: return true;
079: }
080:
081: public boolean canModifyElement(XMLElement el) {
082: return true;
083: }
084:
085: public boolean canRemoveElement(XMLCollection col, XMLElement el) {
086: return true;
087: }
088:
089: public boolean canDuplicateElement(XMLCollection col, XMLElement el) {
090: return true;
091: }
092:
093: public boolean canRepositionElement(XMLCollection col, XMLElement el) {
094: return true;
095: }
096:
097: public void update(Observable o, Object arg) {
098: if (!(arg instanceof XPDLElementChangeInfo))
099: return;
100: XPDLElementChangeInfo info = (XPDLElementChangeInfo) arg;
101: XMLElement changedElement = info.getChangedElement();
102: if (changedElement == null)
103: return;
104:
105: int action = info.getAction();
106: if (!(action == XMLElementChangeInfo.INSERTED || action == XMLElementChangeInfo.REMOVED))
107: return;
108:
109: if (changedElement instanceof Package) {
110: Package pkg = (Package) changedElement;
111: if (action == XMLElementChangeInfo.INSERTED) {
112: if (pkg == JaWEManager.getInstance()
113: .getJaWEController().getMainPackage()) {
114: menu.addToRecentFiles(JaWEManager.getInstance()
115: .getXPDLHandler().getAbsoluteFilePath(pkg));
116: menu.saveRecentFiles();
117: }
118: } else if (action == XMLElementChangeInfo.REMOVED) {
119: if (JaWEManager.getInstance().getJaWEController()
120: .getMainPackage() == null) {
121: String filePath = (String) info.getOldValue();
122: if (filePath != null && !"".equals(filePath)) {
123: menu.addToRecentFiles(filePath);
124: menu.saveRecentFiles();
125: }
126: }
127: }
128: }
129: }
130:
131: public void setUpdateInProgress(boolean inProgress) {
132: }
133:
134: public boolean isUpdateInProgress() {
135: return false;
136: }
137:
138: }
|