/**********************************************************************
- * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
* 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
- * $Id: ShowNodeEnd.java,v 1.3 2006/09/20 20:56:26 ewchan Exp $
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Bernd Hufmann - Updated for TMF
**********************************************************************/
+
package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
import java.util.Iterator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.linuxtools.tmf.ui.ITmfImageConstants;
-import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
+import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
import org.eclipse.ui.IViewPart;
/**
+ * Action class implementation to show end of a graph node.
+ *
+ * @version 1.0
* @author sveyrier
*/
public class ShowNodeEnd extends Action {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- protected SDView fView = null;
+ /**
+ * The sequence diagram view reference
+ */
+ protected SDView fView = null;
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
- public ShowNodeEnd() {
- this(null);
- }
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+ /**
+ * Default constructor
+ */
+ public ShowNodeEnd() {
+ this(null);
+ }
- public ShowNodeEnd(IViewPart _view) {
+ /**
+ * Constructor
+ *
+ * @param view The sequence diagram view reference
+ */
+ public ShowNodeEnd(IViewPart view) {
super();
- if (_view instanceof SDView) {
- fView = (SDView)_view;
+ if (view instanceof SDView) {
+ fView = (SDView)view;
}
- setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END));
+ setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END));
}
// ------------------------------------------------------------------------
@Override
@SuppressWarnings("rawtypes")
public void run() {
- if (fView == null)
+ if (fView == null) {
return;
+ }
SDWidget sdWidget = fView.getSDWidget();
if (sdWidget == null) {
return;
}
-
+
ISelectionProvider selProvider = sdWidget.getSelectionProvider();
ISelection sel = selProvider.getSelection();
Object selectedNode = null;
+
Iterator it = ((StructuredSelection) sel).iterator();
- while (it.hasNext())
+ while (it.hasNext()) {
selectedNode = it.next();
+ }
+
if (selectedNode != null) {
GraphNode node = (GraphNode) selectedNode;
- if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2)
+ if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor()) - sdWidget.getVisibleWidth() / 2, Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
- else
+ } else {
sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
+ }
}
}
- public void setView(SDView view) {
+ /**
+ * Sets the active SD view.
+ *
+ * @param view The SD view.
+ */
+ public void setView(SDView view) {
fView = view;
}
}