Author: scabanovich
Date: 2009-01-15 10:58:48 -0500 (Thu, 15 Jan 2009)
New Revision: 13065
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/event/ActionDeclinedException.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/DefaultWizardDataValidator.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/DefaultCreateHandler.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/PasteHandler.java
Log:
JBIDE-3566
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/DefaultWizardDataValidator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/DefaultWizardDataValidator.java 2009-01-15
15:42:50 UTC (rev 13064)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/DefaultWizardDataValidator.java 2009-01-15
15:58:48 UTC (rev 13065)
@@ -11,12 +11,12 @@
package org.jboss.tools.common.meta.action.impl;
import java.util.*;
+
+import org.jboss.tools.common.meta.XChild;
import org.jboss.tools.common.meta.action.*;
import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
-import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.impl.CreateFileHandler;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
public class DefaultWizardDataValidator implements WizardDataValidator {
@@ -44,6 +44,16 @@
String entity = support.action.getProperty("entity");
if(entity == null) entity = ds[step].getModelEntity().getName();
if(!checkChild(support.getTarget(), entity, data)) return;
+
+ XModelObject parent = support.getTarget();
+ int childCount = parent.getChildren(entity).length;
+ XChild c = support.getTarget().getModelEntity().getChild(entity);
+ int max = c == null ? 0 : c.getMaxCount();
+ if(c != null && max <= childCount) {
+ message = DefaultCreateHandler.title(parent, true) + " can contain only "
+ max +
+ ((max == 1) ? " child " : " children ") +
+ "with entity " + entity + ".";
+ }
} else
if("true".equals(support.action.getProperty("validator.edit"))) {
String entity = support.action.getProperty("entity");
if(entity == null) entity = ds[step].getModelEntity().getName();
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/DefaultCreateHandler.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/DefaultCreateHandler.java 2009-01-15
15:42:50 UTC (rev 13064)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/DefaultCreateHandler.java 2009-01-15
15:58:48 UTC (rev 13065)
@@ -23,6 +23,7 @@
import org.jboss.tools.common.model.ServiceDialog;
import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.event.ActionDeclinedException;
import org.jboss.tools.common.model.impl.RegularObjectImpl;
import org.jboss.tools.common.model.undo.XCreateUndo;
import org.jboss.tools.common.model.undo.XUndoManager;
@@ -184,7 +185,7 @@
mes = title(parent, true) + " can contain only " + max +
((max == 1) ? " child " : " children ") +
"with entity " + ce + ".";
- throw new XModelException(mes);
+ throw new ActionDeclinedException(mes);
}
boolean b = parent.addChild(child);
if(!b &&
child.getModelEntity().getAttribute(XModelObjectLoaderUtil.ATTR_ID_NAME) != null) {
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/PasteHandler.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/PasteHandler.java 2009-01-15
15:42:50 UTC (rev 13064)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/PasteHandler.java 2009-01-15
15:58:48 UTC (rev 13065)
@@ -28,6 +28,7 @@
import org.jboss.tools.common.model.XModelBuffer;
import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.event.ActionDeclinedException;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
public class PasteHandler extends AbstractHandler {
@@ -109,7 +110,7 @@
boolean mustGenerate = (found != null && mustGenerate(entity));
if(!mustGenerate) {
int i = (found == null) ? 0 : PasteEnterNewNameSupport.run(parent, source, copy,
data[0]);
- if(i != 0) throw new XModelException("Paste declined.");
+ if(i != 0) throw new ActionDeclinedException("Paste declined.");
}
for (int j = 0; j < ad.length; j++)
copy.setAttributeValue(ad[j].getAttribute().getName(), ad[j].getValue());
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/event/ActionDeclinedException.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/event/ActionDeclinedException.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/event/ActionDeclinedException.java 2009-01-15
15:58:48 UTC (rev 13065)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.event;
+
+import org.jboss.tools.common.model.XModelException;
+
+public class ActionDeclinedException extends XModelException {
+ private static final long serialVersionUID = 1L;
+
+ public ActionDeclinedException(String message) {
+ super(message);
+ }
+
+}