The Unified and Autonomous Development Platform
Add error page
robin shinef81b118cdd21
diff --git a/commons.git/src/main/java/com/pmease/commons/git/FileEdit.java b/commons.git/src/main/java/com/pmease/commons/git/FileEdit.javaindex 36f0cfa2c2..4d8dc864fd 100644--- a/commons.git/src/main/java/com/pmease/commons/git/FileEdit.java+++ b/commons.git/src/main/java/com/pmease/commons/git/FileEdit.java@@ -24,10 +24,10 @@ import org.eclipse.jgit.treewalk.TreeWalk;import com.google.common.base.Preconditions;import com.google.common.base.Splitter;-import com.pmease.commons.git.exception.NotFileException;-import com.pmease.commons.git.exception.NotTreeException;-import com.pmease.commons.git.exception.ObjectAlreadyExistException;-import com.pmease.commons.git.exception.ObjectNotExistException;+import com.pmease.commons.git.exception.NotGitFileException;+import com.pmease.commons.git.exception.NotGitTreeException;+import com.pmease.commons.git.exception.GitObjectAlreadyExistsException;+import com.pmease.commons.git.exception.GitObjectNotFoundException;import com.pmease.commons.git.exception.ObsoleteCommitException;public class FileEdit implements Serializable {@@ -69,7 +69,7 @@ public class FileEdit implements Serializable {entries.add(new TreeFormatterEntry(name, newFileMode, blobId));}} else if (name.equals(currentNewPath)) {- throw new ObjectAlreadyExistException("Path already exist: " + treeWalk.getPathString());+ throw new GitObjectAlreadyExistsException("Path already exist: " + treeWalk.getPathString());} else if (currentOldPath != null && currentOldPath.startsWith(name + "/")) {TreeWalk childTreeWalk = TreeWalk.forPath(treeWalk.getObjectReader(), treeWalk.getPathString(), revTree);Preconditions.checkNotNull(childTreeWalk);@@ -88,7 +88,7 @@ public class FileEdit implements Serializable {entries.add(new TreeFormatterEntry(name, FileMode.TREE, childTreeId));} else if (currentNewPath != null && currentNewPath.startsWith(name + "/")) {if ((treeWalk.getFileMode(0).getBits() & FileMode.TYPE_TREE) == 0)- throw new NotTreeException("Path does not represent a tree: " + treeWalk.getPathString());+ throw new NotGitTreeException("Path does not represent a tree: " + treeWalk.getPathString());newPathFound = true;TreeWalk childTreeWalk = TreeWalk.forPath(treeWalk.getObjectReader(),treeWalk.getPathString(), revTree);@@ -162,9 +162,9 @@ public class FileEdit implements Serializable {* if expected old commit id of the ref does not equal to* expectedOldCommitId, or if expectedOldCommitId is specified as <tt>null</tt> and* ref exists- * @throws ObjectNotExistException+ * @throws GitObjectNotFoundException* if file to delete does not exist when oldPath!=null&&newFile==null- * @throws ObjectAlreadyExistException+ * @throws GitObjectAlreadyExistsException* if added/renamed file already exists when newFile!=null && (oldPath==null || !oldPath.equals(newFile.getPath()))**/@@ -190,11 +190,11 @@ public class FileEdit implements Serializable {if (oldPath != null) {TreeWalk oldPathTreeWalk = TreeWalk.forPath(repository, oldPath, revTree);if (oldPathTreeWalk == null)- throw new ObjectNotExistException("Path not exist: " + oldPath);+ throw new GitObjectNotFoundException("Path not exist: " + oldPath);newFileMode = oldPathTreeWalk.getFileMode(0);if ((newFileMode.getBits() & FileMode.TYPE_FILE) == 0)- throw new NotFileException("Path does not represent a file: " + oldPath);+ throw new NotGitFileException("Path does not represent a file: " + oldPath);} else {newFileMode = FileMode.REGULAR_FILE;}diff --git a/commons.git/src/main/java/com/pmease/commons/git/exception/GitObjectAlreadyExistsException.java b/commons.git/src/main/java/com/pmease/commons/git/exception/GitObjectAlreadyExistsException.javanew file mode 100644index 0000000000..9a8225f68c--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/exception/GitObjectAlreadyExistsException.java@@ -0,0 +1,11 @@+package com.pmease.commons.git.exception;++public class GitObjectAlreadyExistsException extends GitException {++ private static final long serialVersionUID = 1L;++ public GitObjectAlreadyExistsException(String message) {+ super(message);+ }++}diff --git a/commons.git/src/main/java/com/pmease/commons/git/exception/ObjectNotExistException.java b/commons.git/src/main/java/com/pmease/commons/git/exception/GitObjectNotFoundException.javasimilarity index 50%rename from commons.git/src/main/java/com/pmease/commons/git/exception/ObjectNotExistException.javarename to commons.git/src/main/java/com/pmease/commons/git/exception/GitObjectNotFoundException.javaindex b2585d029a..67218645b1 100644--- a/commons.git/src/main/java/com/pmease/commons/git/exception/ObjectNotExistException.java+++ b/commons.git/src/main/java/com/pmease/commons/git/exception/GitObjectNotFoundException.java@@ -1,10 +1,10 @@package com.pmease.commons.git.exception;-public class ObjectNotExistException extends GitException {+public class GitObjectNotFoundException extends GitException {private static final long serialVersionUID = 1L;- public ObjectNotExistException(String message) {+ public GitObjectNotFoundException(String message) {super(message);}diff --git a/commons.git/src/main/java/com/pmease/commons/git/exception/NotFileException.java b/commons.git/src/main/java/com/pmease/commons/git/exception/NotGitFileException.javasimilarity index 54%rename from commons.git/src/main/java/com/pmease/commons/git/exception/NotFileException.javarename to commons.git/src/main/java/com/pmease/commons/git/exception/NotGitFileException.javaindex 96948fe239..62ac01911f 100644--- a/commons.git/src/main/java/com/pmease/commons/git/exception/NotFileException.java+++ b/commons.git/src/main/java/com/pmease/commons/git/exception/NotGitFileException.java@@ -1,10 +1,10 @@package com.pmease.commons.git.exception;-public class NotFileException extends GitException {+public class NotGitFileException extends GitException {private static final long serialVersionUID = 1L;- public NotFileException(String message) {+ public NotGitFileException(String message) {super(message);}diff --git a/commons.git/src/main/java/com/pmease/commons/git/exception/NotTreeException.java b/commons.git/src/main/java/com/pmease/commons/git/exception/NotGitTreeException.javasimilarity index 54%rename from commons.git/src/main/java/com/pmease/commons/git/exception/NotTreeException.javarename to commons.git/src/main/java/com/pmease/commons/git/exception/NotGitTreeException.javaindex 88dfcdb1d6..09acbf6971 100644--- a/commons.git/src/main/java/com/pmease/commons/git/exception/NotTreeException.java+++ b/commons.git/src/main/java/com/pmease/commons/git/exception/NotGitTreeException.java@@ -1,10 +1,10 @@package com.pmease.commons.git.exception;-public class NotTreeException extends GitException {+public class NotGitTreeException extends GitException {private static final long serialVersionUID = 1L;- public NotTreeException(String message) {+ public NotGitTreeException(String message) {super(message);}diff --git a/commons.git/src/main/java/com/pmease/commons/git/exception/ObjectAlreadyExistException.java b/commons.git/src/main/java/com/pmease/commons/git/exception/ObjectAlreadyExistException.javadeleted file mode 100644index 821437bc39..0000000000--- a/commons.git/src/main/java/com/pmease/commons/git/exception/ObjectAlreadyExistException.java+++ /dev/null@@ -1,11 +0,0 @@-package com.pmease.commons.git.exception;--public class ObjectAlreadyExistException extends GitException {-- private static final long serialVersionUID = 1L;-- public ObjectAlreadyExistException(String message) {- super(message);- }--}diff --git a/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.java b/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.javaindex 04e40d641b..0ba80b0f1f 100644--- a/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.java+++ b/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.java@@ -12,10 +12,10 @@ import org.eclipse.jgit.revwalk.RevWalk;import org.eclipse.jgit.treewalk.TreeWalk;import org.junit.Test;-import com.pmease.commons.git.exception.NotFileException;-import com.pmease.commons.git.exception.NotTreeException;-import com.pmease.commons.git.exception.ObjectAlreadyExistException;-import com.pmease.commons.git.exception.ObjectNotExistException;+import com.pmease.commons.git.exception.NotGitFileException;+import com.pmease.commons.git.exception.NotGitTreeException;+import com.pmease.commons.git.exception.GitObjectAlreadyExistsException;+import com.pmease.commons.git.exception.GitObjectNotFoundException;import com.pmease.commons.git.exception.ObsoleteCommitException;public class FileEditTest extends AbstractGitTest {@@ -64,7 +64,7 @@ public class FileEditTest extends AbstractGitTest {try {edit.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test delete");assertTrue("An ObjectNotExistException should be thrown", false);- } catch (ObjectNotExistException e) {+ } catch (GitObjectNotFoundException e) {}}@@ -114,7 +114,7 @@ public class FileEditTest extends AbstractGitTest {try {edit.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename tree");assertTrue("A NotFileException should be thrown", false);- } catch (NotFileException e) {+ } catch (NotGitFileException e) {}}@@ -137,7 +137,7 @@ public class FileEditTest extends AbstractGitTest {try {edit.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename tree");assertTrue("A NotTreeException should be thrown", false);- } catch (NotTreeException e) {+ } catch (NotGitTreeException e) {}}@@ -200,7 +200,7 @@ public class FileEditTest extends AbstractGitTest {try {edit.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename tree");assertTrue("An ObjectAlreadyExistException should be thrown", false);- } catch (ObjectAlreadyExistException e) {+ } catch (GitObjectAlreadyExistsException e) {}}diff --git a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/DefaultPersistService.java b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/DefaultPersistService.javaindex 3a363b8eee..3f70cf34b3 100644--- a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/DefaultPersistService.java+++ b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/DefaultPersistService.java@@ -1,83 +1,89 @@-package com.pmease.commons.hibernate;--import java.util.Properties;-import java.util.Set;--import javax.annotation.Nullable;-import javax.inject.Named;--import org.hibernate.Interceptor;-import org.hibernate.SessionFactory;-import org.hibernate.boot.Metadata;-import org.hibernate.boot.MetadataSources;-import org.hibernate.boot.model.naming.PhysicalNamingStrategy;-import org.hibernate.boot.registry.StandardServiceRegistry;-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;--import com.google.common.base.Preconditions;-import com.google.inject.Inject;-import com.google.inject.Provider;-import com.google.inject.Singleton;-import com.pmease.commons.util.ClassUtils;--@Singleton-public class DefaultPersistService implements PersistService, Provider<SessionFactory> {-- private final Set<ModelProvider> modelProviders;-- private final PhysicalNamingStrategy physicalNamingStrategy;-- private final Properties properties;-- private final Interceptor interceptor;-- private volatile SessionFactory sessionFactory;-- @Inject- public DefaultPersistService(Set<ModelProvider> modelProviders, PhysicalNamingStrategy physicalNamingStrategy,- @Nullable @Named("hibernate") Properties properties, Interceptor interceptor) {- this.modelProviders = modelProviders;- this.physicalNamingStrategy = physicalNamingStrategy;- this.properties = properties;- this.interceptor = interceptor;- }-- @Override- public void start() {- Preconditions.checkState(sessionFactory == null);-- StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()- .applySettings(properties).build();-- MetadataSources metadataSources = new MetadataSources(standardRegistry);- for (Class<? extends AbstractEntity> each: ClassUtils.findImplementations(AbstractEntity.class, AbstractEntity.class)) {- metadataSources.addAnnotatedClass(each);- }-- for (ModelProvider provider: modelProviders) {- for (Class<? extends AbstractEntity> modelClass: provider.getModelClasses())- metadataSources.addAnnotatedClass(modelClass);- }-- Metadata metadata = metadataSources.getMetadataBuilder()- .applyPhysicalNamingStrategy(physicalNamingStrategy)- .build();- sessionFactory = metadata.getSessionFactoryBuilder().applyInterceptor(interceptor).build();- }-- @Override- public void stop() {- if (sessionFactory != null) {- Preconditions.checkState(!sessionFactory.isClosed());- sessionFactory.close();- sessionFactory = null;- }- }-- @Override- public SessionFactory get() {- Preconditions.checkNotNull(sessionFactory, "Persist service is either not started or is not configured.");- return sessionFactory;- }--}+package com.pmease.commons.hibernate;++import java.util.Properties;+import java.util.Set;++import javax.annotation.Nullable;+import javax.inject.Named;++import org.hibernate.Interceptor;+import org.hibernate.SessionFactory;+import org.hibernate.boot.Metadata;+import org.hibernate.boot.MetadataSources;+import org.hibernate.boot.model.naming.PhysicalNamingStrategy;+import org.hibernate.boot.registry.StandardServiceRegistry;+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;++import com.google.common.base.Preconditions;+import com.google.inject.Inject;+import com.google.inject.Provider;+import com.google.inject.Singleton;+import com.pmease.commons.util.ClassUtils;++@Singleton+public class DefaultPersistService implements PersistService, Provider<SessionFactory> {++ private final Set<ModelProvider> modelProviders;++ private final PhysicalNamingStrategy physicalNamingStrategy;++ private final Properties properties;++ private final Interceptor interceptor;++ private volatile SessionFactory sessionFactory;++ @Inject+ public DefaultPersistService(Set<ModelProvider> modelProviders, PhysicalNamingStrategy physicalNamingStrategy,+ @Nullable @Named("hibernate") Properties properties, Interceptor interceptor) {+ this.modelProviders = modelProviders;+ this.physicalNamingStrategy = physicalNamingStrategy;+ this.properties = properties;+ this.interceptor = interceptor;+ }++ @Override+ public void start() {+ Preconditions.checkState(sessionFactory == null);++ StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()+ .applySettings(properties).build();++ MetadataSources metadataSources = new MetadataSources(standardRegistry);+ for (Class<? extends AbstractEntity> each: ClassUtils.findImplementations(AbstractEntity.class, AbstractEntity.class)) {+ metadataSources.addAnnotatedClass(each);+ }++ for (ModelProvider provider: modelProviders) {+ for (Class<? extends AbstractEntity> modelClass: provider.getModelClasses())+ metadataSources.addAnnotatedClass(modelClass);+ }++ Metadata metadata = metadataSources.getMetadataBuilder()+ .applyPhysicalNamingStrategy(physicalNamingStrategy)+ .build();+ sessionFactory = metadata.getSessionFactoryBuilder().applyInterceptor(interceptor).build();+ }++ @Override+ public void stop() {+ if (sessionFactory != null) {+ Preconditions.checkState(!sessionFactory.isClosed());+ sessionFactory.close();+ sessionFactory = null;+ }+ }++ @Override+ public SessionFactory get() {+ if (sessionFactory == null)+ throw new RuntimeException("Persist service is either not started or is not configured.");+ return sessionFactory;+ }++ @Override+ public boolean isReady() {+ return sessionFactory != null;+ }++}diff --git a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/HibernateFilter.java b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/HibernateFilter.javaindex faefb08cd8..af66f5dbc1 100644--- a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/HibernateFilter.java+++ b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/HibernateFilter.java@@ -17,9 +17,12 @@ public class HibernateFilter implements Filter {private final UnitOfWork unitOfWork;+ private final PersistService persistService;+@Inject- public HibernateFilter(UnitOfWork unitOfWork) {+ public HibernateFilter(UnitOfWork unitOfWork, PersistService persistService) {this.unitOfWork = unitOfWork;+ this.persistService = persistService;}public void destroy() {@@ -27,11 +30,15 @@ public class HibernateFilter implements Filter {public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {- unitOfWork.begin();- try {+ if (persistService.isReady()) {+ unitOfWork.begin();+ try {+ chain.doFilter(request, response);+ } finally {+ unitOfWork.end();+ }+ } else {chain.doFilter(request, response);- } finally {- unitOfWork.end();}}diff --git a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/PersistService.java b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/PersistService.javaindex 38d8b96acc..dd1f72be99 100644--- a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/PersistService.java+++ b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/PersistService.java@@ -1,8 +1,11 @@-package com.pmease.commons.hibernate;--public interface PersistService {-- void start();-- void stop();-}+package com.pmease.commons.hibernate;++public interface PersistService {++ void start();++ void stop();++ boolean isReady();++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/ajaxlistener/IndicateWorkingListener.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/ajaxlistener/IndicateWorkingListener.javaindex 64082461db..884dd1cfb4 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/ajaxlistener/IndicateWorkingListener.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/ajaxlistener/IndicateWorkingListener.java@@ -1,84 +1,85 @@-package com.pmease.commons.wicket.ajaxlistener;--import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;-import org.apache.wicket.ajax.attributes.IAjaxCallListener;-import org.apache.wicket.request.IRequestHandler;-import org.apache.wicket.request.cycle.RequestCycle;-import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;--/**- * Show global ajax loading indicator right away instead of using a timer.- * This is useful in cases when loading a large page to cause timeout- * callback not being able to be executed due to browser being busy.- *- * @author robin- *- */-public class IndicateWorkingListener implements IAjaxCallListener {-- private final boolean indicateSuccessful;-- public IndicateWorkingListener(boolean indicateSuccessful) {- this.indicateSuccessful = indicateSuccessful;- }-- @Override- public CharSequence getBeforeHandler(Component component) {- return null;- }-- @Override- public CharSequence getPrecondition(Component component) {- return null;- }-- @Override- public CharSequence getBeforeSendHandler(Component component) {- IRequestHandler handler = new ResourceReferenceRequestHandler(- AbstractDefaultAjaxBehavior.INDICATOR);- CharSequence url = RequestCycle.get().urlFor(handler);- return String.format(""- + "$('#%s-working-indicator').remove(); "- + "$('#%s').after('<img id=\"%s-working-indicator\" src=\"%s\" class=\"working-indicator\"></img>');",- component.getMarkupId(), component.getMarkupId(), component.getMarkupId(), url);- }-- @Override- public CharSequence getAfterHandler(Component component) {- return null;- }-- @Override- public CharSequence getSuccessHandler(Component component) {- if (indicateSuccessful) {- return String.format(""- + "$('#%s-working-indicator').remove();"- + "$('#%s').after('<span id=\"%s-working-indicator\" class=\"fa fa-check working-indicator\"></span>');",- component.getMarkupId(), component.getMarkupId(), component.getMarkupId());- } else {- return String.format("$('#%s-working-indicator').remove();", component.getMarkupId());- }- }-- @Override- public CharSequence getFailureHandler(Component component) {- return null;- }-- @Override- public CharSequence getCompleteHandler(Component component) {- return null;- }-- @Override- public CharSequence getInitHandler(Component component) {- return null;- }-- @Override- public CharSequence getDoneHandler(Component component) {- return null;- }--}+package com.pmease.commons.wicket.ajaxlistener;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.attributes.IAjaxCallListener;+import org.apache.wicket.request.IRequestHandler;+import org.apache.wicket.request.cycle.RequestCycle;+import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;++import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;++/**+ * Show global ajax loading indicator right away instead of using a timer.+ * This is useful in cases when loading a large page to cause timeout+ * callback not being able to be executed due to browser being busy.+ *+ * @author robin+ *+ */+public class IndicateWorkingListener implements IAjaxCallListener {++ private final boolean indicateSuccessful;++ public IndicateWorkingListener(boolean indicateSuccessful) {+ this.indicateSuccessful = indicateSuccessful;+ }++ @Override+ public CharSequence getBeforeHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getPrecondition(Component component) {+ return null;+ }++ @Override+ public CharSequence getBeforeSendHandler(Component component) {+ IRequestHandler handler = new ResourceReferenceRequestHandler(+ AbstractPostAjaxBehavior.INDICATOR);+ CharSequence url = RequestCycle.get().urlFor(handler);+ return String.format(""+ + "$('#%s-working-indicator').remove(); "+ + "$('#%s').after('<img id=\"%s-working-indicator\" src=\"%s\" class=\"working-indicator\"></img>');",+ component.getMarkupId(), component.getMarkupId(), component.getMarkupId(), url);+ }++ @Override+ public CharSequence getAfterHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getSuccessHandler(Component component) {+ if (indicateSuccessful) {+ return String.format(""+ + "$('#%s-working-indicator').remove();"+ + "$('#%s').after('<span id=\"%s-working-indicator\" class=\"fa fa-check working-indicator\"></span>');",+ component.getMarkupId(), component.getMarkupId(), component.getMarkupId());+ } else {+ return String.format("$('#%s-working-indicator').remove();", component.getMarkupId());+ }+ }++ @Override+ public CharSequence getFailureHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getCompleteHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getInitHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getDoneHandler(Component component) {+ return null;+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/AbstractPostAjaxBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/AbstractPostAjaxBehavior.javanew file mode 100644index 0000000000..398f945afa--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/AbstractPostAjaxBehavior.java@@ -0,0 +1,17 @@+package com.pmease.commons.wicket.behavior;++import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;++public abstract class AbstractPostAjaxBehavior extends AbstractDefaultAjaxBehavior {++ private static final long serialVersionUID = 1L;++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.setMethod(Method.POST);+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/RunTaskBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/RunTaskBehavior.javaindex a8c5df5fce..c342d31f0a 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/RunTaskBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/RunTaskBehavior.java@@ -1,10 +1,9 @@package com.pmease.commons.wicket.behavior;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;@SuppressWarnings("serial")-public abstract class RunTaskBehavior extends AbstractDefaultAjaxBehavior {+public abstract class RunTaskBehavior extends AbstractPostAjaxBehavior {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.javaindex 91b7e045e8..a7d2e036ec 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.java@@ -1,31 +1,31 @@-package com.pmease.commons.wicket.behavior;--import org.apache.wicket.Component;-import org.apache.wicket.behavior.Behavior;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.head.JavaScriptHeaderItem;-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;--import com.pmease.commons.wicket.assets.uri.URIResourceReference;--@SuppressWarnings("serial")-public class ViewStateAwareBehavior extends Behavior {-- @Override- public void renderHead(Component component, IHeaderResponse response) {- super.renderHead(component, response);-- response.render(JavaScriptHeaderItem.forReference(new URIResourceReference()));- String script = String.format(""- + "var viewState = pmease.commons.history.getViewState();"- + "if (viewState) {"- + " var link = document.getElementById('%s');"- + " var uri = new URI(link);"- + " uri.removeSearch('view_state');"- + " uri.addSearch('view_state', JSON.stringify(viewState));"- + " $(link).attr('href', uri.href());"- + "}", component.getMarkupId(true));- response.render(OnDomReadyHeaderItem.forScript(script));- }--}+package com.pmease.commons.wicket.behavior;++import org.apache.wicket.Component;+import org.apache.wicket.behavior.Behavior;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.JavaScriptHeaderItem;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;++import com.pmease.commons.wicket.assets.uri.URIResourceReference;++@SuppressWarnings("serial")+public class ViewStateAwareBehavior extends Behavior {++ @Override+ public void renderHead(Component component, IHeaderResponse response) {+ super.renderHead(component, response);++ response.render(JavaScriptHeaderItem.forReference(new URIResourceReference()));+ String script = String.format(""+ + "var viewState = pmease.commons.history.getViewState();"+ + "if (viewState) {"+ + " var link = document.getElementById('%s');"+ + " var uri = new URI(link);"+ + " uri.removeSearch('view_state');"+ + " uri.addSearch('view_state', JSON.stringify(viewState));"+ + " $(link).attr('href', uri.href());"+ + "}", component.getMarkupId(true));+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dropdown/DropdownHover.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dropdown/DropdownHover.javaindex 66ed401d92..732f6d0bbb 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dropdown/DropdownHover.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dropdown/DropdownHover.java@@ -3,19 +3,19 @@ package com.pmease.commons.wicket.behavior.dropdown;import javax.annotation.Nullable;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptHeaderItem;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.request.cycle.RequestCycle;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.component.floating.AlignPlacement;import com.pmease.commons.wicket.component.floating.ComponentTarget;import com.pmease.commons.wicket.component.floating.FloatingPanel;@SuppressWarnings("serial")-public abstract class DropdownHover extends AbstractDefaultAjaxBehavior {+public abstract class DropdownHover extends AbstractPostAjaxBehavior {private static final int DEFAULT_HOVER_DELAY = 350;diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.javaindex 23bebbbf9c..ac4ad40e3d 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.java@@ -1,118 +1,118 @@-package com.pmease.commons.wicket.behavior.inputassist;--import java.util.List;--import org.apache.commons.lang3.StringEscapeUtils;-import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;-import org.apache.wicket.markup.html.WebMarkupContainer;-import org.apache.wicket.markup.html.basic.Label;-import org.apache.wicket.markup.html.panel.Panel;-import org.apache.wicket.markup.repeater.RepeatingView;--import com.pmease.commons.antlr.codeassist.InputCompletion;-import com.pmease.commons.antlr.codeassist.InputStatus;-import com.pmease.commons.util.Range;--@SuppressWarnings("serial")-class AssistPanel extends Panel {-- private final InputAssistBehavior assistBehavior;-- private final InputStatus inputStatus;-- private List<InputCompletion> suggestions;-- private List<String> hints;-- private RepeatingView suggestionsView;-- private int page = 1;-- public AssistPanel(String id, InputAssistBehavior assistBehavior, InputStatus inputStatus,- List<InputCompletion> suggestions, List<String> hints) {- super(id);- this.assistBehavior = assistBehavior;- this.inputStatus = inputStatus;- this.suggestions = suggestions;- this.hints = hints;- }-- @Override- protected void onInitialize() {- super.onInitialize();-- suggestionsView = new RepeatingView("suggestions");- add(suggestionsView);- for (InputCompletion suggestion: suggestions)- suggestionsView.add(newSuggestionItem(suggestionsView.newChildId(), suggestion));-- RepeatingView hintsView = new RepeatingView("hints");- add(hintsView);- for (String hint: hints)- hintsView.add(new Label(hintsView.newChildId(), hint).setEscapeModelStrings(false));-- add(new AbstractDefaultAjaxBehavior() {-- @Override- protected void respond(AjaxRequestTarget target) {- List<InputCompletion> suggestions = assistBehavior.getSuggestions(inputStatus, (++page)*InputAssistBehavior.PAGE_SIZE);- if (suggestions.size() > AssistPanel.this.suggestions.size()) {- List<InputCompletion> additionalSuggestions =- suggestions.subList(AssistPanel.this.suggestions.size(), suggestions.size());- for (InputCompletion suggestion: additionalSuggestions) {- Component suggestionItem = newSuggestionItem(suggestionsView.newChildId(), suggestion);- suggestionsView.add(suggestionItem);- String script = String.format("$('#%s .suggestions>table>tbody').append('<tr id=\"%s\"></tr>');",- AssistPanel.this.getMarkupId(), suggestionItem.getMarkupId());- target.prependJavaScript(script);- target.add(suggestionItem);- script = String.format("$('#%s').click(function() {$('#%s').data('update')($(this));});",- suggestionItem.getMarkupId(), assistBehavior.getInputField().getMarkupId());- target.appendJavaScript(script);- }- AssistPanel.this.suggestions = suggestions;- }- }-- @Override- public void renderHead(Component component, IHeaderResponse response) {- super.renderHead(component, response);- String script = String.format("pmease.commons.inputassist.initInfiniteScroll('%s', %s);",- getMarkupId(true), getCallbackFunction());- response.render(OnDomReadyHeaderItem.forScript(script));- }-- });- setOutputMarkupId(true);- }-- private Component newSuggestionItem(String itemId, InputCompletion suggestion) {- WebMarkupContainer item = new WebMarkupContainer(itemId);- WebMarkupContainer link = new WebMarkupContainer("link");- Range matchRange = suggestion.getMatchRange();- String label = suggestion.getLabel();- if (matchRange != null) {- String prefix = StringEscapeUtils.escapeHtml4(label.substring(0, matchRange.getFrom()));- String suffix = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getTo()));- String matched = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getFrom(), matchRange.getTo()));- link.add(new Label("label", prefix + "<b>" + matched + "</b>" + suffix).setEscapeModelStrings(false));- } else {- link.add(new Label("label", label));- }- item.add(link);- if (suggestion.getDescription() != null)- item.add(new Label("description", suggestion.getDescription()));- else- item.add(new Label("description").setVisible(false));- item.add(AttributeAppender.append("data-content", suggestion.complete(inputStatus).getContent()));- item.add(AttributeAppender.append("data-caret", suggestion.getCaret()));- item.setOutputMarkupId(true);- return item;- }--}+package com.pmease.commons.wicket.behavior.inputassist;++import java.util.List;++import org.apache.commons.lang3.StringEscapeUtils;+import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.markup.repeater.RepeatingView;++import com.pmease.commons.antlr.codeassist.InputCompletion;+import com.pmease.commons.antlr.codeassist.InputStatus;+import com.pmease.commons.util.Range;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;++@SuppressWarnings("serial")+class AssistPanel extends Panel {++ private final InputAssistBehavior assistBehavior;++ private final InputStatus inputStatus;++ private List<InputCompletion> suggestions;++ private List<String> hints;++ private RepeatingView suggestionsView;++ private int page = 1;++ public AssistPanel(String id, InputAssistBehavior assistBehavior, InputStatus inputStatus,+ List<InputCompletion> suggestions, List<String> hints) {+ super(id);+ this.assistBehavior = assistBehavior;+ this.inputStatus = inputStatus;+ this.suggestions = suggestions;+ this.hints = hints;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ suggestionsView = new RepeatingView("suggestions");+ add(suggestionsView);+ for (InputCompletion suggestion: suggestions)+ suggestionsView.add(newSuggestionItem(suggestionsView.newChildId(), suggestion));++ RepeatingView hintsView = new RepeatingView("hints");+ add(hintsView);+ for (String hint: hints)+ hintsView.add(new Label(hintsView.newChildId(), hint).setEscapeModelStrings(false));++ add(new AbstractPostAjaxBehavior() {++ @Override+ protected void respond(AjaxRequestTarget target) {+ List<InputCompletion> suggestions = assistBehavior.getSuggestions(inputStatus, (++page)*InputAssistBehavior.PAGE_SIZE);+ if (suggestions.size() > AssistPanel.this.suggestions.size()) {+ List<InputCompletion> additionalSuggestions =+ suggestions.subList(AssistPanel.this.suggestions.size(), suggestions.size());+ for (InputCompletion suggestion: additionalSuggestions) {+ Component suggestionItem = newSuggestionItem(suggestionsView.newChildId(), suggestion);+ suggestionsView.add(suggestionItem);+ String script = String.format("$('#%s .suggestions>table>tbody').append('<tr id=\"%s\"></tr>');",+ AssistPanel.this.getMarkupId(), suggestionItem.getMarkupId());+ target.prependJavaScript(script);+ target.add(suggestionItem);+ script = String.format("$('#%s').click(function() {$('#%s').data('update')($(this));});",+ suggestionItem.getMarkupId(), assistBehavior.getInputField().getMarkupId());+ target.appendJavaScript(script);+ }+ AssistPanel.this.suggestions = suggestions;+ }+ }++ @Override+ public void renderHead(Component component, IHeaderResponse response) {+ super.renderHead(component, response);+ String script = String.format("pmease.commons.inputassist.initInfiniteScroll('%s', %s);",+ getMarkupId(true), getCallbackFunction());+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ });+ setOutputMarkupId(true);+ }++ private Component newSuggestionItem(String itemId, InputCompletion suggestion) {+ WebMarkupContainer item = new WebMarkupContainer(itemId);+ WebMarkupContainer link = new WebMarkupContainer("link");+ Range matchRange = suggestion.getMatchRange();+ String label = suggestion.getLabel();+ if (matchRange != null) {+ String prefix = StringEscapeUtils.escapeHtml4(label.substring(0, matchRange.getFrom()));+ String suffix = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getTo()));+ String matched = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getFrom(), matchRange.getTo()));+ link.add(new Label("label", prefix + "<b>" + matched + "</b>" + suffix).setEscapeModelStrings(false));+ } else {+ link.add(new Label("label", label));+ }+ item.add(link);+ if (suggestion.getDescription() != null)+ item.add(new Label("description", suggestion.getDescription()));+ else+ item.add(new Label("description").setVisible(false));+ item.add(AttributeAppender.append("data-content", suggestion.complete(inputStatus).getContent()));+ item.add(AttributeAppender.append("data-caret", suggestion.getCaret()));+ item.setOutputMarkupId(true);+ return item;+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.javaindex 7ba15beb52..4918cd4407 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java@@ -6,7 +6,6 @@ import java.util.ArrayList;import java.util.List;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxChannel;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;@@ -25,13 +24,14 @@ import com.pmease.commons.antlr.codeassist.InputStatus;import com.pmease.commons.loader.AppLoader;import com.pmease.commons.util.Range;import com.pmease.commons.util.RangeUtils;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.component.floating.AlignPlacement;import com.pmease.commons.wicket.component.floating.AlignTarget;import com.pmease.commons.wicket.component.floating.ComponentTarget;import com.pmease.commons.wicket.component.floating.FloatingPanel;@SuppressWarnings("serial")-public abstract class InputAssistBehavior extends AbstractDefaultAjaxBehavior {+public abstract class InputAssistBehavior extends AbstractPostAjaxBehavior {static final int PAGE_SIZE = 25;diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/markdown/MarkdownBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/markdown/MarkdownBehavior.javaindex 4e9c9fd43d..9a396c1e11 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/markdown/MarkdownBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/markdown/MarkdownBehavior.java@@ -15,7 +15,6 @@ import org.apache.commons.lang3.SerializationUtils;import org.apache.commons.lang3.StringEscapeUtils;import org.apache.commons.lang3.StringUtils;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;@@ -34,10 +33,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;import com.google.common.base.Charsets;import com.pmease.commons.loader.AppLoader;import com.pmease.commons.markdown.MarkdownManager;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.page.CommonPage;@SuppressWarnings("serial")-public class MarkdownBehavior extends AbstractDefaultAjaxBehavior {+public class MarkdownBehavior extends AbstractPostAjaxBehavior {protected static final int ATWHO_LIMIT = 5;diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/sortable/SortBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/sortable/SortBehavior.javaindex 59014e7ae8..fd4bb68dd3 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/sortable/SortBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/sortable/SortBehavior.java@@ -2,7 +2,6 @@ package com.pmease.commons.wicket.behavior.sortable;import org.apache.wicket.Component;import org.apache.wicket.MarkupContainer;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.markup.head.IHeaderResponse;@@ -11,8 +10,9 @@ import org.apache.wicket.markup.head.OnLoadHeaderItem;import org.apache.wicket.request.cycle.RequestCycle;import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;-public abstract class SortBehavior extends AbstractDefaultAjaxBehavior {+public abstract class SortBehavior extends AbstractPostAjaxBehavior {private static final long serialVersionUID = 1L;diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/testform/TestFormBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/testform/TestFormBehavior.javaindex edbde4ae28..b89442c3a7 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/testform/TestFormBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/testform/TestFormBehavior.java@@ -1,11 +1,12 @@package com.pmease.commons.wicket.behavior.testform;import org.apache.commons.lang3.StringUtils;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;+@SuppressWarnings("serial")-public abstract class TestFormBehavior extends AbstractDefaultAjaxBehavior {+public abstract class TestFormBehavior extends AbstractPostAjaxBehavior {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.javaindex eafbbcbb7d..50bedbba17 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java@@ -1,151 +1,154 @@-package com.pmease.commons.wicket.component;--import org.apache.wicket.Component;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.markup.html.AjaxLink;-import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;-import org.apache.wicket.request.cycle.RequestCycle;--import com.pmease.commons.wicket.component.floating.AlignPlacement;-import com.pmease.commons.wicket.component.floating.AlignTarget;-import com.pmease.commons.wicket.component.floating.ComponentTarget;-import com.pmease.commons.wicket.component.floating.FloatingPanel;-import com.pmease.commons.wicket.component.floating.RectTarget;--@SuppressWarnings("serial")-public abstract class DropdownLink extends AjaxLink<Void> {-- private final boolean alignTargetMouse;-- private final AlignPlacement placement;-- private FloatingPanel dropdown;-- public DropdownLink(String id) {- this(id, AlignPlacement.bottom(0));- }-- public DropdownLink(String id, AlignPlacement placement) {- this(id, false, placement);- }-- public DropdownLink(String id, boolean alignTargetMouse) {- this(id, alignTargetMouse, AlignPlacement.bottom(0));- }-- public DropdownLink(String id, boolean alignTargetMouse, AlignPlacement placement) {- super(id);-- this.alignTargetMouse = alignTargetMouse;- this.placement = placement;- }-- @Override- protected void onInitialize() {- super.onInitialize();- add(AttributeAppender.append("class", "dropdown-link"));-- setOutputMarkupId(true);- }-- protected void onInitialize(FloatingPanel dropdown) {-- }-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);-- String script = String.format(""- + "return {mouseX: $('#%s').data('mouseX'), mouseY: $('#%s').data('mouseY')};",- getMarkupId(), getMarkupId());- attributes.getDynamicExtraParameters().add(script);- }-- @Override- public void onClick(AjaxRequestTarget target) {- // if dropdown has not been created, or has been removed from page- // when the same page instance is refreshed- if (dropdown == null || dropdown.getParent() == null) {- AlignTarget alignFloatingWith;- if (alignTargetMouse) {- int mouseX = RequestCycle.get().getRequest().getRequestParameters()- .getParameterValue("mouseX").toInt();- int mouseY = RequestCycle.get().getRequest().getRequestParameters()- .getParameterValue("mouseY").toInt();- alignFloatingWith = RectTarget.ofMouse(mouseX, mouseY);- } else {- alignFloatingWith = new ComponentTarget(this);- }-- dropdown = new FloatingPanel(target, alignFloatingWith, placement) {-- @Override- protected void onInitialize() {- super.onInitialize();- DropdownLink.this.onInitialize(this);- }-- @Override- protected Component newContent(String id) {- return DropdownLink.this.newContent(id);- }-- @Override- protected void onClosed() {- super.onClosed();-- AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);- if (target != null) {- String script = String.format("$('#%s').removeClass('dropdown-open');",- DropdownLink.this.getMarkupId(true));- target.appendJavaScript(script);- }-- dropdown = null;- }-- };- String script = String.format(""- + "$('#%s').addClass('dropdown-open');"- + "$('#%s').data('trigger', $('#%s'));",- getMarkupId(), dropdown.getMarkupId(), getMarkupId());- target.appendJavaScript(script);- } else {- dropdown.close();- }- }-- public void close() {- if (dropdown != null)- dropdown.close();- }-- public String getCloseScript() {- if (dropdown != null) {- return String.format("pmease.commons.floating.close($('#%s'), true);", dropdown.getMarkupId());- } else {- return "";- }- }-- public String closeBeforeClick(CharSequence onClickScript) {- return getCloseScript() + (onClickScript!=null?onClickScript:"");- }-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);-- String script = String.format(""- + "$('#%s').on('click', function(e){"- + " $(this).data('mouseX', e.pageX).data('mouseY', e.pageY);"- + "});", getMarkupId());- response.render(OnDomReadyHeaderItem.forScript(script));- }-- protected abstract Component newContent(String id);-}+package com.pmease.commons.wicket.component;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.request.cycle.RequestCycle;++import com.pmease.commons.wicket.component.floating.AlignPlacement;+import com.pmease.commons.wicket.component.floating.AlignTarget;+import com.pmease.commons.wicket.component.floating.ComponentTarget;+import com.pmease.commons.wicket.component.floating.FloatingPanel;+import com.pmease.commons.wicket.component.floating.RectTarget;++@SuppressWarnings("serial")+public abstract class DropdownLink extends AjaxLink<Void> {++ private final boolean alignTargetMouse;++ private final AlignPlacement placement;++ private FloatingPanel dropdown;++ public DropdownLink(String id) {+ this(id, AlignPlacement.bottom(0));+ }++ public DropdownLink(String id, AlignPlacement placement) {+ this(id, false, placement);+ }++ public DropdownLink(String id, boolean alignTargetMouse) {+ this(id, alignTargetMouse, AlignPlacement.bottom(0));+ }++ public DropdownLink(String id, boolean alignTargetMouse, AlignPlacement placement) {+ super(id);++ this.alignTargetMouse = alignTargetMouse;+ this.placement = placement;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();+ add(AttributeAppender.append("class", "dropdown-link"));++ setOutputMarkupId(true);+ }++ protected void onInitialize(FloatingPanel dropdown) {++ }++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);++ attributes.setMethod(Method.POST);++ String script = String.format(""+ + "return {mouseX: $('#%s').data('mouseX'), mouseY: $('#%s').data('mouseY')};",+ getMarkupId(), getMarkupId());+ attributes.getDynamicExtraParameters().add(script);+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ // if dropdown has not been created, or has been removed from page+ // when the same page instance is refreshed+ if (dropdown == null || dropdown.getParent() == null) {+ AlignTarget alignFloatingWith;+ if (alignTargetMouse) {+ int mouseX = RequestCycle.get().getRequest().getPostParameters()+ .getParameterValue("mouseX").toInt();+ int mouseY = RequestCycle.get().getRequest().getPostParameters()+ .getParameterValue("mouseY").toInt();+ alignFloatingWith = RectTarget.ofMouse(mouseX, mouseY);+ } else {+ alignFloatingWith = new ComponentTarget(this);+ }++ dropdown = new FloatingPanel(target, alignFloatingWith, placement) {++ @Override+ protected void onInitialize() {+ super.onInitialize();+ DropdownLink.this.onInitialize(this);+ }++ @Override+ protected Component newContent(String id) {+ return DropdownLink.this.newContent(id);+ }++ @Override+ protected void onClosed() {+ super.onClosed();++ AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);+ if (target != null) {+ String script = String.format("$('#%s').removeClass('dropdown-open');",+ DropdownLink.this.getMarkupId(true));+ target.appendJavaScript(script);+ }++ dropdown = null;+ }++ };+ String script = String.format(""+ + "$('#%s').addClass('dropdown-open');"+ + "$('#%s').data('trigger', $('#%s'));",+ getMarkupId(), dropdown.getMarkupId(), getMarkupId());+ target.appendJavaScript(script);+ } else {+ dropdown.close();+ }+ }++ public void close() {+ if (dropdown != null)+ dropdown.close();+ }++ public String getCloseScript() {+ if (dropdown != null) {+ return String.format("pmease.commons.floating.close($('#%s'), true);", dropdown.getMarkupId());+ } else {+ return "";+ }+ }++ public String closeBeforeClick(CharSequence onClickScript) {+ return getCloseScript() + (onClickScript!=null?onClickScript:"");+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);++ String script = String.format(""+ + "$('#%s').on('click', function(e){"+ + " $(this).data('mouseX', e.pageX).data('mouseY', e.pageY);"+ + "});", getMarkupId());+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ protected abstract Component newContent(String id);+}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.javaindex 10b9f0414a..51054f4099 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java@@ -1,46 +1,46 @@-package com.pmease.commons.wicket.component;--import javax.annotation.Nullable;--import org.apache.commons.lang3.StringUtils;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;-import org.apache.wicket.model.IModel;-import org.apache.wicket.request.cycle.RequestCycle;--@SuppressWarnings("serial")-public abstract class ViewStateAwareAjaxLink<T> extends PreventDefaultAjaxLink<T> {-- public ViewStateAwareAjaxLink(String id) {- super(id);- }-- public ViewStateAwareAjaxLink(String id, IModel<T> model) {- super(id, model);- }-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.setMethod(Method.POST);-- String script = ""- + "$('.autofit:visible').first().trigger('storeViewState');"- + "var viewState = pmease.commons.history.getViewState();"- + "return viewState?JSON.stringify(viewState):'';";- attributes.getDynamicExtraParameters().add("return {view_state: function() {" + script + "}}");- }-- @Override- public final void onClick(AjaxRequestTarget target) {- String value = RequestCycle.get().getRequest().getRequestParameters()- .getParameterValue("view_state").toString();- if (StringUtils.isNotBlank(value))- onClick(target, value);- else- onClick(target, null);- }-- protected abstract void onClick(AjaxRequestTarget target, @Nullable String viewState);-}+package com.pmease.commons.wicket.component;++import javax.annotation.Nullable;++import org.apache.commons.lang3.StringUtils;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;+import org.apache.wicket.model.IModel;+import org.apache.wicket.request.cycle.RequestCycle;++@SuppressWarnings("serial")+public abstract class ViewStateAwareAjaxLink<T> extends PreventDefaultAjaxLink<T> {++ public ViewStateAwareAjaxLink(String id) {+ super(id);+ }++ public ViewStateAwareAjaxLink(String id, IModel<T> model) {+ super(id, model);+ }++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.setMethod(Method.POST);++ String script = ""+ + "$('.autofit:visible').first().trigger('storeViewState');"+ + "var viewState = pmease.commons.history.getViewState();"+ + "return viewState?JSON.stringify(viewState):'';";+ attributes.getDynamicExtraParameters().add("return {view_state: function() {" + script + "}}");+ }++ @Override+ public final void onClick(AjaxRequestTarget target) {+ String value = RequestCycle.get().getRequest().getPostParameters()+ .getParameterValue("view_state").toString();+ if (StringUtils.isNotBlank(value))+ onClick(target, value);+ else+ onClick(target, null);+ }++ protected abstract void onClick(AjaxRequestTarget target, @Nullable String viewState);+}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/datatable/SelectionColumn.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/datatable/SelectionColumn.javaindex 9af5d87799..89e9ea80f6 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/datatable/SelectionColumn.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/datatable/SelectionColumn.java@@ -5,7 +5,6 @@ import java.util.Set;import org.apache.wicket.Component;import org.apache.wicket.MarkupContainer;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.WicketAjaxJQueryResourceReference;import org.apache.wicket.ajax.attributes.CallbackParameter;@@ -27,6 +26,8 @@ import org.apache.wicket.util.resource.StringResourceStream;import org.apache.wicket.util.visit.IVisit;import org.apache.wicket.util.visit.IVisitor;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;+/*** Add this column to the wicket DataTable component so that user can select row of the* data table using checkboxes. Override method ${@link SelectionColumn#onSelectionChange(AjaxRequestTarget)}@@ -104,7 +105,7 @@ public class SelectionColumn<T, S> implements IStyledColumn<T, S> {}.setOutputMarkupId(true));- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {@@ -180,7 +181,7 @@ public class SelectionColumn<T, S> implements IStyledColumn<T, S> {}.setOutputMarkupId(true));- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(final AjaxRequestTarget target) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.javaindex c999a10cf9..e29058b840 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java@@ -1,7 +1,6 @@package com.pmease.commons.wicket.component.floating;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.head.IHeaderResponse;@@ -10,6 +9,7 @@ import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.request.cycle.RequestCycle;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.page.CommonPage;@SuppressWarnings("serial")@@ -39,7 +39,7 @@ public abstract class FloatingPanel extends Panel {add(newContent(CONTENT_ID).setOutputMarkupId(true));- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/markdown/MarkdownPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/markdown/MarkdownPanel.javaindex 9386b243e7..4f77acac6a 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/markdown/MarkdownPanel.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/markdown/MarkdownPanel.java@@ -5,7 +5,6 @@ import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;import javax.annotation.Nullable;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptHeaderItem;@@ -21,6 +20,7 @@ import org.hibernate.StaleStateException;import com.pmease.commons.loader.AppLoader;import com.pmease.commons.markdown.MarkdownManager;import com.pmease.commons.util.StringUtils;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;@@ -60,7 +60,7 @@ public class MarkdownPanel extends GenericPanel<String> {}}).setEscapeModelStrings(false));- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.javaindex 83f28dbaa8..6687906e65 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.java@@ -1,7 +1,6 @@package com.pmease.commons.wicket.component.modal;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.head.IHeaderResponse;@@ -10,6 +9,7 @@ import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.panel.Panel;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.page.CommonPage;@SuppressWarnings("serial")@@ -50,7 +50,7 @@ public abstract class ModalPanel extends Panel {else if (size == Size.SMALL)dialog.add(AttributeAppender.append("class", "modal-sm"));- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/page/CommonPage.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/page/CommonPage.javaindex 9b48ed5a9c..b1c852577b 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/page/CommonPage.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/page/CommonPage.java@@ -9,7 +9,6 @@ import java.util.Collection;import org.apache.commons.codec.binary.Base64;import org.apache.commons.lang3.SerializationUtils;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;@@ -30,6 +29,7 @@ import org.apache.wicket.util.time.Duration;import org.eclipse.jetty.server.SessionManager;import com.pmease.commons.loader.AppLoader;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.websocket.WebSocketManager;import com.pmease.commons.wicket.websocket.WebSocketRegion;@@ -55,7 +55,7 @@ public abstract class CommonPage extends WebPage {protected void onInitialize() {super.onInitialize();- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void updateAjaxAttributes(AjaxRequestAttributes attributes) {@@ -89,8 +89,8 @@ public abstract class CommonPage extends WebPage {sessionFeedback.setOutputMarkupId(true);int sessionTimeout = AppLoader.getInstance(SessionManager.class).getMaxInactiveInterval();- add(new WebMarkupContainer("keepSessionAlive").add(- new AjaxSelfUpdatingTimerBehavior(Duration.milliseconds(sessionTimeout*500L))));+ add(new WebMarkupContainer("keepSessionAlive")+ .add(new AjaxSelfUpdatingTimerBehavior(Duration.milliseconds(sessionTimeout*500L))));add(rootComponents = new RepeatingView("rootComponents"));}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.jsindex cd115953e4..0721889210 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js@@ -212,11 +212,12 @@ pmease.commons = {}},setupAutoSize: function() {- autosize($("textarea"));+ var selector = "textarea:not(.no-autosize)";+ autosize($(selector));$(document).on("elementReplaced", function(event, componentId) {var $component = $("#" + componentId);- var $textarea = $component.find("textarea");- if ($component.is("textarea"))+ var $textarea = $component.find(selector);+ if ($component.is(selector))$textarea = $textarea.add($component);autosize($textarea);});diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.javaindex 070a2ce8e2..db6914bb9a 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java@@ -73,8 +73,8 @@ import com.pmease.commons.git.BlobIdent;import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.RefInfo;import com.pmease.commons.git.Submodule;-import com.pmease.commons.git.exception.NotFileException;-import com.pmease.commons.git.exception.ObjectNotExistException;+import com.pmease.commons.git.exception.NotGitFileException;+import com.pmease.commons.git.exception.GitObjectNotFoundException;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.hibernate.UnitOfWork;import com.pmease.commons.loader.AppLoader;@@ -515,7 +515,7 @@ public class Depot extends AbstractEntity implements AccountBelonging {* @return* blob of specified blob ident* @throws- * ObjectNotExistException if blob of specified ident can not be found in repository+ * GitObjectNotFoundException if blob of specified ident can not be found in repository**/public Blob getBlob(BlobIdent blobIdent) {@@ -532,18 +532,18 @@ public class Depot extends AbstractEntity implements AccountBelonging {if (blobIdent.isGitLink()) {String url = getSubmodules(blobIdent.revision).get(blobIdent.path);if (url == null)- throw new ObjectNotExistException("Unable to find submodule '" + blobIdent.path + "' in .gitmodules");+ throw new GitObjectNotFoundException("Unable to find submodule '" + blobIdent.path + "' in .gitmodules");String hash = treeWalk.getObjectId(0).name();blob = new Blob(blobIdent, new Submodule(url, hash).toString().getBytes());} else if (blobIdent.isTree()) {- throw new NotFileException("Path '" + blobIdent.path + "' is a tree");+ throw new NotGitFileException("Path '" + blobIdent.path + "' is a tree");} else {ObjectLoader objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));blob = readBlob(objectLoader, blobIdent);}getBlobCache().put(blobIdent, blob);} else {- throw new ObjectNotExistException("Unable to find blob path '" + blobIdent.path + "' in revision '" + blobIdent.revision + "'");+ throw new GitObjectNotFoundException("Unable to find blob path '" + blobIdent.path + "' in revision '" + blobIdent.revision + "'");}} catch (IOException e) {throw new RuntimeException(e);@@ -561,7 +561,7 @@ public class Depot extends AbstractEntity implements AccountBelonging {ObjectLoader objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));return objectLoader.openStream();} else {- throw new ObjectNotExistException("Unable to find blob path '" + ident.path + "' in revision '" + ident.revision + "'");+ throw new GitObjectNotFoundException("Unable to find blob path '" + ident.path + "' in revision '" + ident.revision + "'");}} catch (IOException e) {throw new RuntimeException(e);@@ -591,7 +591,7 @@ public class Depot extends AbstractEntity implements AccountBelonging {objectIdCache.put(revision, optional);}if (mustExist && !optional.isPresent())- throw new ObjectNotExistException("Unable to find object '" + revision + "'");+ throw new GitObjectNotFoundException("Unable to find object '" + revision + "'");return optional.orNull();}@@ -734,7 +734,7 @@ public class Depot extends AbstractEntity implements AccountBelonging {commit = null;}if (mustExist && commit == null)- throw new ObjectNotExistException("Unable to find commit: " + revision);+ throw new GitObjectNotFoundException("Unable to find commit: " + revision);elsereturn commit;}@@ -748,7 +748,7 @@ public class Depot extends AbstractEntity implements AccountBelonging {try (RevWalk revWalk = new RevWalk(getRepository())) {RevCommit commit = GitUtils.parseCommit(revWalk, revId);if (mustExist && commit == null)- throw new ObjectNotExistException("Unable to find commit: " + revId.name());+ throw new GitObjectNotFoundException("Unable to find commit: " + revId.name());elsereturn commit;}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.javaindex 041bc56acc..8926967373 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java@@ -40,7 +40,7 @@ import org.hibernate.criterion.Restrictions;import com.fasterxml.jackson.annotation.JsonView;import com.google.common.base.Preconditions;import com.pmease.commons.git.GitUtils;-import com.pmease.commons.git.exception.ObjectNotExistException;+import com.pmease.commons.git.exception.GitObjectNotFoundException;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.hibernate.UnitOfWork;import com.pmease.commons.hibernate.dao.Dao;@@ -515,7 +515,7 @@ public class PullRequest extends AbstractEntity {Long requestId = getId();try {gateResult = getTargetDepot().getGateKeeper().checkRequest(this);- } catch (ObjectNotExistException e) {+ } catch (GitObjectNotFoundException e) {// in case target/source branch is deleted but the pull request is not closed// for some reason, we call check again to make sure they will be closedGitPlex.getInstance(UnitOfWork.class).doAsync(new Runnable() {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/ExpectedExceptionContribution.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/ExpectedExceptionContribution.javanew file mode 100644index 0000000000..151304cd9f--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/ExpectedExceptionContribution.java@@ -0,0 +1,10 @@+package com.pmease.gitplex.web;++import java.util.Collection;++import com.pmease.commons.loader.ExtensionPoint;++@ExtensionPoint+public interface ExpectedExceptionContribution {+ Collection<Class<? extends Exception>> getExpectedExceptionClasses();+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.javaindex 6ff24bd3e2..c7e88d1674 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java@@ -2,12 +2,20 @@ package com.pmease.gitplex.web;import java.util.Collection;+import javax.persistence.EntityNotFoundException;+import org.apache.wicket.Application;+import org.apache.wicket.core.request.mapper.StalePageException;+import org.apache.wicket.protocol.http.PageExpiredException;import org.apache.wicket.protocol.http.WebApplication;+import org.hibernate.ObjectNotFoundException;+import org.hibernate.StaleStateException;+import org.hibernate.exception.ConstraintViolationException;import org.pegdown.Parser;import org.pegdown.plugins.ToHtmlSerializerPlugin;import com.google.common.collect.Lists;+import com.pmease.commons.git.exception.GitException;import com.pmease.commons.jetty.ServletConfigurator;import com.pmease.commons.loader.AbstractPluginModule;import com.pmease.commons.markdown.extensionpoint.HtmlTransformer;@@ -32,6 +40,8 @@ import com.pmease.gitplex.web.websocket.CodeCommentChangeBroadcaster;import com.pmease.gitplex.web.websocket.CommitIndexedBroadcaster;import com.pmease.gitplex.web.websocket.PullRequestChangeBroadcaster;+import jersey.repackaged.com.google.common.collect.Sets;+/*** NOTE: Do not forget to rename moduleClass property defined in the pom if you've renamed this class.*@@ -91,6 +101,17 @@ public class WebModule extends AbstractPluginModule {return Lists.newArrayList(WebModule.class);}+ });+ contribute(ExpectedExceptionContribution.class, new ExpectedExceptionContribution() {++ @SuppressWarnings("unchecked")+ @Override+ public Collection<Class<? extends Exception>> getExpectedExceptionClasses() {+ return Sets.newHashSet(ConstraintViolationException.class, EntityNotFoundException.class,+ ObjectNotFoundException.class, StaleStateException.class,+ GitException.class, PageExpiredException.class, StalePageException.class);+ }+});bind(UrlManager.class).to(WebUrlManager.class);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WicketConfig.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WicketConfig.javaindex 0cd50576f0..4ff50d3b42 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WicketConfig.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WicketConfig.java@@ -1,7 +1,9 @@package com.pmease.gitplex.web;+import java.util.Set;++import javax.inject.Inject;import javax.inject.Singleton;-import javax.persistence.EntityNotFoundException;import javax.servlet.http.HttpServletRequest;import org.apache.wicket.Application;@@ -17,17 +19,24 @@ import org.apache.wicket.request.http.WebRequest;import org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy;import org.apache.wicket.request.resource.caching.version.LastModifiedResourceVersion;-import com.pmease.commons.git.exception.ObjectNotExistException;import com.pmease.commons.util.ExceptionUtils;import com.pmease.commons.wicket.AbstractWicketConfig;import com.pmease.gitplex.web.mapper.UrlMapper;import com.pmease.gitplex.web.page.error.BaseErrorPage;-import com.pmease.gitplex.web.page.error.NotFoundErrorPage;+import com.pmease.gitplex.web.page.error.UnexpectedExceptionPage;+import com.pmease.gitplex.web.page.error.ExpectedExceptionPage;import com.pmease.gitplex.web.page.home.DashboardPage;@Singletonpublic class WicketConfig extends AbstractWicketConfig {+ private final Set<ExpectedExceptionContribution> expectedExceptionContributions;++ @Inject+ public WicketConfig(Set<ExpectedExceptionContribution> expectedExceptionContributions) {+ this.expectedExceptionContributions = expectedExceptionContributions;+ }+public static WicketConfig get() {return (WicketConfig) Application.get();}@@ -81,15 +90,15 @@ public class WicketConfig extends AbstractWicketConfig {@Overrideprotected Page mapExceptions(Exception e) {- EntityNotFoundException entityNotFoundException = ExceptionUtils.find(e, EntityNotFoundException.class);- if (entityNotFoundException != null)- return new NotFoundErrorPage(entityNotFoundException.getMessage());-- ObjectNotExistException objectNotExistException = ExceptionUtils.find(e, ObjectNotExistException.class);- if (objectNotExistException != null)- return new NotFoundErrorPage(objectNotExistException.getMessage());+ for (ExpectedExceptionContribution contribution: expectedExceptionContributions) {+ for (Class<? extends Exception> expectedExceptionClass: contribution.getExpectedExceptionClasses()) {+ Exception expectedException = ExceptionUtils.find(e, expectedExceptionClass);+ if (expectedException != null)+ return new ExpectedExceptionPage(expectedException);+ }+ }- return super.mapExceptions(e);+ return new UnexpectedExceptionPage(e);}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchpicker/BranchSelector.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchpicker/BranchSelector.javaindex 4b23ce1b80..b26d6fb55d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchpicker/BranchSelector.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchpicker/BranchSelector.java@@ -5,7 +5,6 @@ import java.util.List;import org.apache.commons.lang3.StringUtils;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.attributes.CallbackParameter;@@ -28,6 +27,7 @@ import org.apache.wicket.request.cycle.RequestCycle;import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.RefInfo;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.behavior.InputChangeBehavior;import com.pmease.gitplex.core.entity.Depot;@@ -42,7 +42,7 @@ public abstract class BranchSelector extends Panel {private String branchInput;- private AbstractDefaultAjaxBehavior keyBehavior;+ private AbstractPostAjaxBehavior keyBehavior;private TextField<String> branchField;@@ -70,7 +70,7 @@ public abstract class BranchSelector extends Panel {branchField.setOutputMarkupId(true);add(branchField);- keyBehavior = new AbstractDefaultAjaxBehavior() {+ keyBehavior = new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.javaindex 01e9163647..b6f0d3a475 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java@@ -7,7 +7,6 @@ import java.util.List;import org.apache.wicket.AttributeModifier;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxChannel;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;@@ -33,6 +32,7 @@ import org.eclipse.jgit.lib.ObjectId;import com.pmease.commons.util.StringUtils;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.behavior.RunTaskBehavior;import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;import com.pmease.commons.wicket.component.floating.AlignPlacement;@@ -135,7 +135,7 @@ public abstract class InstantSearchPanel extends Panel {super.onInitialize();searchField = new TextField<>("input");- searchField.add(new AbstractDefaultAjaxBehavior() {+ searchField.add(new AbstractPostAjaxBehavior() {@Overrideprotected void updateAjaxAttributes(AjaxRequestAttributes attributes) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownFilePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownFilePanel.javaindex d8cccadf44..f7d404328f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownFilePanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownFilePanel.java@@ -4,20 +4,24 @@ import java.util.ArrayList;import java.util.List;import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.head.CssHeaderItem;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.html.link.AbstractLink;import org.apache.wicket.model.Model;+import org.apache.wicket.request.cycle.RequestCycle;+import org.apache.wicket.request.mapper.parameter.PageParameters;import com.pmease.commons.git.Blob;import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;+import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;import com.pmease.commons.wicket.component.markdown.MarkdownPanel;import com.pmease.commons.wicket.component.menu.MenuItem;import com.pmease.commons.wicket.component.menu.MenuLink;import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;@SuppressWarnings("serial")public class MarkdownFilePanel extends BlobViewPanel {@@ -51,7 +55,7 @@ public class MarkdownFilePanel extends BlobViewPanel {@Overridepublic AbstractLink newLink(String id) {- AbstractLink link = new AjaxLink<Void>(id) {+ AbstractLink link = new PreventDefaultAjaxLink<Void>(id) {@Overridepublic void onClick(AjaxRequestTarget target) {@@ -60,6 +64,15 @@ public class MarkdownFilePanel extends BlobViewPanel {}};+ PageParameters params;+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = context.getBlobIdent();+ if (context.getMode() != Mode.BLAME)+ state.mode = Mode.BLAME;+ state.mark = context.getMark();+ params = DepotFilePage.paramsOf(context.getDepot(), state);+ CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);+ link.add(AttributeAppender.replace("href", url.toString()));link.add(new ViewStateAwareBehavior());return link;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.javaindex 489dec4f53..c7b89d8822 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java@@ -1,959 +1,968 @@-package com.pmease.gitplex.web.component.depotfile.blobview.source;--import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;--import java.util.ArrayList;-import java.util.Collection;-import java.util.HashMap;-import java.util.Iterator;-import java.util.List;-import java.util.Map;-import java.util.UUID;--import javax.annotation.Nullable;-import javax.servlet.http.Cookie;--import org.apache.wicket.Component;-import org.apache.wicket.Session;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.markup.html.AjaxLink;-import org.apache.wicket.ajax.markup.html.form.AjaxButton;-import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;-import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;-import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;-import org.apache.wicket.markup.ComponentTag;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.head.JavaScriptHeaderItem;-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;-import org.apache.wicket.markup.html.WebMarkupContainer;-import org.apache.wicket.markup.html.basic.Label;-import org.apache.wicket.markup.html.form.Form;-import org.apache.wicket.markup.html.form.TextField;-import org.apache.wicket.markup.html.image.Image;-import org.apache.wicket.markup.html.link.AbstractLink;-import org.apache.wicket.markup.html.panel.Fragment;-import org.apache.wicket.model.AbstractReadOnlyModel;-import org.apache.wicket.model.IModel;-import org.apache.wicket.model.LoadableDetachableModel;-import org.apache.wicket.model.Model;-import org.apache.wicket.protocol.ws.api.WebSocketRequestHandler;-import org.apache.wicket.request.IRequestParameters;-import org.apache.wicket.request.cycle.RequestCycle;-import org.apache.wicket.request.http.WebRequest;-import org.apache.wicket.request.http.WebResponse;-import org.apache.wicket.request.mapper.parameter.PageParameters;-import org.eclipse.jgit.lib.FileMode;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;-import org.unbescape.html.HtmlEscape;-import org.unbescape.javascript.JavaScriptEscape;--import com.fasterxml.jackson.core.JsonProcessingException;-import com.fasterxml.jackson.databind.ObjectMapper;-import com.google.common.base.Preconditions;-import com.pmease.commons.git.Blame;-import com.pmease.commons.git.Blob;-import com.pmease.commons.git.BlobIdent;-import com.pmease.commons.git.GitUtils;-import com.pmease.commons.git.command.BlameCommand;-import com.pmease.commons.lang.extractors.ExtractException;-import com.pmease.commons.lang.extractors.Extractor;-import com.pmease.commons.lang.extractors.Extractors;-import com.pmease.commons.lang.extractors.Symbol;-import com.pmease.commons.util.Range;-import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;-import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;-import com.pmease.commons.wicket.component.DropdownLink;-import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;-import com.pmease.commons.wicket.component.menu.MenuItem;-import com.pmease.commons.wicket.component.menu.MenuLink;-import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.entity.CodeComment;-import com.pmease.gitplex.core.entity.Depot;-import com.pmease.gitplex.core.entity.PullRequest;-import com.pmease.gitplex.core.entity.support.CommentPos;-import com.pmease.gitplex.core.entity.support.CompareContext;-import com.pmease.gitplex.core.entity.support.DepotAndRevision;-import com.pmease.gitplex.core.entity.support.TextRange;-import com.pmease.gitplex.core.manager.CodeCommentManager;-import com.pmease.gitplex.core.security.SecurityUtils;-import com.pmease.gitplex.search.hit.QueryHit;-import com.pmease.gitplex.web.component.comment.CodeCommentPanel;-import com.pmease.gitplex.web.component.comment.CommentInput;-import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;-import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;-import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;-import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;-import com.pmease.gitplex.web.component.revisionpicker.RevisionSelector;-import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;-import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;-import com.pmease.gitplex.web.page.depot.file.DepotFilePage;-import com.pmease.gitplex.web.util.DateUtils;--import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;--/**- * Make sure to add only one source view panel per page- *- * @author robin- *- */-@SuppressWarnings("serial")-public class SourceViewPanel extends BlobViewPanel {-- private static final Logger logger = LoggerFactory.getLogger(SourceViewPanel.class);-- private static final String COOKIE_OUTLINE = "sourceView.outline";-- private static final String BODY_ID = "body";-- private final List<Symbol> symbols = new ArrayList<>();-- private final IModel<Collection<CodeComment>> commentsModel =- new LoadableDetachableModel<Collection<CodeComment>>() {-- @Override- protected Collection<CodeComment> load() {- return GitPlex.getInstance(CodeCommentManager.class).findAll(- context.getDepot(), context.getCommit(), context.getBlobIdent().path);- }-- };-- private WebMarkupContainer commentContainer;-- private WebMarkupContainer outlineContainer;-- private SymbolTooltipPanel symbolTooltip;-- private AbstractDefaultAjaxBehavior ajaxBehavior;-- public SourceViewPanel(String id, BlobViewContext context) {- super(id, context);-- Blob blob = context.getDepot().getBlob(context.getBlobIdent());- Preconditions.checkArgument(blob.getText() != null);-- Extractor extractor = GitPlex.getInstance(Extractors.class).getExtractor(context.getBlobIdent().path);- if (extractor != null) {- try {- symbols.addAll(extractor.extract(blob.getText().getContent()));- } catch (ExtractException e) {- logger.debug("Error extracting symbols from blob: " + context.getBlobIdent(), e);- }- }-- }-- @Override- public List<MenuItem> getMenuItems(MenuLink menuLink) {- List<MenuItem> menuItems = new ArrayList<>();- menuItems.add(new MenuItem() {-- @Override- public String getIconClass() {- return context.getMode() == Mode.BLAME?"fa fa-check":null;- }-- @Override- public String getLabel() {- return "Blame";- }-- @Override- public AbstractLink newLink(String id) {- AbstractLink link = new AjaxLink<Void>(id) {-- @Override- public void onClick(AjaxRequestTarget target) {- menuLink.close();- boolean blamed = (context.getMode() != Mode.BLAME);- String jsonOfBlameInfos = getJsonOfBlameInfos(blamed);- String script = String.format("gitplex.sourceview.onBlame(%s);", jsonOfBlameInfos);- target.appendJavaScript(script);- context.onBlameChange(target, blamed);- }-- };- link.add(new ViewStateAwareBehavior());- return link;- }-- });-- if (!symbols.isEmpty()) {- menuItems.add(new MenuItem() {-- @Override- public String getLabel() {- return "Outline";- }-- @Override- public String getIconClass() {- return outlineContainer.isVisible()?"fa fa-check":null;- }-- @Override- public AbstractLink newLink(String id) {- return new AjaxLink<Void>(id) {-- @Override- public void onClick(AjaxRequestTarget target) {- menuLink.close();- toggleOutline(target);- }-- };- }-- });- }- return menuItems;- }-- private void toggleOutline(AjaxRequestTarget target) {- WebResponse response = (WebResponse) RequestCycle.get().getResponse();- Cookie cookie;- if (outlineContainer.isVisible()) {- cookie = new Cookie(COOKIE_OUTLINE, "no");- outlineContainer.setVisible(false);- } else {- cookie = new Cookie(COOKIE_OUTLINE, "yes");- outlineContainer.setVisible(true);- }- cookie.setMaxAge(Integer.MAX_VALUE);- response.addCookie(cookie);- target.add(outlineContainer);- target.appendJavaScript("gitplex.sourceview.onToggleOutline();");- }-- public void mark(AjaxRequestTarget target, TextRange mark, boolean scroll) {- String script = String.format("gitplex.sourceview.mark(%s, %s);",- getJson(mark), scroll);- target.appendJavaScript(script);- }-- private String getJson(TextRange mark) {- try {- return GitPlex.getInstance(ObjectMapper.class).writeValueAsString(mark);- } catch (JsonProcessingException e) {- throw new RuntimeException(e);- }- }-- @Override- protected void onInitialize() {- super.onInitialize();-- commentContainer = new WebMarkupContainer("comment", Model.of((TextRange)null)) {-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);- response.render(OnDomReadyHeaderItem.forScript("gitplex.sourceview.initComment();"));- }-- };-- commentContainer.add(new WebSocketRenderBehavior() {-- @Override- protected void onRender(WebSocketRequestHandler handler) {- if (commentContainer.isVisible())- handler.add(commentContainer.get("head").get("toggleResolve"));- }-- });-- WebMarkupContainer head = new WebMarkupContainer("head");- head.setOutputMarkupId(true);- commentContainer.add(head);-- head.add(new Label("title", new AbstractReadOnlyModel<String>() {-- @Override- public String getObject() {- CodeComment comment = context.getOpenComment();- return comment!=null?comment.getTitle():"";- }-- }) {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(context.getOpenComment() != null);- }-- });- head.add(new DropdownLink("context") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(context.getOpenComment() != null);- }-- @Override- protected Component newContent(String id) {- return new RevisionSelector(id, new AbstractReadOnlyModel<Depot>() {-- @Override- public Depot getObject() {- return context.getDepot();- }-- }) {-- @Override- protected void onSelect(AjaxRequestTarget target, String revision) {- RevisionComparePage.State state = new RevisionComparePage.State();- CodeComment comment = context.getOpenComment();- state.commentId = comment.getId();- state.mark = comment.getCommentPos();- state.compareWithMergeBase = false;- state.leftSide = new DepotAndRevision(context.getDepot(), comment.getCommentPos().getCommit());- state.rightSide = new DepotAndRevision(context.getDepot(), revision);- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;- PageParameters params = RevisionComparePage.paramsOf(context.getDepot(), state);- setResponsePage(RevisionComparePage.class, params);- }-- };- }-- });- head.add(new AjaxLink<Void>("locate") {-- @Override- public void onClick(AjaxRequestTarget target) {- CodeComment comment = context.getOpenComment();- TextRange mark;- if (comment != null) {- mark = comment.getCommentPos().getRange();- } else {- mark = (TextRange) commentContainer.getDefaultModelObject();- }- mark(target, mark, true);- context.onMark(target, mark);- target.appendJavaScript(String.format("$('#%s').blur();", getMarkupId()));- }-- @Override- protected void onInitialize() {- super.onInitialize();- setOutputMarkupId(true);- }-- });-- // use this instead of bookmarkable link as we want to get the link- // updated whenever we re-render the comment container- AttributeAppender appender = AttributeAppender.append("href", new LoadableDetachableModel<String>() {-- @Override- protected String load() {- if (context.getOpenComment() != null) {- DepotFilePage.State state = new DepotFilePage.State();- state.blobIdent = new BlobIdent(context.getBlobIdent());- state.blobIdent.revision = context.getCommit().name();- state.commentId = context.getOpenComment().getId();- state.mark = context.getOpenComment().getCommentPos().getRange();- return urlFor(DepotFilePage.class, DepotFilePage.paramsOf(context.getDepot(), state)).toString();- } else {- return "";- }- }-- });- head.add(new WebMarkupContainer("permanent") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(context.getOpenComment() != null);- }-- }.add(appender));-- head.add(new AjaxLink<Void>("close") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(commentContainer));- }-- @Override- public void onClick(AjaxRequestTarget target) {- clearComment(target);- if (context.getOpenComment() != null)- context.onCommentOpened(target, null);- target.appendJavaScript("gitplex.sourceview.onCloseComment();");- }-- });-- head.add(new AjaxLink<Void>("toggleResolve") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(commentContainer));- }-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(context.getOpenComment() != null);- }-- @Override- protected void onComponentTag(ComponentTag tag) {- super.onComponentTag(tag);- CodeComment comment = context.getOpenComment();- if (comment != null) {- if (comment.isResolved()) {- tag.put("title", "Comment is currently resolved, click to unresolve");- tag.put("class", "pull-right resolve resolved");- } else {- tag.put("title", "Comment is currently unresolved, click to resolve");- tag.put("class", "pull-right resolve unresolved");- }- }- }-- @Override- public void onClick(AjaxRequestTarget target) {- if (SecurityUtils.getAccount() != null) {- ((CodeCommentPanel)commentContainer.get("body")).onChangeStatus(target);- target.appendJavaScript("gitplex.sourceview.scrollToCommentBottom();");- } else {- Session.get().warn("Please login to resolve/unresolve comment");- }- }-- }.setOutputMarkupId(true));-- commentContainer.setOutputMarkupPlaceholderTag(true);- if (context.getOpenComment() != null) {- CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, context.getOpenComment().getId()) {-- @Override- protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {- SourceViewPanel.this.onCommentDeleted(target, comment);- }-- @Override- protected CompareContext getCompareContext(CodeComment comment) {- return SourceViewPanel.this.getCompareContext();- }-- @Override- protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {- target.add(commentContainer.get("head"));- }-- @Override- protected PullRequest getPullRequest() {- return null;- }-- };- commentContainer.add(commentPanel);- } else {- commentContainer.add(new WebMarkupContainer(BODY_ID));- commentContainer.setVisible(false);- }- add(commentContainer);-- add(ajaxBehavior = new AbstractDefaultAjaxBehavior() {-- @Override- protected void respond(AjaxRequestTarget target) {- IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();-- switch(params.getParameterValue("action").toString()) {- case "showBlameMessage":- String tooltipId = params.getParameterValue("param1").toString();- String commitHash = params.getParameterValue("param2").toString();- String message = context.getDepot().getRevCommit(commitHash).getFullMessage();- String escapedMessage = JavaScriptEscape.escapeJavaScript(message);- String script = String.format("gitplex.sourceview.showBlameMessage('%s', '%s');", tooltipId, escapedMessage);- target.appendJavaScript(script);- break;- case "openSelectionPopover":- TextRange mark = getMark(params, "param1", "param2", "param3", "param4");- script = String.format("gitplex.sourceview.openSelectionPopover(%s, '%s', %s);",- getJson(mark), context.getMarkUrl(mark),- SecurityUtils.getAccount()!=null);- target.appendJavaScript(script);- break;- case "addComment":- Preconditions.checkNotNull(SecurityUtils.getAccount());-- mark = getMark(params, "param1", "param2", "param3", "param4");- commentContainer.setDefaultModelObject(mark);-- Fragment fragment = new Fragment(BODY_ID, "newCommentFrag", SourceViewPanel.this);- fragment.setOutputMarkupId(true);-- Form<?> form = new Form<Void>("form");-- String uuid = UUID.randomUUID().toString();-- TextField<String> titleInput = new TextField<String>("title", Model.of(""));- titleInput.setRequired(true);- form.add(titleInput);-- CommentInput contentInput;- form.add(contentInput = new CommentInput("content", Model.of("")) {-- @Override- protected DepotAttachmentSupport getAttachmentSupport() {- return new DepotAttachmentSupport(context.getDepot(), uuid);- }-- @Override- protected Depot getDepot() {- return context.getDepot();- }-- });- contentInput.setRequired(true);-- NotificationPanel feedback = new NotificationPanel("feedback", form);- feedback.setOutputMarkupPlaceholderTag(true);- form.add(feedback);-- form.add(new AjaxLink<Void>("cancel") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));- }-- @Override- public void onClick(AjaxRequestTarget target) {- clearComment(target);- target.appendJavaScript("gitplex.sourceview.onLayoutChange();");- }-- });-- form.add(new AjaxButton("save") {-- @Override- protected void onError(AjaxRequestTarget target, Form<?> form) {- super.onError(target, form);- target.add(feedback);- }-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);-- CodeComment comment = new CodeComment();- comment.setUUID(uuid);- comment.setCommentPos(new CommentPos());- comment.getCommentPos().setCommit(context.getCommit().name());- comment.getCommentPos().setPath(context.getBlobIdent().path);- comment.setTitle(titleInput.getModelObject());- comment.setContent(contentInput.getModelObject());- comment.setDepot(context.getDepot());- comment.setUser(SecurityUtils.getAccount());- comment.getCommentPos().setRange(mark);- comment.setCompareContext(getCompareContext());-- GitPlex.getInstance(CodeCommentManager.class).save(comment);-- CodeCommentPanel commentPanel = new CodeCommentPanel(fragment.getId(), comment.getId()) {-- @Override- protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {- SourceViewPanel.this.onCommentDeleted(target, comment);- }-- @Override- protected CompareContext getCompareContext(CodeComment comment) {- return SourceViewPanel.this.getCompareContext();- }-- @Override- protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {- target.add(commentContainer.get("head"));- }-- @Override- protected PullRequest getPullRequest() {- return null;- }-- };- commentContainer.replace(commentPanel);- target.add(commentContainer);-- String script = String.format("gitplex.sourceview.onCommentAdded(%s);",- getJsonOfComment(comment));- target.appendJavaScript(script);- context.onCommentOpened(target, comment);- }-- });- fragment.add(form);- commentContainer.replace(fragment);- commentContainer.setVisible(true);- target.add(commentContainer);- context.onAddComment(target, mark);- target.appendJavaScript(String.format("gitplex.sourceview.onAddComment(%s);", getJson(mark)));- break;- case "openComment":- Long commentId = params.getParameterValue("param1").toLong();- CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentId) {-- @Override- protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {- SourceViewPanel.this.onCommentDeleted(target, comment);- }-- @Override- protected CompareContext getCompareContext(CodeComment comment) {- return SourceViewPanel.this.getCompareContext();- }-- @Override- protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {- target.add(commentContainer.get("head"));- }-- @Override- protected PullRequest getPullRequest() {- return null;- }-- };- commentContainer.replace(commentPanel);- commentContainer.setVisible(true);- target.add(commentContainer);- CodeComment comment = GitPlex.getInstance(CodeCommentManager.class).load(commentId);- script = String.format("gitplex.sourceview.onOpenComment(%s);", getJsonOfComment(comment));- target.appendJavaScript(script);- context.onCommentOpened(target, comment);- break;- }- }-- });-- outlineContainer = new WebMarkupContainer("outline") {-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);- response.render(OnDomReadyHeaderItem.forScript("gitplex.sourceview.initOutline();"));- }-- };- outlineContainer.add(new AjaxLink<Void>("close") {-- @Override- public void onClick(AjaxRequestTarget target) {- toggleOutline(target);- }-- });- NestedTree<Symbol> tree;- outlineContainer.add(tree = new NestedTree<Symbol>(BODY_ID, new ITreeProvider<Symbol>() {-- @Override- public void detach() {- }-- @Override- public Iterator<? extends Symbol> getRoots() {- return getChildSymbols(null).iterator();- }-- @Override- public boolean hasChildren(Symbol symbol) {- return !getChildSymbols(symbol).isEmpty();- }-- @Override- public Iterator<? extends Symbol> getChildren(Symbol symbol) {- return getChildSymbols(symbol).iterator();- }-- @Override- public IModel<Symbol> model(Symbol symbol) {- return Model.of(symbol);- }-- }) {-- @Override- protected void onInitialize() {- super.onInitialize();- add(new HumanTheme());- }-- @Override- protected Component newContentComponent(String id, IModel<Symbol> nodeModel) {- Fragment fragment = new Fragment(id, "outlineNodeFrag", SourceViewPanel.this);- Symbol symbol = nodeModel.getObject();-- fragment.add(new Image("icon", symbol.getIcon()));-- AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {-- @Override- public void onClick(AjaxRequestTarget target) {- context.onSelect(target, context.getBlobIdent(), symbol.getPos());- }-- };- DepotFilePage.State state = new DepotFilePage.State();- state.blobIdent = context.getBlobIdent();- state.commentId = CodeComment.idOf(context.getOpenComment());- state.mark = TextRange.of(symbol.getPos());- PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);- link.add(AttributeAppender.replace("href", urlFor(DepotFilePage.class, params).toString()));- link.add(symbol.render("label", null));- fragment.add(link);-- return fragment;- }-- });-- for (Symbol root: getChildSymbols(null))- tree.expand(root);-- outlineContainer.setOutputMarkupPlaceholderTag(true);- add(outlineContainer);-- if (!symbols.isEmpty()) {- WebRequest request = (WebRequest) RequestCycle.get().getRequest();- Cookie cookie = request.getCookie(COOKIE_OUTLINE);- if (cookie!=null && cookie.getValue().equals("no"))- outlineContainer.setVisible(false);- } else {- outlineContainer.setVisible(false);- }-- add(symbolTooltip = new SymbolTooltipPanel("symbolTooltip", new AbstractReadOnlyModel<Depot>() {-- @Override- public Depot getObject() {- return context.getDepot();- }-- }) {-- @Override- protected void onSelect(AjaxRequestTarget target, QueryHit hit) {- BlobIdent blobIdent = new BlobIdent(- getRevision(), hit.getBlobPath(), FileMode.REGULAR_FILE.getBits());- context.onSelect(target, blobIdent, hit.getTokenPos());- }-- @Override- protected void onOccurrencesQueried(AjaxRequestTarget target, List<QueryHit> hits) {- context.onSearchComplete(target, hits);- }-- @Override- protected String getBlobPath() {- return context.getBlobIdent().path;- }-- });- }-- private TextRange getMark(IRequestParameters params, String beginLineParam, String beginCharParam,- String endLineParam, String endCharParam) {- int beginLine = params.getParameterValue(beginLineParam).toInt();- int beginChar = params.getParameterValue(beginCharParam).toInt();- int endLine = params.getParameterValue(endLineParam).toInt();- int endChar = params.getParameterValue(endCharParam).toInt();- TextRange mark = new TextRange();- mark.beginLine = beginLine;- mark.beginChar = beginChar;- mark.endLine = endLine;- mark.endChar = endChar;- return mark;- }-- private String getJsonOfComment(CodeComment comment) {- CommentInfo commentInfo = new CommentInfo();- commentInfo.id = comment.getId();- commentInfo.mark = comment.getCommentPos().getRange();- commentInfo.title = comment.getTitle();-- String jsonOfCommentInfo;- try {- jsonOfCommentInfo = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfo);- } catch (JsonProcessingException e) {- throw new RuntimeException(e);- }- return jsonOfCommentInfo;- }-- private void clearComment(AjaxRequestTarget target) {- commentContainer.replace(new WebMarkupContainer(BODY_ID));- commentContainer.setVisible(false);- target.add(commentContainer);- }-- private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {- clearComment(target);- String script = String.format("gitplex.sourceview.onCommentDeleted(%s);",- getJsonOfComment(comment));- target.appendJavaScript(script);- context.onCommentOpened(target, null);- }-- private List<Symbol> getChildSymbols(@Nullable Symbol parentSymbol) {- List<Symbol> children = new ArrayList<>();- for (Symbol symbol: symbols) {- if (symbol.getParent() == parentSymbol)- children.add(symbol);- }- return children;- }-- private String getJsonOfBlameInfos(boolean blamed) {- String jsonOfBlameInfos;- if (blamed) {- List<BlameInfo> blameInfos = new ArrayList<>();-- String commitHash = context.getCommit().name();-- BlameCommand cmd = new BlameCommand(context.getDepot().getDirectory());- cmd.commitHash(commitHash).file(context.getBlobIdent().path);- for (Blame blame: cmd.call().values()) {- BlameInfo blameInfo = new BlameInfo();- blameInfo.commitDate = DateUtils.formatDate(blame.getCommit().getCommitter().getWhen());- blameInfo.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());- blameInfo.hash = blame.getCommit().getHash();- blameInfo.abbreviatedHash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);- CommitDetailPage.State state = new CommitDetailPage.State();- state.revision = blame.getCommit().getHash();- state.pathFilter = context.getBlobIdent().path;- PageParameters params = CommitDetailPage.paramsOf(context.getDepot(), state);- blameInfo.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();- blameInfo.ranges = blame.getRanges();- blameInfos.add(blameInfo);- }- try {- jsonOfBlameInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(blameInfos);- } catch (JsonProcessingException e) {- throw new RuntimeException(e);- }- } else {- jsonOfBlameInfos = "undefined";- }- return jsonOfBlameInfos;- }-- private CompareContext getCompareContext() {- CompareContext compareContext = new CompareContext();- compareContext.setCompareCommit(context.getCommit().name());- compareContext.setPathFilter(context.getBlobIdent().path);- return compareContext;- }-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);-- response.render(JavaScriptHeaderItem.forReference(new SourceViewResourceReference()));-- Blob blob = context.getDepot().getBlob(context.getBlobIdent());-- String jsonOfBlameInfos = getJsonOfBlameInfos(context.getMode() == Mode.BLAME);- Map<Integer, List<CommentInfo>> commentInfos = new HashMap<>();- for (CodeComment comment: commentsModel.getObject()) {- if (comment.getCommentPos().getRange() != null) {- int line = comment.getCommentPos().getRange().getBeginLine();- List<CommentInfo> commentInfosAtLine = commentInfos.get(line);- if (commentInfosAtLine == null) {- commentInfosAtLine = new ArrayList<>();- commentInfos.put(line, commentInfosAtLine);- }- CommentInfo commentInfo = new CommentInfo();- commentInfo.id = comment.getId();- commentInfo.mark = comment.getCommentPos().getRange();- commentInfo.title = comment.getTitle();- commentInfosAtLine.add(commentInfo);- }- }- for (List<CommentInfo> value: commentInfos.values()) {- value.sort((o1, o2)->(int)(o1.id-o2.id));- }-- String jsonOfCommentInfos;- try {- jsonOfCommentInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfos);- } catch (JsonProcessingException e) {- throw new RuntimeException(e);- }- CharSequence callback = ajaxBehavior.getCallbackFunction(- explicit("action"), explicit("param1"), explicit("param2"),- explicit("param3"), explicit("param4"));- String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);- String script = String.format("gitplex.sourceview.init('%s', '%s', %s, %s, '%s', '%s', "- + "%s, %s, %s, %s, %s);",- JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),- JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),- context.getOpenComment()!=null?getJsonOfComment(context.getOpenComment()):"undefined",- context.getMark()!=null?getJson(context.getMark()):"undefined",- symbolTooltip.getMarkupId(),- context.getBlobIdent().revision,- jsonOfBlameInfos,- jsonOfCommentInfos,- callback,- viewState!=null?"JSON.parse('"+viewState+"')":"undefined",- SecurityUtils.getAccount()!=null);- response.render(OnDomReadyHeaderItem.forScript(script));- }-- @Override- protected void onDetach() {- commentsModel.detach();- super.onDetach();- }-- @SuppressWarnings("unused")- private static class BlameInfo {-- String abbreviatedHash;-- String hash;-- String url;-- String authorName;-- String commitDate;-- List<Range> ranges;- }-- @SuppressWarnings("unused")- private static class CommentInfo {- long id;-- String title;-- TextRange mark;- }--}+package com.pmease.gitplex.web.component.depotfile.blobview.source;++import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;++import java.util.ArrayList;+import java.util.Collection;+import java.util.HashMap;+import java.util.Iterator;+import java.util.List;+import java.util.Map;+import java.util.UUID;++import javax.annotation.Nullable;+import javax.servlet.http.Cookie;++import org.apache.wicket.Component;+import org.apache.wicket.Session;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.ajax.markup.html.form.AjaxButton;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;+import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;+import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;+import org.apache.wicket.markup.ComponentTag;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.JavaScriptHeaderItem;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.form.Form;+import org.apache.wicket.markup.html.form.TextField;+import org.apache.wicket.markup.html.image.Image;+import org.apache.wicket.markup.html.link.AbstractLink;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.model.AbstractReadOnlyModel;+import org.apache.wicket.model.IModel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;+import org.apache.wicket.protocol.ws.api.WebSocketRequestHandler;+import org.apache.wicket.request.IRequestParameters;+import org.apache.wicket.request.cycle.RequestCycle;+import org.apache.wicket.request.http.WebRequest;+import org.apache.wicket.request.http.WebResponse;+import org.apache.wicket.request.mapper.parameter.PageParameters;+import org.eclipse.jgit.lib.FileMode;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+import org.unbescape.html.HtmlEscape;+import org.unbescape.javascript.JavaScriptEscape;++import com.fasterxml.jackson.core.JsonProcessingException;+import com.fasterxml.jackson.databind.ObjectMapper;+import com.google.common.base.Preconditions;+import com.pmease.commons.git.Blame;+import com.pmease.commons.git.Blob;+import com.pmease.commons.git.BlobIdent;+import com.pmease.commons.git.GitUtils;+import com.pmease.commons.git.command.BlameCommand;+import com.pmease.commons.lang.extractors.ExtractException;+import com.pmease.commons.lang.extractors.Extractor;+import com.pmease.commons.lang.extractors.Extractors;+import com.pmease.commons.lang.extractors.Symbol;+import com.pmease.commons.util.Range;+import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;+import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;+import com.pmease.commons.wicket.component.DropdownLink;+import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;+import com.pmease.commons.wicket.component.menu.MenuItem;+import com.pmease.commons.wicket.component.menu.MenuLink;+import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.CodeComment;+import com.pmease.gitplex.core.entity.Depot;+import com.pmease.gitplex.core.entity.PullRequest;+import com.pmease.gitplex.core.entity.support.CommentPos;+import com.pmease.gitplex.core.entity.support.CompareContext;+import com.pmease.gitplex.core.entity.support.DepotAndRevision;+import com.pmease.gitplex.core.entity.support.TextRange;+import com.pmease.gitplex.core.manager.CodeCommentManager;+import com.pmease.gitplex.core.security.SecurityUtils;+import com.pmease.gitplex.search.hit.QueryHit;+import com.pmease.gitplex.web.component.comment.CodeCommentPanel;+import com.pmease.gitplex.web.component.comment.CommentInput;+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;+import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;+import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;+import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;+import com.pmease.gitplex.web.component.revisionpicker.RevisionSelector;+import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;+import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;+import com.pmease.gitplex.web.util.DateUtils;++import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;++/**+ * Make sure to add only one source view panel per page+ *+ * @author robin+ *+ */+@SuppressWarnings("serial")+public class SourceViewPanel extends BlobViewPanel {++ private static final Logger logger = LoggerFactory.getLogger(SourceViewPanel.class);++ private static final String COOKIE_OUTLINE = "sourceView.outline";++ private static final String BODY_ID = "body";++ private final List<Symbol> symbols = new ArrayList<>();++ private final IModel<Collection<CodeComment>> commentsModel =+ new LoadableDetachableModel<Collection<CodeComment>>() {++ @Override+ protected Collection<CodeComment> load() {+ return GitPlex.getInstance(CodeCommentManager.class).findAll(+ context.getDepot(), context.getCommit(), context.getBlobIdent().path);+ }++ };++ private WebMarkupContainer commentContainer;++ private WebMarkupContainer outlineContainer;++ private SymbolTooltipPanel symbolTooltip;++ private AbstractPostAjaxBehavior ajaxBehavior;++ public SourceViewPanel(String id, BlobViewContext context) {+ super(id, context);++ Blob blob = context.getDepot().getBlob(context.getBlobIdent());+ Preconditions.checkArgument(blob.getText() != null);++ Extractor extractor = GitPlex.getInstance(Extractors.class).getExtractor(context.getBlobIdent().path);+ if (extractor != null) {+ try {+ symbols.addAll(extractor.extract(blob.getText().getContent()));+ } catch (ExtractException e) {+ logger.debug("Error extracting symbols from blob: " + context.getBlobIdent(), e);+ }+ }++ }++ @Override+ public List<MenuItem> getMenuItems(MenuLink menuLink) {+ List<MenuItem> menuItems = new ArrayList<>();+ menuItems.add(new MenuItem() {++ @Override+ public String getIconClass() {+ return context.getMode() == Mode.BLAME?"fa fa-check":null;+ }++ @Override+ public String getLabel() {+ return "Blame";+ }++ @Override+ public AbstractLink newLink(String id) {+ AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>(id) {++ @Override+ public void onClick(AjaxRequestTarget target) {+ menuLink.close();+ boolean blamed = (context.getMode() != Mode.BLAME);+ String jsonOfBlameInfos = getJsonOfBlameInfos(blamed);+ String script = String.format("gitplex.sourceview.onBlame(%s);", jsonOfBlameInfos);+ target.appendJavaScript(script);+ context.onBlameChange(target, blamed);+ }++ };+ PageParameters params;+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = context.getBlobIdent();+ if (context.getMode() != Mode.BLAME)+ state.mode = Mode.BLAME;+ state.mark = context.getMark();+ params = DepotFilePage.paramsOf(context.getDepot(), state);+ CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);+ link.add(AttributeAppender.replace("href", url.toString()));+ link.add(new ViewStateAwareBehavior());+ return link;+ }++ });++ if (!symbols.isEmpty()) {+ menuItems.add(new MenuItem() {++ @Override+ public String getLabel() {+ return "Outline";+ }++ @Override+ public String getIconClass() {+ return outlineContainer.isVisible()?"fa fa-check":null;+ }++ @Override+ public AbstractLink newLink(String id) {+ return new AjaxLink<Void>(id) {++ @Override+ public void onClick(AjaxRequestTarget target) {+ menuLink.close();+ toggleOutline(target);+ }++ };+ }++ });+ }+ return menuItems;+ }++ private void toggleOutline(AjaxRequestTarget target) {+ WebResponse response = (WebResponse) RequestCycle.get().getResponse();+ Cookie cookie;+ if (outlineContainer.isVisible()) {+ cookie = new Cookie(COOKIE_OUTLINE, "no");+ outlineContainer.setVisible(false);+ } else {+ cookie = new Cookie(COOKIE_OUTLINE, "yes");+ outlineContainer.setVisible(true);+ }+ cookie.setMaxAge(Integer.MAX_VALUE);+ response.addCookie(cookie);+ target.add(outlineContainer);+ target.appendJavaScript("gitplex.sourceview.onToggleOutline();");+ }++ public void mark(AjaxRequestTarget target, TextRange mark, boolean scroll) {+ String script = String.format("gitplex.sourceview.mark(%s, %s);",+ getJson(mark), scroll);+ target.appendJavaScript(script);+ }++ private String getJson(TextRange mark) {+ try {+ return GitPlex.getInstance(ObjectMapper.class).writeValueAsString(mark);+ } catch (JsonProcessingException e) {+ throw new RuntimeException(e);+ }+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ commentContainer = new WebMarkupContainer("comment", Model.of((TextRange)null)) {++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(OnDomReadyHeaderItem.forScript("gitplex.sourceview.initComment();"));+ }++ };++ commentContainer.add(new WebSocketRenderBehavior() {++ @Override+ protected void onRender(WebSocketRequestHandler handler) {+ if (commentContainer.isVisible())+ handler.add(commentContainer.get("head").get("toggleResolve"));+ }++ });++ WebMarkupContainer head = new WebMarkupContainer("head");+ head.setOutputMarkupId(true);+ commentContainer.add(head);++ head.add(new Label("title", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ CodeComment comment = context.getOpenComment();+ return comment!=null?comment.getTitle():"";+ }++ }) {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(context.getOpenComment() != null);+ }++ });+ head.add(new DropdownLink("context") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(context.getOpenComment() != null);+ }++ @Override+ protected Component newContent(String id) {+ return new RevisionSelector(id, new AbstractReadOnlyModel<Depot>() {++ @Override+ public Depot getObject() {+ return context.getDepot();+ }++ }) {++ @Override+ protected void onSelect(AjaxRequestTarget target, String revision) {+ RevisionComparePage.State state = new RevisionComparePage.State();+ CodeComment comment = context.getOpenComment();+ state.commentId = comment.getId();+ state.mark = comment.getCommentPos();+ state.compareWithMergeBase = false;+ state.leftSide = new DepotAndRevision(context.getDepot(), comment.getCommentPos().getCommit());+ state.rightSide = new DepotAndRevision(context.getDepot(), revision);+ state.tabPanel = RevisionComparePage.TabPanel.CHANGES;+ PageParameters params = RevisionComparePage.paramsOf(context.getDepot(), state);+ setResponsePage(RevisionComparePage.class, params);+ }++ };+ }++ });+ head.add(new AjaxLink<Void>("locate") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ CodeComment comment = context.getOpenComment();+ TextRange mark;+ if (comment != null) {+ mark = comment.getCommentPos().getRange();+ } else {+ mark = (TextRange) commentContainer.getDefaultModelObject();+ }+ mark(target, mark, true);+ context.onMark(target, mark);+ target.appendJavaScript(String.format("$('#%s').blur();", getMarkupId()));+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();+ setOutputMarkupId(true);+ }++ });++ // use this instead of bookmarkable link as we want to get the link+ // updated whenever we re-render the comment container+ AttributeAppender appender = AttributeAppender.append("href", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ if (context.getOpenComment() != null) {+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = new BlobIdent(context.getBlobIdent());+ state.blobIdent.revision = context.getCommit().name();+ state.commentId = context.getOpenComment().getId();+ state.mark = context.getOpenComment().getCommentPos().getRange();+ return urlFor(DepotFilePage.class, DepotFilePage.paramsOf(context.getDepot(), state)).toString();+ } else {+ return "";+ }+ }++ });+ head.add(new WebMarkupContainer("permanent") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(context.getOpenComment() != null);+ }++ }.add(appender));++ head.add(new AjaxLink<Void>("close") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(commentContainer));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ clearComment(target);+ if (context.getOpenComment() != null)+ context.onCommentOpened(target, null);+ target.appendJavaScript("gitplex.sourceview.onCloseComment();");+ }++ });++ head.add(new AjaxLink<Void>("toggleResolve") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(commentContainer));+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(context.getOpenComment() != null);+ }++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ CodeComment comment = context.getOpenComment();+ if (comment != null) {+ if (comment.isResolved()) {+ tag.put("title", "Comment is currently resolved, click to unresolve");+ tag.put("class", "pull-right resolve resolved");+ } else {+ tag.put("title", "Comment is currently unresolved, click to resolve");+ tag.put("class", "pull-right resolve unresolved");+ }+ }+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ if (SecurityUtils.getAccount() != null) {+ ((CodeCommentPanel)commentContainer.get("body")).onChangeStatus(target);+ target.appendJavaScript("gitplex.sourceview.scrollToCommentBottom();");+ } else {+ Session.get().warn("Please login to resolve/unresolve comment");+ }+ }++ }.setOutputMarkupId(true));++ commentContainer.setOutputMarkupPlaceholderTag(true);+ if (context.getOpenComment() != null) {+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, context.getOpenComment().getId()) {++ @Override+ protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {+ SourceViewPanel.this.onCommentDeleted(target, comment);+ }++ @Override+ protected CompareContext getCompareContext(CodeComment comment) {+ return SourceViewPanel.this.getCompareContext();+ }++ @Override+ protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {+ target.add(commentContainer.get("head"));+ }++ @Override+ protected PullRequest getPullRequest() {+ return null;+ }++ };+ commentContainer.add(commentPanel);+ } else {+ commentContainer.add(new WebMarkupContainer(BODY_ID));+ commentContainer.setVisible(false);+ }+ add(commentContainer);++ add(ajaxBehavior = new AbstractPostAjaxBehavior() {++ @Override+ protected void respond(AjaxRequestTarget target) {+ IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();++ switch(params.getParameterValue("action").toString()) {+ case "showBlameMessage":+ String tooltipId = params.getParameterValue("param1").toString();+ String commitHash = params.getParameterValue("param2").toString();+ String message = context.getDepot().getRevCommit(commitHash).getFullMessage();+ String escapedMessage = JavaScriptEscape.escapeJavaScript(message);+ String script = String.format("gitplex.sourceview.showBlameMessage('%s', '%s');", tooltipId, escapedMessage);+ target.appendJavaScript(script);+ break;+ case "openSelectionPopover":+ TextRange mark = getMark(params, "param1", "param2", "param3", "param4");+ script = String.format("gitplex.sourceview.openSelectionPopover(%s, '%s', %s);",+ getJson(mark), context.getMarkUrl(mark),+ SecurityUtils.getAccount()!=null);+ target.appendJavaScript(script);+ break;+ case "addComment":+ Preconditions.checkNotNull(SecurityUtils.getAccount());++ mark = getMark(params, "param1", "param2", "param3", "param4");+ commentContainer.setDefaultModelObject(mark);++ Fragment fragment = new Fragment(BODY_ID, "newCommentFrag", SourceViewPanel.this);+ fragment.setOutputMarkupId(true);++ Form<?> form = new Form<Void>("form");++ String uuid = UUID.randomUUID().toString();++ TextField<String> titleInput = new TextField<String>("title", Model.of(""));+ titleInput.setRequired(true);+ form.add(titleInput);++ CommentInput contentInput;+ form.add(contentInput = new CommentInput("content", Model.of("")) {++ @Override+ protected DepotAttachmentSupport getAttachmentSupport() {+ return new DepotAttachmentSupport(context.getDepot(), uuid);+ }++ @Override+ protected Depot getDepot() {+ return context.getDepot();+ }++ });+ contentInput.setRequired(true);++ NotificationPanel feedback = new NotificationPanel("feedback", form);+ feedback.setOutputMarkupPlaceholderTag(true);+ form.add(feedback);++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ clearComment(target);+ target.appendJavaScript("gitplex.sourceview.onLayoutChange();");+ }++ });++ form.add(new AjaxButton("save") {++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(feedback);+ }++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);++ CodeComment comment = new CodeComment();+ comment.setUUID(uuid);+ comment.setCommentPos(new CommentPos());+ comment.getCommentPos().setCommit(context.getCommit().name());+ comment.getCommentPos().setPath(context.getBlobIdent().path);+ comment.setTitle(titleInput.getModelObject());+ comment.setContent(contentInput.getModelObject());+ comment.setDepot(context.getDepot());+ comment.setUser(SecurityUtils.getAccount());+ comment.getCommentPos().setRange(mark);+ comment.setCompareContext(getCompareContext());++ GitPlex.getInstance(CodeCommentManager.class).save(comment);++ CodeCommentPanel commentPanel = new CodeCommentPanel(fragment.getId(), comment.getId()) {++ @Override+ protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {+ SourceViewPanel.this.onCommentDeleted(target, comment);+ }++ @Override+ protected CompareContext getCompareContext(CodeComment comment) {+ return SourceViewPanel.this.getCompareContext();+ }++ @Override+ protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {+ target.add(commentContainer.get("head"));+ }++ @Override+ protected PullRequest getPullRequest() {+ return null;+ }++ };+ commentContainer.replace(commentPanel);+ target.add(commentContainer);++ String script = String.format("gitplex.sourceview.onCommentAdded(%s);",+ getJsonOfComment(comment));+ target.appendJavaScript(script);+ context.onCommentOpened(target, comment);+ }++ });+ fragment.add(form);+ commentContainer.replace(fragment);+ commentContainer.setVisible(true);+ target.add(commentContainer);+ context.onAddComment(target, mark);+ target.appendJavaScript(String.format("gitplex.sourceview.onAddComment(%s);", getJson(mark)));+ break;+ case "openComment":+ Long commentId = params.getParameterValue("param1").toLong();+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentId) {++ @Override+ protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {+ SourceViewPanel.this.onCommentDeleted(target, comment);+ }++ @Override+ protected CompareContext getCompareContext(CodeComment comment) {+ return SourceViewPanel.this.getCompareContext();+ }++ @Override+ protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {+ target.add(commentContainer.get("head"));+ }++ @Override+ protected PullRequest getPullRequest() {+ return null;+ }++ };+ commentContainer.replace(commentPanel);+ commentContainer.setVisible(true);+ target.add(commentContainer);+ CodeComment comment = GitPlex.getInstance(CodeCommentManager.class).load(commentId);+ script = String.format("gitplex.sourceview.onOpenComment(%s);", getJsonOfComment(comment));+ target.appendJavaScript(script);+ context.onCommentOpened(target, comment);+ break;+ }+ }++ });++ outlineContainer = new WebMarkupContainer("outline") {++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(OnDomReadyHeaderItem.forScript("gitplex.sourceview.initOutline();"));+ }++ };+ outlineContainer.add(new AjaxLink<Void>("close") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ toggleOutline(target);+ }++ });+ NestedTree<Symbol> tree;+ outlineContainer.add(tree = new NestedTree<Symbol>(BODY_ID, new ITreeProvider<Symbol>() {++ @Override+ public void detach() {+ }++ @Override+ public Iterator<? extends Symbol> getRoots() {+ return getChildSymbols(null).iterator();+ }++ @Override+ public boolean hasChildren(Symbol symbol) {+ return !getChildSymbols(symbol).isEmpty();+ }++ @Override+ public Iterator<? extends Symbol> getChildren(Symbol symbol) {+ return getChildSymbols(symbol).iterator();+ }++ @Override+ public IModel<Symbol> model(Symbol symbol) {+ return Model.of(symbol);+ }++ }) {++ @Override+ protected void onInitialize() {+ super.onInitialize();+ add(new HumanTheme());+ }++ @Override+ protected Component newContentComponent(String id, IModel<Symbol> nodeModel) {+ Fragment fragment = new Fragment(id, "outlineNodeFrag", SourceViewPanel.this);+ Symbol symbol = nodeModel.getObject();++ fragment.add(new Image("icon", symbol.getIcon()));++ AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ context.onSelect(target, context.getBlobIdent(), symbol.getPos());+ }++ };+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = context.getBlobIdent();+ state.commentId = CodeComment.idOf(context.getOpenComment());+ state.mark = TextRange.of(symbol.getPos());+ PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);+ link.add(AttributeAppender.replace("href", urlFor(DepotFilePage.class, params).toString()));+ link.add(symbol.render("label", null));+ fragment.add(link);++ return fragment;+ }++ });++ for (Symbol root: getChildSymbols(null))+ tree.expand(root);++ outlineContainer.setOutputMarkupPlaceholderTag(true);+ add(outlineContainer);++ if (!symbols.isEmpty()) {+ WebRequest request = (WebRequest) RequestCycle.get().getRequest();+ Cookie cookie = request.getCookie(COOKIE_OUTLINE);+ if (cookie!=null && cookie.getValue().equals("no"))+ outlineContainer.setVisible(false);+ } else {+ outlineContainer.setVisible(false);+ }++ add(symbolTooltip = new SymbolTooltipPanel("symbolTooltip", new AbstractReadOnlyModel<Depot>() {++ @Override+ public Depot getObject() {+ return context.getDepot();+ }++ }) {++ @Override+ protected void onSelect(AjaxRequestTarget target, QueryHit hit) {+ BlobIdent blobIdent = new BlobIdent(+ getRevision(), hit.getBlobPath(), FileMode.REGULAR_FILE.getBits());+ context.onSelect(target, blobIdent, hit.getTokenPos());+ }++ @Override+ protected void onOccurrencesQueried(AjaxRequestTarget target, List<QueryHit> hits) {+ context.onSearchComplete(target, hits);+ }++ @Override+ protected String getBlobPath() {+ return context.getBlobIdent().path;+ }++ });+ }++ private TextRange getMark(IRequestParameters params, String beginLineParam, String beginCharParam,+ String endLineParam, String endCharParam) {+ int beginLine = params.getParameterValue(beginLineParam).toInt();+ int beginChar = params.getParameterValue(beginCharParam).toInt();+ int endLine = params.getParameterValue(endLineParam).toInt();+ int endChar = params.getParameterValue(endCharParam).toInt();+ TextRange mark = new TextRange();+ mark.beginLine = beginLine;+ mark.beginChar = beginChar;+ mark.endLine = endLine;+ mark.endChar = endChar;+ return mark;+ }++ private String getJsonOfComment(CodeComment comment) {+ CommentInfo commentInfo = new CommentInfo();+ commentInfo.id = comment.getId();+ commentInfo.mark = comment.getCommentPos().getRange();+ commentInfo.title = comment.getTitle();++ String jsonOfCommentInfo;+ try {+ jsonOfCommentInfo = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfo);+ } catch (JsonProcessingException e) {+ throw new RuntimeException(e);+ }+ return jsonOfCommentInfo;+ }++ private void clearComment(AjaxRequestTarget target) {+ commentContainer.replace(new WebMarkupContainer(BODY_ID));+ commentContainer.setVisible(false);+ target.add(commentContainer);+ }++ private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {+ clearComment(target);+ String script = String.format("gitplex.sourceview.onCommentDeleted(%s);",+ getJsonOfComment(comment));+ target.appendJavaScript(script);+ context.onCommentOpened(target, null);+ }++ private List<Symbol> getChildSymbols(@Nullable Symbol parentSymbol) {+ List<Symbol> children = new ArrayList<>();+ for (Symbol symbol: symbols) {+ if (symbol.getParent() == parentSymbol)+ children.add(symbol);+ }+ return children;+ }++ private String getJsonOfBlameInfos(boolean blamed) {+ String jsonOfBlameInfos;+ if (blamed) {+ List<BlameInfo> blameInfos = new ArrayList<>();++ String commitHash = context.getCommit().name();++ BlameCommand cmd = new BlameCommand(context.getDepot().getDirectory());+ cmd.commitHash(commitHash).file(context.getBlobIdent().path);+ for (Blame blame: cmd.call().values()) {+ BlameInfo blameInfo = new BlameInfo();+ blameInfo.commitDate = DateUtils.formatDate(blame.getCommit().getCommitter().getWhen());+ blameInfo.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());+ blameInfo.hash = blame.getCommit().getHash();+ blameInfo.abbreviatedHash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);+ CommitDetailPage.State state = new CommitDetailPage.State();+ state.revision = blame.getCommit().getHash();+ state.pathFilter = context.getBlobIdent().path;+ PageParameters params = CommitDetailPage.paramsOf(context.getDepot(), state);+ blameInfo.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();+ blameInfo.ranges = blame.getRanges();+ blameInfos.add(blameInfo);+ }+ try {+ jsonOfBlameInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(blameInfos);+ } catch (JsonProcessingException e) {+ throw new RuntimeException(e);+ }+ } else {+ jsonOfBlameInfos = "undefined";+ }+ return jsonOfBlameInfos;+ }++ private CompareContext getCompareContext() {+ CompareContext compareContext = new CompareContext();+ compareContext.setCompareCommit(context.getCommit().name());+ compareContext.setPathFilter(context.getBlobIdent().path);+ return compareContext;+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);++ response.render(JavaScriptHeaderItem.forReference(new SourceViewResourceReference()));++ Blob blob = context.getDepot().getBlob(context.getBlobIdent());++ String jsonOfBlameInfos = getJsonOfBlameInfos(context.getMode() == Mode.BLAME);+ Map<Integer, List<CommentInfo>> commentInfos = new HashMap<>();+ for (CodeComment comment: commentsModel.getObject()) {+ if (comment.getCommentPos().getRange() != null) {+ int line = comment.getCommentPos().getRange().getBeginLine();+ List<CommentInfo> commentInfosAtLine = commentInfos.get(line);+ if (commentInfosAtLine == null) {+ commentInfosAtLine = new ArrayList<>();+ commentInfos.put(line, commentInfosAtLine);+ }+ CommentInfo commentInfo = new CommentInfo();+ commentInfo.id = comment.getId();+ commentInfo.mark = comment.getCommentPos().getRange();+ commentInfo.title = comment.getTitle();+ commentInfosAtLine.add(commentInfo);+ }+ }+ for (List<CommentInfo> value: commentInfos.values()) {+ value.sort((o1, o2)->(int)(o1.id-o2.id));+ }++ String jsonOfCommentInfos;+ try {+ jsonOfCommentInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfos);+ } catch (JsonProcessingException e) {+ throw new RuntimeException(e);+ }+ CharSequence callback = ajaxBehavior.getCallbackFunction(+ explicit("action"), explicit("param1"), explicit("param2"),+ explicit("param3"), explicit("param4"));+ String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);+ String script = String.format("gitplex.sourceview.init('%s', '%s', %s, %s, '%s', '%s', "+ + "%s, %s, %s, %s, %s);",+ JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),+ JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),+ context.getOpenComment()!=null?getJsonOfComment(context.getOpenComment()):"undefined",+ context.getMark()!=null?getJson(context.getMark()):"undefined",+ symbolTooltip.getMarkupId(),+ context.getBlobIdent().revision,+ jsonOfBlameInfos,+ jsonOfCommentInfos,+ callback,+ viewState!=null?"JSON.parse('"+viewState+"')":"undefined",+ SecurityUtils.getAccount()!=null);+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ @Override+ protected void onDetach() {+ commentsModel.detach();+ super.onDetach();+ }++ @SuppressWarnings("unused")+ private static class BlameInfo {++ String abbreviatedHash;++ String hash;++ String url;++ String authorName;++ String commitDate;++ List<Range> ranges;+ }++ @SuppressWarnings("unused")+ private static class CommentInfo {+ long id;++ String title;++ TextRange mark;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.javaindex 8bb2fa56b1..b9a417fd45 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java@@ -36,8 +36,8 @@ import com.pmease.commons.git.BlobChange;import com.pmease.commons.git.BlobIdent;import com.pmease.commons.git.FileEdit;import com.pmease.commons.git.PathAndContent;-import com.pmease.commons.git.exception.NotTreeException;-import com.pmease.commons.git.exception.ObjectAlreadyExistException;+import com.pmease.commons.git.exception.NotGitTreeException;+import com.pmease.commons.git.exception.GitObjectAlreadyExistsException;import com.pmease.commons.git.exception.ObsoleteCommitException;import com.pmease.commons.lang.diff.WhitespaceOption;import com.pmease.gitplex.core.GitPlex;@@ -224,7 +224,7 @@ public abstract class EditSavePanel extends Panel {protected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);- String viewState = RequestCycle.get().getRequest().getRequestParameters()+ String viewState = RequestCycle.get().getRequest().getPostParameters().getParameterValue("view_state").toString();RequestCycle.get().setMetaData(DepotFilePage.VIEW_STATE_KEY, viewState);@@ -296,12 +296,12 @@ public abstract class EditSavePanel extends Panel {} catch (IOException e2) {throw new RuntimeException(e2);}- } catch (ObjectAlreadyExistException e) {+ } catch (GitObjectAlreadyExistsException e) {EditSavePanel.this.error("A file with same name already exists. "+ "Please choose a different name and try again.");target.add(feedback);break;- } catch (NotTreeException e) {+ } catch (NotGitTreeException e) {EditSavePanel.this.error("A file exists where you’re trying to create a subdirectory. "+ "Choose a new path and try again..");target.add(feedback);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.javaindex 6b6c6c6d57..7a3cbefbe3 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java@@ -3,7 +3,6 @@ package com.pmease.gitplex.web.component.depotfile.fileedit;import javax.annotation.Nullable;import org.apache.commons.lang3.StringEscapeUtils;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;@@ -31,6 +30,7 @@ import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.PathAndContent;import com.pmease.commons.lang.diff.WhitespaceOption;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.component.ViewStateAwareAjaxLink;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.entity.Depot;@@ -60,9 +60,9 @@ public abstract class FileEditPanel extends Panel {private final TextRange mark;- private AbstractDefaultAjaxBehavior previewBehavior;+ private AbstractPostAjaxBehavior previewBehavior;- private AbstractDefaultAjaxBehavior saveBehavior;+ private AbstractPostAjaxBehavior saveBehavior;private EditSavePanel editSavePanel;@@ -84,7 +84,7 @@ public abstract class FileEditPanel extends Panel {protected void onInitialize() {super.onInitialize();- previewBehavior = new AbstractDefaultAjaxBehavior() {+ previewBehavior = new AbstractPostAjaxBehavior() {@Overrideprotected void updateAjaxAttributes(AjaxRequestAttributes attributes) {@@ -139,7 +139,7 @@ public abstract class FileEditPanel extends Panel {};add(new WebMarkupContainer("previewLink").add(previewBehavior));- saveBehavior = new AbstractDefaultAjaxBehavior() {+ saveBehavior = new AbstractPostAjaxBehavior() {@Overrideprotected void updateAjaxAttributes(AjaxRequestAttributes attributes) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.javaindex 1da9fffeaa..fd631c866a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java@@ -1,574 +1,628 @@-package com.pmease.gitplex.web.component.depotfile.filenavigator;--import java.io.IOException;-import java.util.ArrayList;-import java.util.Collections;-import java.util.Iterator;-import java.util.List;--import javax.annotation.Nullable;--import org.apache.wicket.Component;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;-import org.apache.wicket.ajax.markup.html.AjaxLink;-import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;-import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;-import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;-import org.apache.wicket.markup.ComponentTag;-import org.apache.wicket.markup.head.CssHeaderItem;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;-import org.apache.wicket.markup.html.WebMarkupContainer;-import org.apache.wicket.markup.html.basic.Label;-import org.apache.wicket.markup.html.form.TextField;-import org.apache.wicket.markup.html.link.AbstractLink;-import org.apache.wicket.markup.html.link.Link;-import org.apache.wicket.markup.html.link.ResourceLink;-import org.apache.wicket.markup.html.list.ListItem;-import org.apache.wicket.markup.html.list.ListView;-import org.apache.wicket.markup.html.panel.Fragment;-import org.apache.wicket.markup.html.panel.Panel;-import org.apache.wicket.model.IModel;-import org.apache.wicket.model.LoadableDetachableModel;-import org.apache.wicket.model.Model;-import org.apache.wicket.request.cycle.RequestCycle;-import org.apache.wicket.request.mapper.parameter.PageParameters;-import org.eclipse.jgit.lib.FileMode;-import org.eclipse.jgit.lib.ObjectId;-import org.eclipse.jgit.lib.Repository;-import org.eclipse.jgit.revwalk.RevTree;-import org.eclipse.jgit.revwalk.RevWalk;-import org.eclipse.jgit.treewalk.TreeWalk;--import com.google.common.base.Preconditions;-import com.google.common.base.Splitter;-import com.pmease.commons.git.BlobIdent;-import com.pmease.commons.util.StringUtils;-import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;-import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;-import com.pmease.commons.wicket.component.DropdownLink;-import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;-import com.pmease.commons.wicket.component.ViewStateAwareAjaxLink;-import com.pmease.commons.wicket.component.floating.AlignPlacement;-import com.pmease.commons.wicket.component.floating.FloatingPanel;-import com.pmease.commons.wicket.component.menu.MenuItem;-import com.pmease.commons.wicket.component.menu.MenuLink;-import com.pmease.gitplex.core.security.SecurityUtils;-import com.pmease.gitplex.web.component.BlobIcon;-import com.pmease.gitplex.web.component.depotfile.blobview.BlobNameChangeCallback;-import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;-import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;-import com.pmease.gitplex.web.page.depot.commit.DepotCommitsPage;-import com.pmease.gitplex.web.page.depot.file.DepotFilePage;-import com.pmease.gitplex.web.resource.BlobResource;-import com.pmease.gitplex.web.resource.BlobResourceReference;--@SuppressWarnings("serial")-public abstract class FileNavigator extends Panel {-- private final static String LAST_SEGMENT_ID = "lastSegment";-- private final BlobViewContext context;-- private final BlobNameChangeCallback callback;-- public FileNavigator(String id, BlobViewContext context, @Nullable BlobNameChangeCallback callback) {- super(id);-- this.context = context;- this.callback = callback;- }-- @Override- protected void onInitialize() {- super.onInitialize();-- add(new ListView<BlobIdent>("treeSegments", new LoadableDetachableModel<List<BlobIdent>>() {-- @Override- protected List<BlobIdent> load() {- BlobIdent file = context.getBlobIdent();- List<BlobIdent> treeSegments = new ArrayList<>();- treeSegments.add(new BlobIdent(file.revision, null, FileMode.TREE.getBits()));-- if (file.path != null) {- List<String> segments = Splitter.on('/').omitEmptyStrings().splitToList(file.path);-- for (int i=0; i<segments.size(); i++) {- BlobIdent parent = treeSegments.get(treeSegments.size()-1);- int treeMode = FileMode.TREE.getBits();- if (i<segments.size()-1 || file.mode == treeMode) {- String treePath = segments.get(i);- if (parent.path != null)- treePath = parent.path + "/" + treePath;- treeSegments.add(new BlobIdent(file.revision, treePath, treeMode));- }- }- }-- return treeSegments;- }-- }) {-- @Override- protected void populateItem(final ListItem<BlobIdent> item) {- final BlobIdent blobIdent = item.getModelObject();- AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());- }-- @Override- public void onClick(AjaxRequestTarget target) {- context.onSelect(target, blobIdent, null);- }-- @Override- protected void onComponentTag(ComponentTag tag) {- super.onComponentTag(tag);- DepotFilePage.State state = new DepotFilePage.State();- state.blobIdent = blobIdent;- PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);- tag.put("href", urlFor(DepotFilePage.class, params));- }-- };- link.setEnabled(!context.getBlobIdent().isTree() || item.getIndex() != getViewSize()-1);-- if (blobIdent.path != null) {- if (blobIdent.path.indexOf('/') != -1)- link.add(new Label("label", StringUtils.substringAfterLast(blobIdent.path, "/")));- else- link.add(new Label("label", blobIdent.path));- } else {- link.add(new Label("label", context.getDepot().getName()));- }-- item.add(link);-- item.add(new DropdownLink("subtreeDropdownTrigger", AlignPlacement.bottom(6)) {-- @Override- protected void onInitialize(FloatingPanel dropdown) {- super.onInitialize(dropdown);- dropdown.add(AttributeAppender.append("class", "subtree-dropdown"));- }-- @Override- protected Component newContent(String id) {- return new NestedTree<BlobIdent>(id, new ITreeProvider<BlobIdent>() {-- @Override- public void detach() {- }-- @Override- public Iterator<? extends BlobIdent> getRoots() {- Repository repository = context.getDepot().getRepository();- try (RevWalk revWalk = new RevWalk(repository)) {- RevTree revTree = revWalk.parseCommit(getCommitId()).getTree();- TreeWalk treeWalk;- if (blobIdent.path != null) {- treeWalk = Preconditions.checkNotNull(TreeWalk.forPath(repository, blobIdent.path, revTree));- treeWalk.enterSubtree();- } else {- treeWalk = new TreeWalk(repository);- treeWalk.addTree(revTree);- }- treeWalk.setRecursive(false);-- List<BlobIdent> roots = new ArrayList<>();- while (treeWalk.next())- roots.add(new BlobIdent(context.getBlobIdent().revision, treeWalk.getPathString(), treeWalk.getRawMode(0)));- Collections.sort(roots);- return roots.iterator();- } catch (IOException e) {- throw new RuntimeException(e);- }- }-- @Override- public boolean hasChildren(BlobIdent blobIdent) {- return blobIdent.isTree();- }-- @Override- public Iterator<? extends BlobIdent> getChildren(BlobIdent blobIdent) {- return FileNavigator.this.getChildren(blobIdent).iterator();- }-- @Override- public IModel<BlobIdent> model(BlobIdent blobIdent) {- return Model.of(blobIdent);- }-- }) {-- @Override- protected void onInitialize() {- super.onInitialize();- add(new HumanTheme());- }-- @Override- public void expand(BlobIdent blobIdent) {- super.expand(blobIdent);-- List<BlobIdent> children = getChildren(blobIdent);- if (children.size() == 1 && children.get(0).isTree())- expand(children.get(0));- }-- @Override- protected Component newContentComponent(String id, final IModel<BlobIdent> model) {- BlobIdent blobIdent = model.getObject();- Fragment fragment = new Fragment(id, "treeNodeFrag", FileNavigator.this);-- fragment.add(new BlobIcon("icon", model));-- AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());- }-- @Override- public void onClick(AjaxRequestTarget target) {- context.onSelect(target, model.getObject(), null);- close();- }-- @Override- protected void onComponentTag(ComponentTag tag) {- super.onComponentTag(tag);-- DepotFilePage.State state = new DepotFilePage.State();- state.blobIdent = model.getObject();- PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);- tag.put("href", urlFor(DepotFilePage.class, params));- }-- };- if (blobIdent.path.indexOf('/') != -1)- link.add(new Label("label", StringUtils.substringAfterLast(blobIdent.path, "/")));- else- link.add(new Label("label", blobIdent.path));- fragment.add(link);-- return fragment;- }-- };- }-- });- }-- });-- WebMarkupContainer lastSegment;- BlobIdent file = context.getBlobIdent();- if (callback != null) {- lastSegment = new Fragment(LAST_SEGMENT_ID, "nameEditFrag", this);-- String name;- if (file.isTree())- name = "";- else if (file.path.contains("/"))- name = StringUtils.substringAfterLast(file.path, "/");- else- name = file.path;-- final TextField<String> nameInput = new TextField<String>("name", Model.of(name));- lastSegment.add(nameInput);- nameInput.add(new OnChangeAjaxBehavior() {-- @Override- protected void onUpdate(AjaxRequestTarget target) {- callback.onChange(target, nameInput.getInput());- }-- });- if (name.length() == 0)- nameInput.add(AttributeAppender.append("class", "focusable"));- lastSegment.add(AttributeAppender.append("class", "input"));- } else if (file.isFile()) {- lastSegment = new Fragment(LAST_SEGMENT_ID, "blobNameFrag", this);-- String blobName = file.path;- if (blobName.contains("/"))- blobName = StringUtils.substringAfterLast(blobName, "/");- lastSegment.add(new Label("label", blobName));- } else {- lastSegment = new WebMarkupContainer(LAST_SEGMENT_ID);- }- add(lastSegment);-- if (callback == null) {- add(new MenuLink("fileMenu") {-- @Override- protected List<MenuItem> getMenuItems() {- List<MenuItem> generalItems = new ArrayList<>();- generalItems.add(new MenuItem() {-- @Override- public String getIconClass() {- return "fa-history";- }-- @Override- public String getLabel() {- return "History";- }-- @Override- public AbstractLink newLink(String id) {- return new Link<Void>(id) {-- @Override- public void onClick() {- DepotCommitsPage.State state = new DepotCommitsPage.State();- String commitHash = context.getDepot().getObjectId(file.revision).name();- state.setCompareWith(commitHash);- if (file.path != null)- state.setQuery(String.format("path(%s)", file.path));- setResponsePage(DepotCommitsPage.class, DepotCommitsPage.paramsOf(context.getDepot(), state));- }-- };- }-- });- if (file.isFile()) {- generalItems.add(new MenuItem() {-- @Override- public String getIconClass() {- return "fa-file-text-o";- }-- @Override- public String getLabel() {- return "Raw";- }-- @Override- public AbstractLink newLink(String id) {- return new ResourceLink<Void>(id, new BlobResourceReference(),- BlobResource.paramsOf(context.getDepot(), file)) {-- @Override- protected CharSequence getOnClickScript(CharSequence url) {- return closeBeforeClick(super.getOnClickScript(url));- }-- };- }-- });- }-- String path = file.path;- if (path != null && file.isTree())- path += "/";-- List<MenuItem> changeItems = new ArrayList<>();- if (file.isTree() && context.isOnBranch() && SecurityUtils.canModify(context.getDepot(), file.revision, path)) {- changeItems.add(new MenuItem() {-- @Override- public String getIconClass() {- return "fa-plus";- }-- @Override- public String getLabel() {- return "Create new file";- }-- @Override- public AbstractLink newLink(String id) {- return new AjaxLink<Void>(id) {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());- }-- @Override- public void onClick(AjaxRequestTarget target) {- close();- onNewFile(target);- }-- };- }-- });- }-- if (file.isFile() && context.getDepot().getBlob(file).getText() != null- && context.isOnBranch()- && SecurityUtils.canModify(context.getDepot(), file.revision, path)) {- changeItems.add(new MenuItem() {-- @Override- public String getIconClass() {- return "fa-pencil";- }-- @Override- public String getLabel() {- return "Edit";- }-- @Override- public AbstractLink newLink(String id) {- AbstractLink link = new ViewStateAwareAjaxLink<Void>(id) {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());- }-- @Override- public void onClick(AjaxRequestTarget target, String viewState) {- close();- RequestCycle.get().setMetaData(DepotFilePage.VIEW_STATE_KEY, viewState);- context.onEdit(target);- }- };-- PageParameters params;- DepotFilePage.State state = new DepotFilePage.State();- state.blobIdent = context.getBlobIdent();- state.mode = Mode.EDIT;- state.mark = context.getMark();- params = DepotFilePage.paramsOf(context.getDepot(), state);- CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);- link.add(AttributeAppender.replace("href", url.toString()));- link.add(new ViewStateAwareBehavior());- return link;- }-- });- }-- if (file.isFile() && context.isOnBranch()- && SecurityUtils.canModify(context.getDepot(), file.revision, path)) {- changeItems.add(new MenuItem() {-- @Override- public String getIconClass() {- return "fa-trash";- }-- @Override- public String getLabel() {- return "Delete";- }-- @Override- public AbstractLink newLink(String id) {- AbstractLink link = new PreventDefaultAjaxLink<Void>(id) {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());- }-- @Override- public void onClick(AjaxRequestTarget target) {- close();- context.onDelete(target);- }-- };- DepotFilePage.State state = new DepotFilePage.State();- state.blobIdent = context.getBlobIdent();- state.mode = Mode.EDIT;- PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);- CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);- link.add(AttributeAppender.replace("href", url.toString()));- return link;- }-- });- }-- List<MenuItem> customItems = context.getMenuItems(this);-- List<MenuItem> menuItems = new ArrayList<>(generalItems);- if (!changeItems.isEmpty()) {- if (!menuItems.isEmpty())- menuItems.add(null); // add separator- menuItems.addAll(changeItems);- }- if (!customItems.isEmpty()) {- if (!menuItems.isEmpty())- menuItems.add(null); // add separator- menuItems.addAll(customItems);- }- return menuItems;- }-- });- } else {- add(new WebMarkupContainer("fileMenu").setVisible(false));- }-- setOutputMarkupId(true);- }-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);- response.render(CssHeaderItem.forReference(new FileNavigatorResourceReference()));-- if (context.getBlobIdent().isTree()) {- String script = String.format("$('#%s input[type=text]').focus();", getMarkupId());- response.render(OnDomReadyHeaderItem.forScript(script));- }-- String script = String.format("$('#%s form').submit(false);", getMarkupId());- response.render(OnDomReadyHeaderItem.forScript(script));- }-- private ObjectId getCommitId() {- return context.getDepot().getObjectId(context.getBlobIdent().revision);- }-- protected abstract void onNewFile(AjaxRequestTarget target);-- private List<BlobIdent> getChildren(BlobIdent blobIdent) {- Repository repository = context.getDepot().getRepository();- try (RevWalk revWalk = new RevWalk(repository)) {- RevTree revTree = revWalk.parseCommit(getCommitId()).getTree();- TreeWalk treeWalk = TreeWalk.forPath(repository, blobIdent.path, revTree);- treeWalk.setRecursive(false);- treeWalk.enterSubtree();-- List<BlobIdent> children = new ArrayList<>();- while (treeWalk.next())- children.add(new BlobIdent(context.getBlobIdent().revision, treeWalk.getPathString(), treeWalk.getRawMode(0)));- Collections.sort(children);- return children;- } catch (IOException e) {- throw new RuntimeException(e);- }- }--}+package com.pmease.gitplex.web.component.depotfile.filenavigator;++import java.io.IOException;+import java.util.ArrayList;+import java.util.Collections;+import java.util.Iterator;+import java.util.List;++import javax.annotation.Nullable;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.attributes.IAjaxCallListener;+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;+import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;+import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;+import org.apache.wicket.markup.ComponentTag;+import org.apache.wicket.markup.head.CssHeaderItem;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.form.TextField;+import org.apache.wicket.markup.html.link.AbstractLink;+import org.apache.wicket.markup.html.link.Link;+import org.apache.wicket.markup.html.link.ResourceLink;+import org.apache.wicket.markup.html.list.ListItem;+import org.apache.wicket.markup.html.list.ListView;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.IModel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;+import org.apache.wicket.request.cycle.RequestCycle;+import org.apache.wicket.request.mapper.parameter.PageParameters;+import org.eclipse.jgit.lib.FileMode;+import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.lib.Repository;+import org.eclipse.jgit.revwalk.RevTree;+import org.eclipse.jgit.revwalk.RevWalk;+import org.eclipse.jgit.treewalk.TreeWalk;++import com.google.common.base.Preconditions;+import com.google.common.base.Splitter;+import com.pmease.commons.git.BlobIdent;+import com.pmease.commons.util.StringUtils;+import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;+import com.pmease.commons.wicket.component.DropdownLink;+import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;+import com.pmease.commons.wicket.component.ViewStateAwareAjaxLink;+import com.pmease.commons.wicket.component.floating.AlignPlacement;+import com.pmease.commons.wicket.component.floating.FloatingPanel;+import com.pmease.commons.wicket.component.menu.MenuItem;+import com.pmease.commons.wicket.component.menu.MenuLink;+import com.pmease.gitplex.core.security.SecurityUtils;+import com.pmease.gitplex.web.component.BlobIcon;+import com.pmease.gitplex.web.component.depotfile.blobview.BlobNameChangeCallback;+import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;+import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;+import com.pmease.gitplex.web.page.depot.commit.DepotCommitsPage;+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;+import com.pmease.gitplex.web.resource.BlobResource;+import com.pmease.gitplex.web.resource.BlobResourceReference;++@SuppressWarnings("serial")+public abstract class FileNavigator extends Panel {++ private final static String LAST_SEGMENT_ID = "lastSegment";++ private final BlobViewContext context;++ private final BlobNameChangeCallback callback;++ public FileNavigator(String id, BlobViewContext context, @Nullable BlobNameChangeCallback callback) {+ super(id);++ this.context = context;+ this.callback = callback;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(new ListView<BlobIdent>("treeSegments", new LoadableDetachableModel<List<BlobIdent>>() {++ @Override+ protected List<BlobIdent> load() {+ BlobIdent file = context.getBlobIdent();+ List<BlobIdent> treeSegments = new ArrayList<>();+ treeSegments.add(new BlobIdent(file.revision, null, FileMode.TREE.getBits()));++ if (file.path != null) {+ List<String> segments = Splitter.on('/').omitEmptyStrings().splitToList(file.path);++ for (int i=0; i<segments.size(); i++) {+ BlobIdent parent = treeSegments.get(treeSegments.size()-1);+ int treeMode = FileMode.TREE.getBits();+ if (i<segments.size()-1 || file.mode == treeMode) {+ String treePath = segments.get(i);+ if (parent.path != null)+ treePath = parent.path + "/" + treePath;+ treeSegments.add(new BlobIdent(file.revision, treePath, treeMode));+ }+ }+ }++ return treeSegments;+ }++ }) {++ @Override+ protected void populateItem(final ListItem<BlobIdent> item) {+ final BlobIdent blobIdent = item.getModelObject();+ AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ context.onSelect(target, blobIdent, null);+ }++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = blobIdent;+ PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);+ tag.put("href", urlFor(DepotFilePage.class, params));+ }++ };+ link.setEnabled(!context.getBlobIdent().isTree() || item.getIndex() != getViewSize()-1);++ if (blobIdent.path != null) {+ if (blobIdent.path.indexOf('/') != -1)+ link.add(new Label("label", StringUtils.substringAfterLast(blobIdent.path, "/")));+ else+ link.add(new Label("label", blobIdent.path));+ } else {+ link.add(new Label("label", context.getDepot().getName()));+ }++ item.add(link);++ item.add(new DropdownLink("subtreeDropdownTrigger", AlignPlacement.bottom(6)) {++ @Override+ protected void onInitialize(FloatingPanel dropdown) {+ super.onInitialize(dropdown);+ dropdown.add(AttributeAppender.append("class", "subtree-dropdown"));+ }++ @Override+ protected Component newContent(String id) {+ return new NestedTree<BlobIdent>(id, new ITreeProvider<BlobIdent>() {++ @Override+ public void detach() {+ }++ @Override+ public Iterator<? extends BlobIdent> getRoots() {+ Repository repository = context.getDepot().getRepository();+ try (RevWalk revWalk = new RevWalk(repository)) {+ RevTree revTree = revWalk.parseCommit(getCommitId()).getTree();+ TreeWalk treeWalk;+ if (blobIdent.path != null) {+ treeWalk = Preconditions.checkNotNull(TreeWalk.forPath(repository, blobIdent.path, revTree));+ treeWalk.enterSubtree();+ } else {+ treeWalk = new TreeWalk(repository);+ treeWalk.addTree(revTree);+ }+ treeWalk.setRecursive(false);++ List<BlobIdent> roots = new ArrayList<>();+ while (treeWalk.next())+ roots.add(new BlobIdent(context.getBlobIdent().revision, treeWalk.getPathString(), treeWalk.getRawMode(0)));+ Collections.sort(roots);+ return roots.iterator();+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }++ @Override+ public boolean hasChildren(BlobIdent blobIdent) {+ return blobIdent.isTree();+ }++ @Override+ public Iterator<? extends BlobIdent> getChildren(BlobIdent blobIdent) {+ return FileNavigator.this.getChildren(blobIdent).iterator();+ }++ @Override+ public IModel<BlobIdent> model(BlobIdent blobIdent) {+ return Model.of(blobIdent);+ }++ }) {++ @Override+ protected void onInitialize() {+ super.onInitialize();+ add(new HumanTheme());+ }++ @Override+ public void expand(BlobIdent blobIdent) {+ super.expand(blobIdent);++ List<BlobIdent> children = getChildren(blobIdent);+ if (children.size() == 1 && children.get(0).isTree())+ expand(children.get(0));+ }++ @Override+ protected Component newContentComponent(String id, final IModel<BlobIdent> model) {+ BlobIdent blobIdent = model.getObject();+ Fragment fragment = new Fragment(id, "treeNodeFrag", FileNavigator.this);++ fragment.add(new BlobIcon("icon", model));++ AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ context.onSelect(target, model.getObject(), null);+ close();+ }++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);++ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = model.getObject();+ PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);+ tag.put("href", urlFor(DepotFilePage.class, params));+ }++ };+ if (blobIdent.path.indexOf('/') != -1)+ link.add(new Label("label", StringUtils.substringAfterLast(blobIdent.path, "/")));+ else+ link.add(new Label("label", blobIdent.path));+ fragment.add(link);++ return fragment;+ }++ };+ }++ });+ }++ });++ WebMarkupContainer lastSegment;+ BlobIdent file = context.getBlobIdent();+ if (callback != null) {+ lastSegment = new Fragment(LAST_SEGMENT_ID, "nameEditFrag", this);++ String name;+ if (file.isTree())+ name = "";+ else if (file.path.contains("/"))+ name = StringUtils.substringAfterLast(file.path, "/");+ else+ name = file.path;++ final TextField<String> nameInput = new TextField<String>("name", Model.of(name));+ lastSegment.add(nameInput);+ nameInput.add(new OnChangeAjaxBehavior() {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ callback.onChange(target, nameInput.getInput());+ }++ });+ if (name.length() == 0)+ nameInput.add(AttributeAppender.append("class", "focusable"));+ lastSegment.add(AttributeAppender.append("class", "input"));+ } else if (file.isFile()) {+ lastSegment = new Fragment(LAST_SEGMENT_ID, "blobNameFrag", this);++ String blobName = file.path;+ if (blobName.contains("/"))+ blobName = StringUtils.substringAfterLast(blobName, "/");+ lastSegment.add(new Label("label", blobName));+ } else {+ lastSegment = new WebMarkupContainer(LAST_SEGMENT_ID);+ }+ add(lastSegment);++ if (callback == null) {+ add(new MenuLink("fileMenu") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new IAjaxCallListener() {++ @Override+ public CharSequence getSuccessHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getPrecondition(Component component) {+ return null;+ }++ @Override+ public CharSequence getInitHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getFailureHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getDoneHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getCompleteHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getBeforeSendHandler(Component component) {+ return null;+ }++ @Override+ public CharSequence getBeforeHandler(Component component) {+ return "$('.autofit:visible').first().trigger('storeViewState');";+ }++ @Override+ public CharSequence getAfterHandler(Component component) {+ return null;+ }++ });+ }++ @Override+ protected List<MenuItem> getMenuItems() {+ List<MenuItem> generalItems = new ArrayList<>();+ generalItems.add(new MenuItem() {++ @Override+ public String getIconClass() {+ return "fa-history";+ }++ @Override+ public String getLabel() {+ return "History";+ }++ @Override+ public AbstractLink newLink(String id) {+ return new Link<Void>(id) {++ @Override+ public void onClick() {+ DepotCommitsPage.State state = new DepotCommitsPage.State();+ String commitHash = context.getDepot().getObjectId(file.revision).name();+ state.setCompareWith(commitHash);+ if (file.path != null)+ state.setQuery(String.format("path(%s)", file.path));+ setResponsePage(DepotCommitsPage.class, DepotCommitsPage.paramsOf(context.getDepot(), state));+ }++ };+ }++ });+ if (file.isFile()) {+ generalItems.add(new MenuItem() {++ @Override+ public String getIconClass() {+ return "fa-file-text-o";+ }++ @Override+ public String getLabel() {+ return "Raw";+ }++ @Override+ public AbstractLink newLink(String id) {+ return new ResourceLink<Void>(id, new BlobResourceReference(),+ BlobResource.paramsOf(context.getDepot(), file)) {++ @Override+ protected CharSequence getOnClickScript(CharSequence url) {+ return closeBeforeClick(super.getOnClickScript(url));+ }++ };+ }++ });+ }++ String path = file.path;+ if (path != null && file.isTree())+ path += "/";++ List<MenuItem> changeItems = new ArrayList<>();+ if (file.isTree() && context.isOnBranch() && SecurityUtils.canModify(context.getDepot(), file.revision, path)) {+ changeItems.add(new MenuItem() {++ @Override+ public String getIconClass() {+ return "fa-plus";+ }++ @Override+ public String getLabel() {+ return "Create new file";+ }++ @Override+ public AbstractLink newLink(String id) {+ return new AjaxLink<Void>(id) {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ close();+ onNewFile(target);+ }++ };+ }++ });+ }++ if (file.isFile() && context.getDepot().getBlob(file).getText() != null+ && context.isOnBranch()+ && SecurityUtils.canModify(context.getDepot(), file.revision, path)) {+ changeItems.add(new MenuItem() {++ @Override+ public String getIconClass() {+ return "fa-pencil";+ }++ @Override+ public String getLabel() {+ return "Edit";+ }++ @Override+ public AbstractLink newLink(String id) {+ AbstractLink link = new ViewStateAwareAjaxLink<Void>(id) {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());+ }++ @Override+ public void onClick(AjaxRequestTarget target, String viewState) {+ close();+ RequestCycle.get().setMetaData(DepotFilePage.VIEW_STATE_KEY, viewState);+ context.onEdit(target);+ }+ };++ PageParameters params;+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = context.getBlobIdent();+ state.mode = Mode.EDIT;+ state.mark = context.getMark();+ params = DepotFilePage.paramsOf(context.getDepot(), state);+ CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);+ link.add(AttributeAppender.replace("href", url.toString()));+ link.add(new ViewStateAwareBehavior());+ return link;+ }++ });+ }++ if (file.isFile() && context.isOnBranch()+ && SecurityUtils.canModify(context.getDepot(), file.revision, path)) {+ changeItems.add(new MenuItem() {++ @Override+ public String getIconClass() {+ return "fa-trash";+ }++ @Override+ public String getLabel() {+ return "Delete";+ }++ @Override+ public AbstractLink newLink(String id) {+ AbstractLink link = new PreventDefaultAjaxLink<Void>(id) {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ close();+ context.onDelete(target);+ }++ };+ DepotFilePage.State state = new DepotFilePage.State();+ state.blobIdent = context.getBlobIdent();+ state.mode = Mode.EDIT;+ PageParameters params = DepotFilePage.paramsOf(context.getDepot(), state);+ CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);+ link.add(AttributeAppender.replace("href", url.toString()));+ return link;+ }++ });+ }++ List<MenuItem> customItems = context.getMenuItems(this);++ List<MenuItem> menuItems = new ArrayList<>(generalItems);+ if (!changeItems.isEmpty()) {+ if (!menuItems.isEmpty())+ menuItems.add(null); // add separator+ menuItems.addAll(changeItems);+ }+ if (!customItems.isEmpty()) {+ if (!menuItems.isEmpty())+ menuItems.add(null); // add separator+ menuItems.addAll(customItems);+ }+ return menuItems;+ }++ });+ } else {+ add(new WebMarkupContainer("fileMenu").setVisible(false));+ }++ setOutputMarkupId(true);+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(CssHeaderItem.forReference(new FileNavigatorResourceReference()));++ if (context.getBlobIdent().isTree()) {+ String script = String.format("$('#%s input[type=text]').focus();", getMarkupId());+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ String script = String.format("$('#%s form').submit(false);", getMarkupId());+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ private ObjectId getCommitId() {+ return context.getDepot().getObjectId(context.getBlobIdent().revision);+ }++ protected abstract void onNewFile(AjaxRequestTarget target);++ private List<BlobIdent> getChildren(BlobIdent blobIdent) {+ Repository repository = context.getDepot().getRepository();+ try (RevWalk revWalk = new RevWalk(repository)) {+ RevTree revTree = revWalk.parseCommit(getCommitId()).getTree();+ TreeWalk treeWalk = TreeWalk.forPath(repository, blobIdent.path, revTree);+ treeWalk.setRecursive(false);+ treeWalk.enterSubtree();++ List<BlobIdent> children = new ArrayList<>();+ while (treeWalk.next())+ children.add(new BlobIdent(context.getBlobIdent().revision, treeWalk.getPathString(), treeWalk.getRawMode(0)));+ Collections.sort(children);+ return children;+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotselector/DepotSelector.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotselector/DepotSelector.javaindex f76e8b28b7..8b6f046512 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotselector/DepotSelector.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotselector/DepotSelector.java@@ -5,7 +5,6 @@ import java.util.Collection;import java.util.List;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.CallbackParameter;import org.apache.wicket.ajax.markup.html.AjaxLink;@@ -27,6 +26,7 @@ import org.apache.wicket.request.IRequestParameters;import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.mapper.parameter.PageParameters;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.behavior.InputChangeBehavior;import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;import com.pmease.gitplex.core.GitPlex;@@ -89,7 +89,7 @@ public abstract class DepotSelector extends Panel {}});- searchField.add(new AbstractDefaultAjaxBehavior() {+ searchField.add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex 60eb985f94..0368768865 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java@@ -12,7 +12,6 @@ import java.util.Map;import javax.annotation.Nullable;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.behavior.AttributeAppender;@@ -51,6 +50,7 @@ import com.pmease.commons.lang.tokenizers.CmToken;import com.pmease.commons.util.Range;import com.pmease.commons.util.RangeUtils;import com.pmease.commons.util.StringUtils;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;@@ -92,7 +92,7 @@ public class TextDiffPanel extends Panel implements SourceAware {private Component symbolTooltip;- private AbstractDefaultAjaxBehavior callbackBehavior;+ private AbstractPostAjaxBehavior callbackBehavior;private transient List<MarkAwareDiffBlock> diffBlocks;@@ -223,7 +223,7 @@ public class TextDiffPanel extends Panel implements SourceAware {}).setEscapeModelStrings(false));- add(callbackBehavior = new AbstractDefaultAjaxBehavior() {+ add(callbackBehavior = new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/revisionpicker/RevisionSelector.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/revisionpicker/RevisionSelector.javaindex 19e0f442d5..5a134e2cd5 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/revisionpicker/RevisionSelector.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/revisionpicker/RevisionSelector.java@@ -11,7 +11,6 @@ import javax.annotation.Nullable;import org.apache.commons.lang3.StringUtils;import org.apache.wicket.AttributeModifier;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.markup.html.AjaxLink;@@ -44,6 +43,7 @@ import com.google.common.base.Throwables;import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.RefInfo;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.behavior.InputChangeBehavior;import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;import com.pmease.commons.wicket.component.modal.ModalPanel;@@ -188,7 +188,7 @@ public abstract class RevisionSelector extends Panel {feedback.setOutputMarkupPlaceholderTag(true);add(feedback);- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.javaindex 7cbeac8924..9b42d9fe4a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java@@ -6,7 +6,6 @@ import java.util.ArrayList;import java.util.List;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.behavior.AttributeAppender;@@ -29,6 +28,7 @@ import org.apache.wicket.request.resource.PackageResourceReference;import org.apache.wicket.request.resource.ResourceReference;import org.eclipse.jgit.lib.ObjectId;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.behavior.RunTaskBehavior;import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;import com.pmease.gitplex.core.GitPlex;@@ -176,7 +176,7 @@ public abstract class SymbolTooltipPanel extends Panel {});- add(new AbstractDefaultAjaxBehavior() {+ add(new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.javaindex dedbd01c50..878e6c449e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java@@ -17,7 +17,6 @@ import org.apache.shiro.util.ThreadContext;import org.apache.wicket.Component;import org.apache.wicket.MetaDataKey;import org.apache.wicket.RestartResponseException;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;@@ -45,10 +44,11 @@ import org.eclipse.jgit.treewalk.TreeWalk;import com.google.common.base.Objects;import com.pmease.commons.git.BlobIdent;import com.pmease.commons.git.GitUtils;-import com.pmease.commons.git.exception.ObjectNotExistException;+import com.pmease.commons.git.exception.GitObjectNotFoundException;import com.pmease.commons.hibernate.UnitOfWork;import com.pmease.commons.lang.extractors.TokenPosition;import com.pmease.commons.loader.ListenerRegistry;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.component.menu.MenuItem;import com.pmease.commons.wicket.component.menu.MenuLink;import com.pmease.commons.wicket.component.modal.ModalLink;@@ -169,7 +169,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {RevTree revTree = commit.getTree();TreeWalk treeWalk = TreeWalk.forPath(getDepot().getRepository(), blobIdent.path, revTree);if (treeWalk == null) {- throw new ObjectNotExistException("Unable to find blob path '" + blobIdent.path+ throw new GitObjectNotFoundException("Unable to find blob path '" + blobIdent.path+ "' in revision '" + blobIdent.revision + "'");}blobIdent.mode = treeWalk.getRawMode(0);@@ -420,7 +420,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {@Overridepublic Component getLoadingComponent(String markupId) {- IRequestHandler handler = new ResourceReferenceRequestHandler(AbstractDefaultAjaxBehavior.INDICATOR);+ IRequestHandler handler = new ResourceReferenceRequestHandler(AbstractPostAjaxBehavior.INDICATOR);String html = "<img src='" + RequestCycle.get().urlFor(handler) + "' class='loading'/> Loading latest commit...";return new Label(markupId, html).setEscapeModelStrings(false);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.javaindex d509beab71..04d77a1079 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java@@ -17,6 +17,8 @@ import java.util.ArrayList;import java.util.Collection;import java.util.List;+import javax.persistence.EntityNotFoundException;+import org.apache.commons.lang3.StringUtils;import org.apache.commons.lang3.text.WordUtils;import org.apache.wicket.AttributeModifier;@@ -110,7 +112,11 @@ public abstract class RequestDetailPage extends PullRequestPage {@Overrideprotected PullRequest load() {- return Preconditions.checkNotNull(GitPlex.getInstance(PullRequestManager.class).find(getDepot(), params.get("request").toLong()));+ Long requestNumber = params.get("request").toLong();+ PullRequest request = GitPlex.getInstance(PullRequestManager.class).find(getDepot(), requestNumber);+ if (request == null)+ throw new EntityNotFoundException("Unable to find request #" + requestNumber + " in repository " + getDepot());+ return request;}};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.javaindex c464a2c317..6f35b23fa2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java@@ -10,7 +10,6 @@ import java.util.List;import javax.annotation.Nullable;import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.behavior.AttributeAppender;@@ -36,6 +35,7 @@ import org.eclipse.jgit.revwalk.RevCommit;import com.google.common.base.Preconditions;import com.pmease.commons.git.GitUtils;import com.pmease.commons.lang.diff.WhitespaceOption;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;import com.pmease.commons.wicket.component.DropdownLink;import com.pmease.commons.wicket.websocket.WebSocketManager;import com.pmease.commons.wicket.websocket.WebSocketRegion;@@ -223,11 +223,11 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp@Overrideprotected Component newContent(String id) {- AbstractDefaultAjaxBehavior callbackBehavior = new AbstractDefaultAjaxBehavior() {+ AbstractPostAjaxBehavior callbackBehavior = new AbstractPostAjaxBehavior() {@Overrideprotected void respond(AjaxRequestTarget target) {- IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();+ IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();state.oldCommit = params.getParameterValue("oldCommit").toString();state.newCommit = params.getParameterValue("newCommit").toString();target.add(head);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/BaseErrorPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/BaseErrorPage.javaindex 5971ad3df0..f4c86ea558 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/BaseErrorPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/BaseErrorPage.java@@ -3,21 +3,15 @@ package com.pmease.gitplex.web.page.error;import java.io.Serializable;import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.request.http.WebResponse;+import org.apache.wicket.markup.head.CssHeaderItem;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import com.pmease.gitplex.web.page.base.BasePage;@SuppressWarnings("serial")public abstract class BaseErrorPage extends BasePage {- protected abstract int getErrorCode();-- @Override- protected void configureResponse(final WebResponse response) {- super.configureResponse(response);- response.setStatus(getErrorCode());- }-@Overridepublic boolean isErrorPage() {return true;@@ -28,5 +22,12 @@ public abstract class BaseErrorPage extends BasePage {super.onPopState(target, data);target.appendJavaScript("location.reload();");}++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(CssHeaderItem.forReference(new ErrorPageResourceReference()));+ response.render(OnDomReadyHeaderItem.forScript("$('html,body').addClass('error');"));+ }}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ErrorPageResourceReference.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ErrorPageResourceReference.javanew file mode 100644index 0000000000..cb170bf0a7--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ErrorPageResourceReference.java@@ -0,0 +1,13 @@+package com.pmease.gitplex.web.page.error;++import com.pmease.gitplex.web.page.base.BaseDependentCssResourceReference;++public class ErrorPageResourceReference extends BaseDependentCssResourceReference {++ private static final long serialVersionUID = 1L;++ public ErrorPageResourceReference() {+ super(ErrorPageResourceReference.class, "error-page.css");+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ExpectedExceptionPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ExpectedExceptionPage.htmlnew file mode 100644index 0000000000..c6839b1ea3--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ExpectedExceptionPage.html@@ -0,0 +1,17 @@+<wicket:extend>+ <div wicket:id="error" class="center-box">+ <div wicket:id="title" class="title"></div>+ <div wicket:id="description" class="description"></div>+ <div class="actions">+ <a wicket:id="dashboard" class="btn btn-primary">Back to dashboard</a>+ <a wicket:id="showDetail" class="btn btn-primary">Show Error Detail</a>+ </div>+ <div wicket:id="detail"></div>+ </div>+ <wicket:fragment wicket:id="detailFrag">+ <div class="detail">+ <div class="head">Error Detail</div>+ <div wicket:id="body" class="body"></div>+ </div>+ </wicket:fragment>+</wicket:extend>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ExpectedExceptionPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ExpectedExceptionPage.javanew file mode 100644index 0000000000..a4261e832b--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/ExpectedExceptionPage.java@@ -0,0 +1,59 @@+package com.pmease.gitplex.web.page.error;++import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.link.BookmarkablePageLink;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.util.string.Strings;++import com.pmease.commons.util.WordUtils;+import com.pmease.commons.wicket.component.MultilineLabel;+import com.pmease.gitplex.web.page.home.DashboardPage;++@SuppressWarnings("serial")+public class ExpectedExceptionPage extends BaseErrorPage {++ private final Exception exception;++ public ExpectedExceptionPage(Exception exception) {+ this.exception = exception;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ String title = exception.getClass().getSimpleName();+ String suffixToRemove = "Exception";+ if (title.endsWith(suffixToRemove))+ title = title.substring(0, title.length()-suffixToRemove.length());++ title = WordUtils.capitalizeFully(WordUtils.uncamel(title));++ WebMarkupContainer container = new WebMarkupContainer("error");+ container.setOutputMarkupId(true);+ add(container);++ container.add(new Label("title", title));+ container.add(new Label("description", exception.getMessage()));++ container.add(new BookmarkablePageLink<Void>("dashboard", DashboardPage.class));++ container.add(new AjaxLink<Void>("showDetail") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = new Fragment("detail", "detailFrag", ExpectedExceptionPage.this);+ fragment.add(new MultilineLabel("body", Strings.toString(exception)));+ container.replace(fragment);+ target.add(container);+ setVisible(false);+ }++ });+ container.add(new WebMarkupContainer("detail"));+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/NotFoundErrorPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/NotFoundErrorPage.htmldeleted file mode 100644index 3dddc5c26d..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/NotFoundErrorPage.html+++ /dev/null@@ -1,3 +0,0 @@-<wicket:extend>- <div wicket:id="errorMessage"></div>-</wicket:extend>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/NotFoundErrorPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/NotFoundErrorPage.javadeleted file mode 100644index cf1dea523a..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/NotFoundErrorPage.java+++ /dev/null@@ -1,28 +0,0 @@-package com.pmease.gitplex.web.page.error;--import javax.servlet.http.HttpServletResponse;--import org.apache.wicket.markup.html.basic.Label;--@SuppressWarnings("serial")-public class NotFoundErrorPage extends BaseErrorPage {-- private final String errorMessage;-- public NotFoundErrorPage(String errorMessage) {- this.errorMessage = errorMessage;- }-- @Override- protected void onInitialize() {- super.onInitialize();-- add(new Label("errorMessage", errorMessage));- }-- @Override- protected int getErrorCode() {- return HttpServletResponse.SC_NOT_FOUND;- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/UnexpectedExceptionPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/UnexpectedExceptionPage.htmlnew file mode 100644index 0000000000..fc98306a25--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/UnexpectedExceptionPage.html@@ -0,0 +1,103 @@+<wicket:extend>+ <script type="text/javascript">+ function validateBugReport() {+ var noError = true;+ var value = document.getElementById("subject").value.toString();+ if (value == null || value.trim().length == 0) {+ $("#subject_error").show();+ noError = false;+ } else {+ $("#subject_error").hide();+ }+ value = document.getElementById("description").value.toString();+ if (value == null || value.trim().length == 0) {+ $("#description_error").show();+ noError = false;+ } else {+ $("#description_error").hide();+ }+ value = document.getElementById("contact_name").value.toString();+ if (value == null || value.trim().length == 0) {+ $("#contact_name_error").show();+ noError = false;+ } else {+ $("#contact_name_error").hide();+ }+ value = document.getElementById("contact_email").value.toString();+ if (value == null || value.trim().length == 0) {+ $("#contact_email_error").show();+ noError = false;+ } else {+ $("#contact_email_error").hide();+ }++ return noError;+ };+ </script>+ <div class="center-box">+ <div class="title">Whoops! An Unexpected Exception Occurred</div>++ <div class="description">Sorry, we've encountered an unexpected+ exception. If you believe it is a bug of GitPlex, please send this+ error using below form to help us improving quality of the product</div>++ <form action="http://www.pmease.com/gitplex_bug_report" method="post">+ <div class="actions">+ <input type="submit" value="Send Error Report" class="btn btn-primary" onclick="if (validateBugReport()) this.form.submit();return false;"></input>+ <input wicket:id="dashboardTop" type="button" value="Back to Dashboard" class="btn btn-primary"></input>+ </div>+ <table class="table properties">+ <tbody>+ <tr>+ <td class="name">Subject <span class="required">*</span></td>+ <td class="value">+ <input type="text" id="subject" name="subject" value="Unexpected exception" class="form-control"></input>+ <div id="subject_error" class="error"><i class="fa fa-warning"></i> Subject can not be empty</div>+ <div class="help-block">Specify title of the bug report</div>+ </td>+ </tr>+ <tr>+ <td class="name">Description <span class="required">*</span></td>+ <td class="value">+ <textarea wicket:id="description" id="description" name="description" class="form-control no-autosize"></textarea>+ <div id="description_error" class="error"><i class="fa fa-warning"></i> Description can not be empty</div>+ <div class="help-block">Please describe details for the+ error below. It is filled with error message of the exception by+ default. You may add more details here, for example, to describe+ steps to reproduce the error</div>+ </td>+ </tr>+ <tr>+ <td class="name">Contact Email <span class="required">*</span></td>+ <td class="value">+ <input wicket:id="contactEmail" id="contact_email" type="text" name="contact_email" class="form-control">+ <div id="contact_email_error" class="error"><i class="fa fa-warning"></i> Contact email can not be empty</div>+ <div class="help-block">Please provide an email so that we can contact with to get details of the+ error if necessary</div>+ </td>+ </tr>+ <tr>+ <td class="name">Contact Name <span class="required">*</span></td>+ <td class="value">+ <input wicket:id="contactName" id="contact_name" type="text" name="contact_name" class="form-control">+ <div id="contact_name_error" class="error"><i class="fa fa-warning"></i> Contact name can not be empty</div>+ <div class="help-block">Please provide name of the contact above</div></td>+ </tr>+ <tr>+ <td colspan="2" class="caption">Below information will also be sent to help us analyzing the problem</td>+ </tr>+ <tr wicket:id="props">+ <td wicket:id="name"></td>+ <td wicket:id="value"></td>+ </tr>+ </tbody>+ </table>+ <div class="actions">+ <input type="submit" value="Send Error Report" onclick="if (validateBugReport()) this.form.submit();return false;" class="btn btn-primary"></input>+ <input wicket:id="dashboardBottom" type="button" value="Back to Dashboard" class="btn btn-primary"></input>+ </div>+ <input wicket:id="gitplexUrl" type="hidden" name="dashboard_url"></input>+ <input wicket:id="additionalInfo" type="hidden" name="additional_info"></input>+ </form>+ </div>+</wicket:extend>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/UnexpectedExceptionPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/UnexpectedExceptionPage.javanew file mode 100644index 0000000000..855ddc75b1--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/UnexpectedExceptionPage.java@@ -0,0 +1,169 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package com.pmease.gitplex.web.page.error;++import java.io.Serializable;+import java.net.InetAddress;+import java.net.UnknownHostException;+import java.util.ArrayList;+import java.util.Date;+import java.util.List;++import org.apache.wicket.markup.ComponentTag;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.form.TextArea;+import org.apache.wicket.markup.html.link.BookmarkablePageLink;+import org.apache.wicket.markup.html.list.ListItem;+import org.apache.wicket.markup.html.list.ListView;+import org.apache.wicket.model.Model;+import org.apache.wicket.util.string.Strings;++import com.pmease.commons.util.FileUtils;+import com.pmease.commons.util.StringUtils;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.Account;+import com.pmease.gitplex.core.manager.ConfigManager;+import com.pmease.gitplex.web.page.home.DashboardPage;+import com.pmease.gitplex.web.util.DateUtils;++@SuppressWarnings("serial")+public class UnexpectedExceptionPage extends BaseErrorPage {++ private static final long serialVersionUID = 1L;++ private Exception exception;++ public UnexpectedExceptionPage(Exception exception) {+ this.exception = exception;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ String description = "Error Details: \n\n" + StringUtils.replace(Strings.toString(exception).trim(), " ", "\t");+ add(new TextArea<String>("description", Model.of(description)));+ add(new WebMarkupContainer("contactName") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ Account user = getLoginUser();+ if (user != null)+ tag.put("value", user.getDisplayName());+ }++ });+ add(new WebMarkupContainer("contactEmail") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ Account user = getLoginUser();+ if (user != null)+ tag.put("value", user.getEmail());+ }++ });++ List<Property> serverProps = new ArrayList<>();+ try {+ serverProps.add(new Property("Host Name", InetAddress.getLocalHost().getHostName()));+ } catch (UnknownHostException e) {+ throw new RuntimeException(e);+ }+ serverProps.add(new Property("System Date and Time", DateUtils.formatDateTime(new Date())));+ serverProps.add(new Property("Operating System",+ System.getProperty("os.name") + " "+ + System.getProperty("os.version") + ", "+ + System.getProperty("os.arch")));+ serverProps.add(new Property("OS User",+ System.getProperty("user.name")));+ serverProps.add(new Property("JVM",+ System.getProperty("java.vm.name") + " "+ + System.getProperty("java.version") + ", "+ + System.getProperty("java.vm.vendor")));+ serverProps.add(new Property("GitPlex Version", "EAP"));+ Account user = getLoginUser();+ if (user != null)+ serverProps.add(new Property("GitPlex User", user.getName()));+ else+ serverProps.add(new Property("GitPlex User", "<anonymous>"));+ serverProps.add(new Property("Total Memory",+ FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory())));+ serverProps.add(new Property("Used Memory",+ FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory() -+ Runtime.getRuntime().freeMemory())));+ add(new ListView<Property>("props", serverProps) {++ @Override+ protected void populateItem(ListItem<Property> item) {+ Property property = item.getModelObject();+ item.add(new Label("name", property.getName()));+ item.add(new Label("value", property.getValue()));+ }++ });+ add(new BookmarkablePageLink<Void>("dashboardTop", DashboardPage.class));+ add(new BookmarkablePageLink<Void>("dashboardBottom", DashboardPage.class));++ add(new WebMarkupContainer("gitplexUrl") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ tag.put("value", GitPlex.getInstance(ConfigManager.class).getSystemSetting().getServerUrl());+ }++ });+ add(new WebMarkupContainer("additionalInfo") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ String serverInfo = "";+ for (Property property: serverProps)+ serverInfo += property.getName() + ": " + property.getValue() + "\n";+ tag.put("value", serverInfo);+ }++ });+ }++ private static class Property implements Serializable {++ private final String name;++ private final String value;++ public Property(String name, String value) {+ this.name = name;+ this.value = value;+ }++ public String getName() {+ return name;+ }++ public String getValue() {+ return value;+ }++ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/error-page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/error-page.cssnew file mode 100644index 0000000000..113b323d40--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/error/error-page.css@@ -0,0 +1,50 @@+html.error, body.error {+ background: #FCC;+}+body.error .center-box {+ width: 75%;+ padding: 20px;+ margin-top: 50px;+ margin-bottom: 50px;+}++body.error .center-box>div {+ margin-bottom: 20px;+}++body.error .center-box>.title {+ font-size: 24px;+ font-weight: bold;+}++body.error .center-box .detail>.head {+ font-size: 20px;+ margin-bottom: 20px;+}+body.error .center-box .detail>.body {+ white-space: pre-wrap;+ word-wrap: break-word;+ font-family: monospace;+}++body.error .center-box textarea {+ height: 800px;+}++body.error form .actions {+ margin-bottom: 20px;+}+body.error td.name {+ font-weight: bold;+ color: #444;+}+body.error form .error {+ margin-top: 8px;+ color: #A00;+ display: none;+}++body.error .caption {+ font-size: 16px;+ font-weight: bold;+}\ No newline at end of file