/*******************************************************************************
* Copyright 2011 Google Inc. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are 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
*
* 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.google.gdt.eclipse.designer.gwtext.gef.policy;
import com.google.gdt.eclipse.designer.gwtext.model.layout.LayoutInfo;
import com.google.gdt.eclipse.designer.gwtext.model.widgets.ContainerInfo;
import org.eclipse.wb.core.gef.command.EditCommand;
import org.eclipse.wb.core.gef.policy.PolicyUtils;
import org.eclipse.wb.core.gef.policy.validator.LayoutRequestValidators;
import org.eclipse.wb.gef.core.Command;
import org.eclipse.wb.gef.core.policies.ILayoutRequestValidator;
import org.eclipse.wb.gef.core.requests.CreateRequest;
import org.eclipse.wb.gef.core.requests.Request;
import org.eclipse.wb.gef.graphical.policies.LayoutEditPolicy;
/**
* {@link LayoutEditPolicy} for dropping {@link LayoutInfo} on {@link ContainerInfo}.
*
* @author scheglov_ke
* @coverage GWTExt.gef.policy
*/
public final class DropLayoutEditPolicy extends LayoutEditPolicy {
private static final ILayoutRequestValidator VALIDATOR =
LayoutRequestValidators.modelType(LayoutInfo.class);
private final ContainerInfo m_container;
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public DropLayoutEditPolicy(ContainerInfo container) {
m_container = container;
}
////////////////////////////////////////////////////////////////////////////
//
// Requests
//
////////////////////////////////////////////////////////////////////////////
@Override
protected ILayoutRequestValidator getRequestValidator() {
return VALIDATOR;
}
////////////////////////////////////////////////////////////////////////////
//
// Feedback
//
////////////////////////////////////////////////////////////////////////////
@Override
protected void showLayoutTargetFeedback(Request request) {
PolicyUtils.showBorderTargetFeedback(this);
}
@Override
protected void eraseLayoutTargetFeedback(Request request) {
PolicyUtils.eraseBorderTargetFeedback(this);
}
////////////////////////////////////////////////////////////////////////////
//
// Command
//
////////////////////////////////////////////////////////////////////////////
@Override
protected Command getCreateCommand(CreateRequest request) {
final LayoutInfo newLayout = (LayoutInfo) request.getNewObject();
return new EditCommand(m_container) {
@Override
protected void executeEdit() throws Exception {
m_container.setLayout(newLayout);
}
};
}
}