blob: 52f272b44e0b4c704fdc0db0ecb916db20a7a83c [file] [log] [blame]
/*******************************************************************************
* <copyright>
*
* Copyright (c) 2013, 2013 SAP AG.
* 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
*
* Contributors:
* SAP AG - initial API, implementation and documentation
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.fmc.blockdiagram.editor.features.custom;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.FMCNodeAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.FMCNodeAlgorithmFactory;
import org.eclipse.fmc.blockdiagram.editor.diagram.BlockDiagramImageProvider;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
/**
* Rotates the selected polygon by 90 degrees to the right.
*
* @author Heiko Witteborg
*
*/
public class HideContentCustomFeature extends FMCCustomFeature {
/**
* Boolean to track whether something has changed in diagram.
*/
private boolean hasDoneChanges = false;
/**
* The default constructor.
*
* @param featureProvider
* The feature provider.
*/
public HideContentCustomFeature(IFeatureProvider featureProvider) {
super(featureProvider, "Transform");
}
/*
* (non-Javadoc)
* @see org.eclipse.graphiti.features.impl.AbstractFeature#getName()
*/
@Override
public String getName() {
return "Hide Content";
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#getImageId()
*/
@Override
public String getImageId() {
return BlockDiagramImageProvider.ICON_HIDE_CONTENT + BlockDiagramImageProvider.SIZE_16;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#getDescription
* ()
*/
@Override
public String getDescription() {
return "Hide the contained elements";
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#canExecute
* (org.eclipse.graphiti.features.context.ICustomContext)
*/
@Override
public boolean canExecute(ICustomContext context) {
// allow rotate if exactly one pictogram element representing a Polygon
// is selected
boolean ret = false;
PictogramElement[] pes = context.getPictogramElements();
if (pes != null && pes.length == 1
&& context.getPictogramElements()[0] instanceof ContainerShape) {
ContainerShape container = (ContainerShape) context
.getPictogramElements()[0];
FMCNodeAlgorithm na = FMCNodeAlgorithmFactory.getInstance()
.getShape(container);
ret = na != null && !na.isEmpty(container)
&& !na.isHiding(container);
}
return ret;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse
* .graphiti.features.context.ICustomContext)
*/
@Override
public void execute(ICustomContext context) {
PictogramElement[] pes = context.getPictogramElements();
if (pes != null && pes.length == 1) {
ContainerShape firstLevelContainer = (ContainerShape) context
.getPictogramElements()[0];
FMCNodeAlgorithm na = FMCNodeAlgorithmFactory.getInstance()
.getShape(firstLevelContainer);
na.hideContainedShapes(firstLevelContainer, true);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.graphiti.features.impl.AbstractFeature#hasDoneChanges()
*/
@Override
public boolean hasDoneChanges() {
return this.hasDoneChanges;
}
}