From: jinwooim.bae Date: Wed, 7 May 2014 11:53:47 +0000 (+0900) Subject: ANIMATOR : Check duplication animationgroup name X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=811ade94927aebab1c1a6fd8695d4ced3d051e92;p=sdk%2Fide%2Fweb-ui-builder-eplugin.git ANIMATOR : Check duplication animationgroup name This will check for duplicate animationgroup names. Change-Id: I93ebacae639d4d8872b421fd23e79155a0516e09 Signed-off-by: jinwooim.bae --- diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/part/AnimatorPagePart.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/part/AnimatorPagePart.java index bdc09ca..166562e 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/part/AnimatorPagePart.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/part/AnimatorPagePart.java @@ -77,6 +77,19 @@ public class AnimatorPagePart extends AnimatorPart { return animation; } + + public AnimatorAnimation getAnimationByName(String animationName) { + AnimatorAnimation animation = null; + for (AnimatorAnimation currentAnimation : getAnimations()) { + String currentAnimationName = currentAnimation.getName(); + if (currentAnimationName.equals(animationName)) { + animation = currentAnimation; + break; + } + } + + return animation; + } public AnimatorAnimation createAnimatorAnimation(AnimatorModelFactory modelFactory) { AnimatorAnimation animationGroup = (AnimatorAnimation)modelFactory.createAnimatorModel(AnimatorModelType.ANIMATION); diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupCreateDialog.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupCreateDialog.java index 8964c1c..ab24287 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupCreateDialog.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupCreateDialog.java @@ -43,6 +43,8 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Text; +import org.tizen.webuibuilder.animator.model.AnimatorAnimation; +import org.tizen.webuibuilder.animator.model.part.AnimatorPagePart; /** @@ -59,6 +61,7 @@ public class AnimationGroupCreateDialog extends Dialog { private boolean isRepeated = false; private boolean isAutoPlay = false; + private TimelineOutlineHeader outlineHeader = null; /** * Construct * @@ -67,9 +70,10 @@ public class AnimationGroupCreateDialog extends Dialog { * @param style * SWT Composite style */ - public AnimationGroupCreateDialog(Shell parent, int style) { + public AnimationGroupCreateDialog(Shell parent, TimelineOutlineHeader outlineHeader, int style) { super(parent, style); setText("Create animation group"); + this.outlineHeader = outlineHeader; } /** @@ -126,12 +130,12 @@ public class AnimationGroupCreateDialog extends Dialog { animationGroupName.setTextLimit(31); animationGroupName.setMessage("Under 32 characters."); animationGroupName - .setToolTipText("Under 32 Characters, and check pattern, [^A-Za-z0-9\\.\\@_\\-~#\\s]+"); + .setToolTipText("Under 32 Characters, and check pattern, [^A-Za-z0-9//_//-]+"); animationGroupName.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { String animationGroupName = e.text; - Pattern pattern = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#\\s]+"); + Pattern pattern = Pattern.compile("[^A-Za-z0-9//_//-]+"); Matcher matcher = pattern.matcher(animationGroupName); boolean find = matcher.find(); if (find) { @@ -222,12 +226,27 @@ public class AnimationGroupCreateDialog extends Dialog { public void mouseUp(MouseEvent e) { String newAnimationGroupName = animationGroupName.getText(); - result = - new AnimationGroupDialogResult(animationIterationSpinner.getSelection(), - isRepeated, isAutoPlay, - newAnimationGroupName); - - shell.dispose(); + if (newAnimationGroupName == null || newAnimationGroupName.length() == 0) { + AnimatorGroupToolTip toolTip = + new AnimatorGroupToolTip(shell, animationGroupName); + toolTip.showErrorToolTip("Insert Name"); + } else { + AnimatorPagePart pagePart = + outlineHeader.getTimelineMainContainer().getPage().getPagePart(); + AnimatorAnimation animation = + pagePart.getAnimationByName(newAnimationGroupName); + if (animation != null) { + AnimatorGroupToolTip toolTip = + new AnimatorGroupToolTip(shell, animationGroupName); + toolTip.showErrorToolTip("Duplicate Name"); + } else { + result = + new AnimationGroupDialogResult(animationIterationSpinner + .getSelection(), isRepeated, isAutoPlay, + newAnimationGroupName); + shell.dispose(); + } + } } @Override diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupEditDialog.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupEditDialog.java index da75fa9..5647701 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupEditDialog.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimationGroupEditDialog.java @@ -43,7 +43,9 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolTip; import org.tizen.webuibuilder.animator.model.AnimatorAnimation; +import org.tizen.webuibuilder.animator.model.part.AnimatorPagePart; /** @@ -63,6 +65,7 @@ public class AnimationGroupEditDialog extends Dialog { private AnimatorAnimation animation = null; private boolean isDirty = false; + private TimelineOutlineHeader outlineHeader = null; /** * Construct * @@ -73,10 +76,12 @@ public class AnimationGroupEditDialog extends Dialog { * @param animation * {@link AnimatorAnimation} */ - public AnimationGroupEditDialog(Shell parent, int style, AnimatorAnimation animation) { + public AnimationGroupEditDialog(Shell parent, TimelineOutlineHeader outlineHeader, int style, + AnimatorAnimation animation) { super(parent, style); this.animation = animation; + this.outlineHeader = outlineHeader; setText("Show and edit animation group"); } @@ -145,13 +150,13 @@ public class AnimationGroupEditDialog extends Dialog { animationGroupName.setTextLimit(32); animationGroupName.setMessage("Under 32 characters."); animationGroupName - .setToolTipText("Under 32 Characters, and check pattern, [^A-Za-z0-9\\.\\@_\\-~#\\s]+"); + .setToolTipText("Under 32 Characters, and check pattern, [^A-Za-z0-9\\_\\-]+"); animationGroupName.setText(animation.getName()); animationGroupName.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { String animationGroupName = e.text; - Pattern pattern = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#\\s]+"); + Pattern pattern = Pattern.compile("[^A-Za-z0-9\\_\\-]+"); Matcher matcher = pattern.matcher(animationGroupName); boolean find = matcher.find(); if (find) { @@ -247,33 +252,52 @@ public class AnimationGroupEditDialog extends Dialog { createAnimationButton.addMouseListener(new MouseListener() { @Override public void mouseUp(MouseEvent e) { - if (!animation.getName().equals(animationGroupName.getText())) { - isDirty = true; - } - - if (animation.getIteration() != animationIterationSpinner.getSelection()) { - isDirty = true; - } - if (animation.isRepeated() != isRepeated) { - isDirty = true; - } + String newAnimationGroupName = animationGroupName.getText(); - if (animation.isJustPlay() != isAutoPlay) { - isDirty = true; - } - - if (isDirty) { - result = - new AnimationGroupDialogResult( - animationIterationSpinner.getSelection(), - isRepeated, isAutoPlay, - animationGroupName.getText()); + if (newAnimationGroupName == null || newAnimationGroupName.length() == 0) { + AnimatorGroupToolTip toolTip = + new AnimatorGroupToolTip(shell, animationGroupName); + toolTip.showErrorToolTip("Insert Name"); } else { - result = null; + AnimatorPagePart pagePart = + outlineHeader.getTimelineMainContainer().getPage().getPagePart(); + AnimatorAnimation findAnimation = + pagePart.getAnimationByName(newAnimationGroupName); + if (findAnimation != null) { + AnimatorGroupToolTip toolTip = + new AnimatorGroupToolTip(shell, animationGroupName); + toolTip.showErrorToolTip("Duplicate Name"); + } else { + + if (!animation.getName().equals(animationGroupName.getText())) { + isDirty = true; + } + + if (animation.getIteration() != animationIterationSpinner.getSelection()) { + isDirty = true; + } + + if (animation.isRepeated() != isRepeated) { + isDirty = true; + } + + if (animation.isJustPlay() != isAutoPlay) { + isDirty = true; + } + + if (isDirty) { + result = + new AnimationGroupDialogResult(animationIterationSpinner + .getSelection(), isRepeated, isAutoPlay, + animationGroupName.getText()); + } else { + result = null; + } + shell.dispose(); + } } - shell.dispose(); } @Override diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimatorGroupToolTip.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimatorGroupToolTip.java new file mode 100644 index 0000000..a2bd7d9 --- /dev/null +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/AnimatorGroupToolTip.java @@ -0,0 +1,85 @@ + + +package org.tizen.webuibuilder.animator.ui.views.timeline.header; + +import java.util.Timer; +import java.util.TimerTask; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolTip; + + +public class AnimatorGroupToolTip { + + private ToolTip tooltip = null; + private Shell shell = null; + private Control control = null; + + public AnimatorGroupToolTip(Shell shell, Control control) { + this.shell = shell; + this.control = control; + } + + /** + * Show Error ToolTip + * + * @param text + */ + public void showErrorToolTip(String text) { + hideErrorTooltip(); + tooltip = new ToolTip(shell, SWT.ICON_WARNING | SWT.BALLOON); + tooltip.setText(text); + + Point location = control.toDisplay(control.getSize().x, control.getSize().y); + + tooltip.setLocation(location.x - control.getSize().x + control.getBorderWidth(), location.y + - control.getBorderWidth()); + tooltip.setVisible(true); + + control.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + if (tooltip != null) { + Timer timer = new Timer(); + TimerTask timerTask = new TimerTask() { + @Override + public void run() { + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + hideErrorTooltip(); + } + }); + } + }; + + timer.schedule(timerTask, 300); + } + } + + @Override + public void focusGained(FocusEvent e) { + // Do nothing + } + }); + } + + /** + * Hides error message on the control + */ + public void hideErrorTooltip() { + if (tooltip != null && !tooltip.isDisposed()) { + tooltip.setVisible(false); + tooltip.dispose(); + tooltip = null; + } + } +} diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/TimelineOutlineHeader.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/TimelineOutlineHeader.java index 49c124f..5308151 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/TimelineOutlineHeader.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/header/TimelineOutlineHeader.java @@ -197,7 +197,7 @@ public class TimelineOutlineHeader extends Composite { for (int i = 0; i < animations.size(); i++) { final MenuItem aniGroupItem = new MenuItem(animationGroupMenu, SWT.CHECK); final AnimatorAnimation animatorAnimation = animations.get(i); - aniGroupItem.setText(animatorAnimation.getName() + getId(animatorAnimation)); + aniGroupItem.setText(animatorAnimation.getName()); aniGroupItem.setData("id", animatorAnimation.getId()); if (selectedAnimationGroupId != null @@ -309,7 +309,7 @@ public class TimelineOutlineHeader extends Composite { if (size != 0) { selectedAnimationGroupId = animations.get(0).getId(); - animationGroupLabel.setText(animations.get(0).getName() + getId(animations.get(0))); + animationGroupLabel.setText(animations.get(0).getName()); animationGroupLabel.setData("id", animations.get(0).getId()); } else { animationGroupLabel.setText("NONE"); @@ -325,17 +325,6 @@ public class TimelineOutlineHeader extends Composite { } /** - * Get AnimationGroupId - * - * @param animationGroup {@link AnimatorAnimation} - * @return - */ - private String getId(AnimatorAnimation animationGroup) { - String id = " ( ID : " + animationGroup.getId() + " )"; - return id; - } - - /** * Clear Tree in Timeline */ public void clearTree() { @@ -354,8 +343,9 @@ public class TimelineOutlineHeader extends Composite { * Add Animation Group */ public void addAnimationGroup() { + AnimationGroupCreateDialog createDialog = - new AnimationGroupCreateDialog(getShell(), SWT.NONE); + new AnimationGroupCreateDialog(getShell(), this, SWT.NONE); AnimationGroupDialogResult result = (AnimationGroupDialogResult) createDialog.open(); if (result != null) { @@ -485,8 +475,9 @@ public class TimelineOutlineHeader extends Composite { return; } + AnimationGroupEditDialog editDialog = - new AnimationGroupEditDialog(getShell(), SWT.NONE, editAnimation); + new AnimationGroupEditDialog(getShell(), this, SWT.NONE, editAnimation); AnimationGroupDialogResult result = (AnimationGroupDialogResult) editDialog.open(); if (result != null) { AnimatorPagePart pagePart = getTimelineMainContainer().getPage().getPagePart(); @@ -606,7 +597,7 @@ public class TimelineOutlineHeader extends Composite { } } - private TimelineMainContainer getTimelineMainContainer() { + public TimelineMainContainer getTimelineMainContainer() { return (TimelineMainContainer) getParent().getParent().getParent().getParent(); } @@ -637,7 +628,7 @@ public class TimelineOutlineHeader extends Composite { String animationId = animation.getId(); setSelectedAnimationGroupId(animationId); - animationGroupLabel.setText(animationName + getId(animation)); + animationGroupLabel.setText(animationName); getAnimationGroupLabel().setData("id", animationId); animationGroupLabel.setToolTipText(animationName); animationGroupLabel.pack(); @@ -658,7 +649,7 @@ public class TimelineOutlineHeader extends Composite { String animationName = animation.getName(); String animationId = animation.getId(); - animationGroupLabel.setText(animationName + getId(animation)); + animationGroupLabel.setText(animationName); getAnimationGroupLabel().setData("id", animationId); animationGroupLabel.setToolTipText(animationName); animationGroupLabel.pack();