/*******************************************************************************
* 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.common.collect.Lists;
import com.google.gdt.eclipse.designer.gef.policy.AbstractResizeSelectionEditPolicy;
import com.google.gdt.eclipse.designer.gwtext.model.layout.ColumnLayoutInfo;
import com.google.gdt.eclipse.designer.model.widgets.WidgetInfo;
import org.eclipse.wb.core.gef.command.EditCommand;
import org.eclipse.wb.draw2d.IColorConstants;
import org.eclipse.wb.draw2d.IPositionConstants;
import org.eclipse.wb.gef.graphical.handles.Handle;
import java.util.List;
/**
* {@link SelectionLayoutEditPolicy} for {@link WidgetInfo} on {@link ColumnLayoutInfo}.
*
* @author scheglov_ke
* @coverage GWTExt.gef.policy
*/
public final class ColumnSelectionEditPolicy extends AbstractResizeSelectionEditPolicy {
private final WidgetInfo m_widget;
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public ColumnSelectionEditPolicy(WidgetInfo widget) {
m_widget = widget;
}
////////////////////////////////////////////////////////////////////////////
//
// Handles
//
////////////////////////////////////////////////////////////////////////////
@Override
protected List<Handle> createSelectionHandles() {
List<Handle> handles = Lists.newArrayList();
handles.add(createResizeHandle(IPositionConstants.EAST, 0.25, IColorConstants.green));
return handles;
}
////////////////////////////////////////////////////////////////////////////
//
// Update
//
////////////////////////////////////////////////////////////////////////////
@Override
protected void updateTooltipCommand() {
double width0 = (double) m_newSize.width / getParentHeight();
final double width = (int) (100 * width0) / 100.0;
m_tooltip = "width: " + width;
m_command = new EditCommand(m_widget) {
@Override
protected void executeEdit() throws Exception {
ColumnLayoutInfo.getColumnData(m_widget).setWidth(width);
}
};
}
}