ScriptsComponent and associated clases no longer needed

Now zk package mechanism for grouping scripts is used.

FEA: ItEr75S08MigrationZK5
This commit is contained in:
Óscar González Fernández 2011-06-28 19:09:49 +02:00
parent cc77593c9f
commit 48ac38c138
21 changed files with 1 additions and 1007 deletions

View file

@ -1,43 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz;
import org.zkoss.ganttz.util.script.ScriptsRequiredDeclaration;
@ScriptsRequiredDeclaration(dependsOn = { YUIMin.class, ScrollSyncScript.class })
public class ScriptsRequiredByPlanner {
private ScriptsRequiredByPlanner() {
}
public static final String SELECTOR = "/zkau/web/js/yui/2.7.0/selector/selector-min.js";
public static final String YAHOO_DOM_EVENT = "/zkau/web/js/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js";
public static final String DRAGDROPMIN = "/zkau/web/js/yui/2.7.0/dragdrop/dragdrop-min.js";
public static final String ELEMENT_MIN = "/zkau/web/js/yui/2.7.0/element/element-min.js";
public static final String RESIZE_MIN = "/zkau/web/js/yui/2.7.0/resize/resize-min.js";
public static final String LOGGER_MIN = "/zkau/web/js/yui/2.7.0/logger/logger-min.js";
// adding manually js associated to components since they can be used by
// other files with no dependencies being present
public static final String DEPENDENCY_LIST = "/zkau/web/js/ganttz/dependencylist.js";
public static final String DEPENDENCY = "/zkau/web/js/ganttz/dependency.js";
}

View file

@ -1,36 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz;
import org.zkoss.ganttz.util.script.ScriptsRequiredDeclaration;
@ScriptsRequiredDeclaration(dependsOn = YUIMin.class)
public class ScrollSyncScript {
private ScrollSyncScript() {
}
public static final String SCROLL_SYNC = "/zkau/web/js/ganttz/scrollSync.js";
public static final String YAHOO_DOM_EVENT = "/zkau/web/js/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js";
}

View file

@ -1,34 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz;
import org.zkoss.ganttz.util.script.ScriptsRequiredDeclaration;
@ScriptsRequiredDeclaration
public class YUIMin {
private YUIMin() {
}
public static final String YUI_MIN = "/zkau/web/js/yui/2.7.0/yahoo/yahoo-min.js";
}

View file

@ -37,10 +37,8 @@ import org.zkoss.ganttz.util.Interval;
import org.zkoss.ganttz.util.LongOperationFeedback; import org.zkoss.ganttz.util.LongOperationFeedback;
import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation; import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation;
import org.zkoss.ganttz.util.MutableTreeModel; import org.zkoss.ganttz.util.MutableTreeModel;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.WeakReferencedListeners; import org.zkoss.ganttz.util.WeakReferencedListeners;
import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification; import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification;
import org.zkoss.ganttz.util.script.IScriptsRegister;
import org.zkoss.zk.au.out.AuInvoke; import org.zkoss.zk.au.out.AuInvoke;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.HtmlMacroComponent; import org.zkoss.zk.ui.HtmlMacroComponent;
@ -128,7 +126,6 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
timeTrackerComponent = timeTrackerForResourcesLoadPanel(timeTracker); timeTrackerComponent = timeTrackerForResourcesLoadPanel(timeTracker);
resourceLoadList = new ResourceLoadList(timeTracker, treeModel); resourceLoadList = new ResourceLoadList(timeTracker, treeModel);
leftPane = new ResourceLoadLeftPane(treeModel, resourceLoadList); leftPane = new ResourceLoadLeftPane(treeModel, resourceLoadList);
registerNeededScripts();
} }
public ListModel getFilters() { public ListModel getFilters() {
@ -278,15 +275,6 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
return toolbar; return toolbar;
} }
private void registerNeededScripts() {
getScriptsRegister().register(ScriptsRequiredByResourceLoadPanel.class);
}
private IScriptsRegister getScriptsRegister() {
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class)
.retrieve();
}
private MutableTreeModel<LoadTimeLine> createModelForTree() { private MutableTreeModel<LoadTimeLine> createModelForTree() {
MutableTreeModel<LoadTimeLine> result = MutableTreeModel MutableTreeModel<LoadTimeLine> result = MutableTreeModel
.create(LoadTimeLine.class); .create(LoadTimeLine.class);
@ -513,7 +501,6 @@ public class ResourcesLoadPanel extends HtmlMacroComponent {
timeTrackerComponent = timeTrackerForResourcesLoadPanel(timeTracker); timeTrackerComponent = timeTrackerForResourcesLoadPanel(timeTracker);
resourceLoadList = new ResourceLoadList(timeTracker, treeModel); resourceLoadList = new ResourceLoadList(timeTracker, treeModel);
leftPane = new ResourceLoadLeftPane(treeModel, resourceLoadList); leftPane = new ResourceLoadLeftPane(treeModel, resourceLoadList);
registerNeededScripts();
} }
nameFilterListener.fireEvent(new IListenerNotification<IPaginationFilterChangedListener>() { nameFilterListener.fireEvent(new IListenerNotification<IPaginationFilterChangedListener>() {
@Override @Override

View file

@ -1,37 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.resourceload;
import org.zkoss.ganttz.ScrollSyncScript;
import org.zkoss.ganttz.YUIMin;
import org.zkoss.ganttz.util.script.ScriptsRequiredDeclaration;
@ScriptsRequiredDeclaration(dependsOn = { YUIMin.class, ScrollSyncScript.class })
public class ScriptsRequiredByResourceLoadPanel {
private ScriptsRequiredByResourceLoadPanel() {
}
public static final String SELECTOR = "/zkau/web/js/yui/2.7.0/selector/selector-min.js";
public static final String YAHOO_DOM_EVENT = "/zkau/web/js/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js";
}

View file

@ -1,29 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
public interface IScriptsRegister {
public void register(Class<?> klassContainingScripts)
throws IllegalArgumentException;
}

View file

@ -1,137 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.Validate;
public class ScriptDependenciesSorter implements IScriptsRegister {
public static List<ScriptDependency> extractFrom(Class<?> classWithScripts) {
ScriptsRequiredDeclaration annotation = classWithScripts
.getAnnotation(ScriptsRequiredDeclaration.class);
if (annotation == null) {
throw new IllegalArgumentException(classWithScripts
+ " must be annotated with "
+ ScriptsRequiredDeclaration.class.getName());
}
List<ScriptDependency> dependsOn = getDependencies(annotation);
List<ScriptDependency> result = new ArrayList<ScriptDependency>();
for (Field field : getStringFields(getStaticFields(classWithScripts
.getFields()))) {
result.add(new ScriptDependency(getValueFromStringField(field),
dependsOn));
}
return result;
}
static ArrayList<ScriptDependency> getDependencies(
ScriptsRequiredDeclaration declaration) {
Class<?>[] dependsOn = declaration.dependsOn();
ArrayList<ScriptDependency> result = new ArrayList<ScriptDependency>();
for (Class<?> klass : dependsOn) {
result.addAll(extractFrom(klass));
}
return result;
}
static String getValueFromStringField(Field stringField) {
try {
return (String) stringField.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static List<Field> getStaticFields(Field[] fields) {
List<Field> result = new ArrayList<Field>();
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers())) {
result.add(field);
}
}
return result;
}
static List<Field> getStringFields(Collection<Field> fields) {
List<Field> stringFields = new ArrayList<Field>();
for (Field field : fields) {
if (field.getType().equals(String.class)) {
stringFields.add(field);
}
}
return stringFields;
}
private List<ScriptDependency> allScripts = new ArrayList<ScriptDependency>();
public ScriptDependenciesSorter() {
}
public void add(ScriptDependency scriptDependency) {
addAll(Arrays.asList(scriptDependency));
}
public void addAll(List<ScriptDependency> dependencies) {
Validate.noNullElements(dependencies);
allScripts.addAll(dependencies);
}
public List<ScriptDependency> getScriptDependenciesOrderered() {
List<ScriptDependency> result = new ArrayList<ScriptDependency>();
Set<ScriptDependency> alreadyAdded = new HashSet<ScriptDependency>();
for (ScriptDependency scriptDependency : allScripts) {
result.addAll(extract(alreadyAdded, scriptDependency));
}
return Collections.unmodifiableList(result);
}
private List<ScriptDependency> extract(Set<ScriptDependency> alreadyAdded,
ScriptDependency scriptDependency) {
List<ScriptDependency> result = new ArrayList<ScriptDependency>();
if (alreadyAdded.contains(scriptDependency)) {
return result;
}
for (ScriptDependency d : scriptDependency.getDependsOn()) {
result.addAll(extract(alreadyAdded, d));
}
result.add(scriptDependency);
alreadyAdded.add(scriptDependency);
return result;
}
@Override
public void register(Class<?> klassContainingScripts)
throws IllegalArgumentException {
addAll(extractFrom(klassContainingScripts));
}
}

View file

@ -1,91 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Represents a dependency to a script
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class ScriptDependency {
public static List<String> getOnlyURLs(
Collection<? extends ScriptDependency> dependencies) {
List<String> result = new ArrayList<String>();
for (ScriptDependency scriptDependency : dependencies) {
result.add(scriptDependency.getURL());
}
return result;
}
private final String url;
private final List<ScriptDependency> dependsOn;
public ScriptDependency(String url) {
this(url, Collections.<ScriptDependency> emptyList());
}
public ScriptDependency(String url, Collection<? extends ScriptDependency> dependencies) {
Validate.notEmpty(url);
Validate.noNullElements(dependencies);
this.url = url;
this.dependsOn = Collections.unmodifiableList(new ArrayList<ScriptDependency>(
dependencies));
}
public String getURL() {
return this.url;
}
public List<ScriptDependency> getDependsOn() {
return dependsOn;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other instanceof ScriptDependency) {
return url.equals(((ScriptDependency) other).url);
}
return false;
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(url).toHashCode();
}
@Override
public String toString() {
return url;
}
}

View file

@ -1,102 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.HtmlMacroComponent;
public class ScriptsComponent extends HtmlMacroComponent {
private List<ScriptDependency> current = Collections.emptyList();
public ScriptsComponent() {
OnZKDesktopRegistry<IScriptsRegister> singleton = getScriptsRegister();
ScriptRegister register;
if (singleton.isRegistered()) {
register = (ScriptRegister) singleton.retrieve();
} else {
register = new ScriptRegister();
singleton.store(register);
}
register.addDependant(this);
}
private OnZKDesktopRegistry<IScriptsRegister> getScriptsRegister() {
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class);
}
public List<ScriptDependency> getScriptDependencies() {
return current;
}
void setDependencies(List<ScriptDependency> current) {
this.current = current;
if (!executionIsUpdatingPage()) {
recreate();
}
}
private boolean executionIsUpdatingPage() {
return Executions.getCurrent().isAsyncUpdate(null);
}
}
class ScriptRegister implements IScriptsRegister {
private ScriptDependenciesSorter dependenciesSorter = new ScriptDependenciesSorter();
private List<ScriptsComponent> dependant = new ArrayList<ScriptsComponent>();
void addDependant(ScriptsComponent component) {
dependant.add(component);
}
@Override
public void register(Class<?> klassContainingScripts)
throws IllegalArgumentException {
dependenciesSorter.register(klassContainingScripts);
notifyDependant(encodeURLs(dependenciesSorter
.getScriptDependenciesOrderered()));
}
private List<ScriptDependency> encodeURLs(
List<ScriptDependency> scriptDependenciesOrderered) {
List<ScriptDependency> result = new ArrayList<ScriptDependency>();
Execution execution = Executions.getCurrent();
for (ScriptDependency s : scriptDependenciesOrderered) {
result.add(new ScriptDependency(execution.encodeURL(s.getURL())));
}
return result;
}
private void notifyDependant(List<ScriptDependency> current) {
for (ScriptsComponent d : dependant) {
d.setDependencies(current);
}
}
}

View file

@ -1,34 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ScriptsRequiredDeclaration {
public Class<?>[] dependsOn() default {};
}

View file

@ -182,10 +182,4 @@
<macro-uri>~./ganttz/zul/timetracker/timetrackedtable.zul</macro-uri> <macro-uri>~./ganttz/zul/timetracker/timetrackedtable.zul</macro-uri>
</component> </component>
<component>
<component-name>scripts</component-name>
<component-class>org.zkoss.ganttz.util.script.ScriptsComponent</component-class>
<macro-uri>~./ganttz/zul/scripts.zul</macro-uri>
</component>
</language-addon> </language-addon>

View file

@ -1,107 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;
public class ScriptDependenciesSorterTest {
private ScriptDependenciesSorter scriptDependenciesSorter;
@Test(expected = IllegalArgumentException.class)
public void cannotAddNullDependency() {
givenAllScriptsRequired();
scriptDependenciesSorter.add(null);
}
@Test
public void testWithoutDependencies() {
givenAllScriptsRequired();
scriptDependenciesSorter.add(new ScriptDependency("A"));
scriptDependenciesSorter.add(new ScriptDependency("B"));
assertThat(scriptDependenciesSorter.getScriptDependenciesOrderered(),
scriptsReturnedAre("A", "B"));
}
@Test(expected = UnsupportedOperationException.class)
public void theDependenciesOrderedCannotBeModified() {
givenAllScriptsRequired();
scriptDependenciesSorter.getScriptDependenciesOrderered().add(
new ScriptDependency("bla"));
}
@Test
public void dependenciesGoesFirst() {
givenAllScriptsRequired();
scriptDependenciesSorter.add(new ScriptDependency("A", Arrays
.asList(new ScriptDependency("B"))));
assertThat(scriptDependenciesSorter.getScriptDependenciesOrderered(),
scriptsReturnedAre("B", "A"));
}
@Test
public void dependenciesAreNotRepeated() {
givenAllScriptsRequired();
scriptDependenciesSorter.add(new ScriptDependency("A", Arrays
.asList(new ScriptDependency("B"))));
scriptDependenciesSorter.add(new ScriptDependency("C", Arrays
.asList(new ScriptDependency("B"))));
scriptDependenciesSorter.add(new ScriptDependency("D"));
assertThat(scriptDependenciesSorter.getScriptDependenciesOrderered(),
scriptsReturnedAre("B", "A", "C", "D"));
}
private Matcher<List<ScriptDependency>> scriptsReturnedAre(String... urls) {
final List<String> urlsList = Arrays.asList(urls);
return new BaseMatcher<List<ScriptDependency>>() {
@Override
public boolean matches(Object object) {
if (object instanceof List) {
List<ScriptDependency> scriptsRequired = (List<ScriptDependency>) object;
List<String> onlyURLs = ScriptDependency
.getOnlyURLs(scriptsRequired);
return onlyURLs.equals(urlsList);
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("must return " + urlsList);
}
};
}
private void givenAllScriptsRequired() {
scriptDependenciesSorter = new ScriptDependenciesSorter();
}
}

View file

@ -1,91 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public class ScriptDependencyTest {
private ScriptDependency script;
private String url;
private List<ScriptDependency> dependencies;
private void givenScript() {
url = "blabla/zkau/web/js/yui/2.7.0/selector/selector-min.js";
dependencies = new ArrayList<ScriptDependency>();
dependencies.add(new ScriptDependency("blabla/blabla/bla.js"));
script = new ScriptDependency(url, dependencies);
}
@Test
public void aScriptHasAURL() {
givenScript();
assertThat(script.getURL(), equalTo(url));
}
@Test(expected = IllegalArgumentException.class)
public void theURLMustBeNotNull() {
new ScriptDependency(null);
}
@Test(expected = IllegalArgumentException.class)
public void theURLMustBeNotEmpty() {
new ScriptDependency("");
}
@Test(expected = IllegalArgumentException.class)
public void noDependenciesCanBeNull() {
List<ScriptDependency> list = new ArrayList<ScriptDependency>();
list.add(null);
new ScriptDependency("bla", list);
}
@Test
public void aScriptCanHaveDependencies() {
givenScript();
assertThat(script.getDependsOn(), equalTo(dependencies));
}
@Test(expected = UnsupportedOperationException.class)
public void theDependenciesCannotBeModified() {
givenScript();
script.getDependsOn().clear();
}
@Test
public void twoScriptsAreEqualsIfHaveTheSameURL() {
givenScript();
ScriptDependency scriptDependencyWithSameURL = new ScriptDependency(url);
assertThat(scriptDependencyWithSameURL, equalTo(script));
assertThat(scriptDependencyWithSameURL.hashCode(), equalTo(script
.hashCode()));
assertThat(new ScriptDependency(url + "b"), not(equalTo(script)));
}
}

View file

@ -1,108 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.each;
import static org.junit.matchers.JUnitMatchers.hasItem;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;
public class ScriptExtractionTest {
@Test(expected = IllegalArgumentException.class)
public void aClassWithoutScriptRequiredAnnotationIsNotIncluded() {
ScriptDependenciesSorter.extractFrom(String.class);
}
@Test
public void onlyPublicStringFieldsAreIncluded() {
List<ScriptDependency> scripts = ScriptDependenciesSorter
.extractFrom(ScriptsDeclarationsExample.class);
assertThat(scripts.size(), equalTo(2));
assertThat(scripts,
hasItem(withURL(ScriptsDeclarationsExample.EXAMPLE_A)));
}
@Test
public void testIncludesDependencies() {
List<ScriptDependency> scripts = ScriptDependenciesSorter
.extractFrom(ScriptsDeclarationsExample.class);
assertThat(scripts, each(withDependencies(ScriptIncludedExample.base,
ScriptIncludedExample.other)));
}
private Matcher<ScriptDependency> withDependencies(final String... urls) {
final Set<String> urlsSet = new HashSet<String>(Arrays.asList(urls));
return new BaseMatcher<ScriptDependency>() {
@Override
public boolean matches(Object object) {
if (object instanceof ScriptDependency) {
ScriptDependency dependency = (ScriptDependency) object;
Set<String> urls = new HashSet<String>();
for (ScriptDependency s : dependency.getDependsOn()) {
urls.add(s.getURL());
}
return urlsSet.equals(urls);
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("depends on "
+ Arrays.toString(urls));
}
};
}
private Matcher<ScriptDependency> withURL(final String url) {
return new BaseMatcher<ScriptDependency>() {
@Override
public boolean matches(Object dependency) {
if (dependency instanceof ScriptDependency) {
ScriptDependency d = (ScriptDependency) dependency;
return d.getURL().equals(url);
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("it has url:" + url);
}
};
}
}

View file

@ -1,30 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
@ScriptsRequiredDeclaration
public class ScriptIncludedExample {
public static final String base = "blabla/bla/base.js";
public static final String other = "othare/other.js";
}

View file

@ -1,37 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.zkoss.ganttz.util.script;
@ScriptsRequiredDeclaration(dependsOn = ScriptIncludedExample.class)
public class ScriptsDeclarationsExample {
public static final String EXAMPLE_A = "/project-a/blabla/a.js";
public static final String EXAMPLE_B = "/project-a/blabla/b.js";
private static String EXAMPLE_NOT_INCLUDED = "/project-a/blablaadsf/a.js";
public static int NOT_INCLUDED_BECAUSE_IS_NOT_STRING = 4;
public String NOT_INCLUDED_BECAUSE_IS_NOT_STATIC = "balbla/bladsfafa/ba.js";
}

View file

@ -56,8 +56,6 @@ import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
import org.zkoss.ganttz.timetracker.ICellForDetailItemRenderer; import org.zkoss.ganttz.timetracker.ICellForDetailItemRenderer;
import org.zkoss.ganttz.timetracker.IConvertibleToColumn; import org.zkoss.ganttz.timetracker.IConvertibleToColumn;
import org.zkoss.ganttz.timetracker.OnColumnsRowRenderer; import org.zkoss.ganttz.timetracker.OnColumnsRowRenderer;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.script.IScriptsRegister;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
@ -136,16 +134,6 @@ public class ResourceAllocationController extends GenericForwardComposer {
private Window editTaskWindow; private Window editTaskWindow;
public static void registerNeededScripts() {
getScriptsRegister()
.register(ScriptsRequiredByAdvancedAllocation.class);
}
private static IScriptsRegister getScriptsRegister() {
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class)
.retrieve();
}
private EditTaskController editTaskController; private EditTaskController editTaskController;
public void setEditTaskController(EditTaskController editTaskController) { public void setEditTaskController(EditTaskController editTaskController) {

View file

@ -1,37 +0,0 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.web.planner.allocation;
import org.zkoss.ganttz.util.script.ScriptsRequiredDeclaration;
/**
* Represents the scripts required by advance allocation<br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
@ScriptsRequiredDeclaration
public class ScriptsRequiredByAdvancedAllocation {
private ScriptsRequiredByAdvancedAllocation() {
}
public static final String ADVANDED_ALLOCATION = "/js/advanceAllocations.js";
}

View file

@ -42,10 +42,7 @@ import org.springframework.context.annotation.Scope;
import org.zkoss.ganttz.IPredicate; import org.zkoss.ganttz.IPredicate;
import org.zkoss.ganttz.Planner; import org.zkoss.ganttz.Planner;
import org.zkoss.ganttz.extensions.ICommandOnTask; import org.zkoss.ganttz.extensions.ICommandOnTask;
import org.zkoss.ganttz.resourceload.ScriptsRequiredByResourceLoadPanel;
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel; import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.script.IScriptsRegister;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.WrongValueException;
@ -92,12 +89,6 @@ public class CompanyPlanningController implements Composer {
private MultipleTabsPlannerController tabsController; private MultipleTabsPlannerController tabsController;
public CompanyPlanningController() { public CompanyPlanningController() {
getScriptsRegister().register(ScriptsRequiredByResourceLoadPanel.class);
}
private IScriptsRegister getScriptsRegister() {
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class)
.retrieve();
} }
private Combobox cbProgressTypes; private Combobox cbProgressTypes;

View file

@ -25,7 +25,6 @@ import static org.navalplanner.web.I18nHelper._;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -41,7 +40,6 @@ import org.navalplanner.web.common.components.finders.FilterPair;
import org.navalplanner.web.orders.OrderCRUDController; import org.navalplanner.web.orders.OrderCRUDController;
import org.navalplanner.web.orders.OrderElementPredicate; import org.navalplanner.web.orders.OrderElementPredicate;
import org.navalplanner.web.planner.advances.AdvanceAssignmentPlanningController; import org.navalplanner.web.planner.advances.AdvanceAssignmentPlanningController;
import org.navalplanner.web.planner.allocation.ResourceAllocationController;
import org.navalplanner.web.planner.calendar.CalendarAllocationController; import org.navalplanner.web.planner.calendar.CalendarAllocationController;
import org.navalplanner.web.planner.consolidations.AdvanceConsolidationController; import org.navalplanner.web.planner.consolidations.AdvanceConsolidationController;
import org.navalplanner.web.planner.taskedition.EditTaskController; import org.navalplanner.web.planner.taskedition.EditTaskController;
@ -56,12 +54,10 @@ import org.zkoss.ganttz.extensions.ContextWithPlannerTask;
import org.zkoss.ganttz.extensions.ICommand; import org.zkoss.ganttz.extensions.ICommand;
import org.zkoss.ganttz.extensions.IContext; import org.zkoss.ganttz.extensions.IContext;
import org.zkoss.ganttz.extensions.IContextWithPlannerTask; import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
import org.zkoss.ganttz.resourceload.ScriptsRequiredByResourceLoadPanel;
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel; import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.LongOperationFeedback; import org.zkoss.ganttz.util.LongOperationFeedback;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation; import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation;
import org.zkoss.ganttz.util.script.IScriptsRegister; import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.util.Composer; import org.zkoss.zk.ui.util.Composer;
@ -115,13 +111,6 @@ public class OrderPlanningController implements Composer {
private Textbox filterNameOrderElement; private Textbox filterNameOrderElement;
public OrderPlanningController() { public OrderPlanningController() {
getScriptsRegister().register(ScriptsRequiredByResourceLoadPanel.class);
ResourceAllocationController.registerNeededScripts();
}
private IScriptsRegister getScriptsRegister() {
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class)
.retrieve();
} }
public List<org.navalplanner.business.planner.entities.TaskElement> getCriticalPath() { public List<org.navalplanner.business.planner.entities.TaskElement> getCriticalPath() {

View file

@ -50,8 +50,6 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
<north border="none"> <north border="none">
<n:div> <n:div>
<scripts />
<n:table width="100%" border="0" cellpadding="0" cellspacing="0"> <n:table width="100%" border="0" cellpadding="0" cellspacing="0">
<n:tr> <n:tr>
<n:td width="180" valign="center"> <n:td width="180" valign="center">