Permalink
Browse files

IDE-194

  • Loading branch information...
1 parent d30b808 commit afabd27787cb7215f7c8b7e60bed694645568506 @cinnndy9 cinnndy9 committed with gamerson Feb 28, 2013
@@ -27,12 +27,14 @@
/**
* @author Greg Amerson
+ * @author Cindy Li
*/
public class PortletColumnChangeConstraintCommand extends Command
{
protected PortletColumn column;
protected PortletLayout currentParent;
+ protected int diffWeight = 0;
protected PortletLayout newParent;
protected LayoutConstraint layoutConstraint;
@@ -62,7 +64,7 @@ public void redo()
{
int existingWeight = column.getWeight();
column.setWeight( layoutConstraint.weight );
- int diffWeight = existingWeight - layoutConstraint.weight;
+ diffWeight = existingWeight - layoutConstraint.weight;
PortletColumn refColumn = layoutConstraint.refColumn;
int newWeight = refColumn.getWeight() + diffWeight;
@@ -83,7 +85,21 @@ public void redo()
public void undo()
{
- System.out.println( "UNDO" ); //$NON-NLS-1$
+ //do the opposite of redo: give diffWeight back to the column and take it away from refColumn
+ //since diffWeight means the reduction of the modified column according to redo
+ column.setWeight( column.getWeight() + diffWeight );
+
+ PortletColumn refColumn = layoutConstraint.refColumn;
+ int newWeight = refColumn.getWeight() - diffWeight;
+
+ if( refColumn.getWeight() == 33 )
+ {
+ newWeight = newWeight + 1;
+ }
+
+ newWeight = LayoutTplUtil.adjustWeight( newWeight );
+
+ refColumn.setWeight( newWeight );
}
private static class Msgs extends NLS
@@ -28,12 +28,14 @@
/**
* @author Greg Amerson
+ * @author Cindy Li
*/
public class PortletColumnCreateCommand extends Command
{
protected LayoutTplDiagram diagram;
protected LayoutConstraint layoutConstraint;
protected PortletColumn newColumn;
+ protected int refColumnOldWeight = 0;
public PortletColumnCreateCommand( PortletColumn newColumn, LayoutTplDiagram diagram, LayoutConstraint constraint )
{
@@ -68,6 +70,7 @@ else if( layoutConstraint.rowIndex > -1 && layoutConstraint.newColumnIndex > -1
if( layoutConstraint.refColumn != null )
{
+ refColumnOldWeight = layoutConstraint.refColumn.getWeight();
layoutConstraint.refColumn.setWeight( layoutConstraint.weight );
}
@@ -86,7 +89,7 @@ else if( layoutConstraint.rowIndex > -1 && layoutConstraint.newColumnIndex > -1
public void undo()
{
- if( layoutConstraint.equals( LayoutConstraint.EMPTY ) )
+ if( layoutConstraint.equals( LayoutConstraint.EMPTY ) || layoutConstraint.newColumnIndex == -1 )
{
for( ModelElement row : diagram.getRows() )
{
@@ -95,12 +98,24 @@ public void undo()
if( portletLayout.getColumns().size() == 1 && portletLayout.getColumns().get( 0 ).equals( newColumn ) )
{
diagram.removeRow( portletLayout );
+ break;
}
}
}
- else
+ else if( layoutConstraint.rowIndex > -1 && layoutConstraint.newColumnIndex > -1 )
{
- System.out.println( "UNDO not supported!" ); //$NON-NLS-1$
+ if( layoutConstraint.refColumn != null )
+ {
+ layoutConstraint.refColumn.setWeight( refColumnOldWeight );
+ }
+
+ ModelElement row = diagram.getRows().get( layoutConstraint.rowIndex );
+ PortletLayout portletLayout = (PortletLayout) row;
+
+ if( row != null )
+ {
+ portletLayout.removeColumn( newColumn );
+ }
}
}
@@ -27,6 +27,7 @@
/**
* @author Gregory Amerson
+ * @author Cindy Li
*/
public class PortletLayoutCreateCommand extends Command
{
@@ -65,7 +66,7 @@ public void redo()
public void undo()
{
- System.out.println( "UNDO not yet supported!" ); //$NON-NLS-1$
+ diagram.removeRow( newLayout );
}
private static class Msgs extends NLS
@@ -47,6 +47,7 @@
/**
* @author Greg Amerson
+ * @author Cindy Li
*/
@SuppressWarnings( { "restriction", "rawtypes" } )
public class LayoutTplMultiPageEditor extends MultiPageEditorPart implements ISelectionListener
@@ -190,6 +191,16 @@ public void gotoMarker( IMarker marker )
return result;
}
+ public StructuredTextEditor getSourceEditor()
+ {
+ return sourceEditor;
+ }
+
+ public LayoutTplEditor getVisualEditor()
+ {
+ return visualEditor;
+ }
+
@Override
public void init( IEditorSite site, IEditorInput input ) throws PartInitException
{
@@ -14,24 +14,28 @@
package com.liferay.ide.layouttpl.ui.editor;
+import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.wst.html.ui.internal.edit.ui.ActionContributorHTML;
import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor;
/**
* @author Gregory Amerson
+ * @author Cindy Li
*/
@SuppressWarnings( "restriction" )
public class LayoutTplMultiPageEditorActionBarContributor extends MultiPageEditorActionBarContributor
{
protected IEditorActionBarContributor sourceEditorContributor;
protected IEditorActionBarContributor visualEditorContributor;
- protected MultiPageEditorPart multiPageEditor;
+ protected LayoutTplMultiPageEditor layoutTplMultiPageEditor;
protected boolean needsMultiInit;
public LayoutTplMultiPageEditorActionBarContributor()
@@ -84,13 +88,13 @@ public void dispose()
sourceEditorContributor.dispose();
}
- multiPageEditor = null;
+ layoutTplMultiPageEditor = null;
}
@Override
public void setActivePage( IEditorPart activeEditor )
{
- if( multiPageEditor != null )
+ if( layoutTplMultiPageEditor != null )
{
if( ( activeEditor != null ) && ( activeEditor instanceof ITextEditor ) )
{
@@ -105,17 +109,62 @@ public void setActivePage( IEditorPart activeEditor )
IActionBars actionBars = getActionBars();
if( actionBars != null )
{
+ actionBars.clearGlobalActionHandlers();
+
+ if( layoutTplMultiPageEditor.getSelectedPage() instanceof LayoutTplEditor )
+ {
+ actionBars.setGlobalActionHandler(
+ ActionFactory.UNDO.getId(), getLayoutEditorAction( ActionFactory.UNDO.getId() ) );
+ actionBars.setGlobalActionHandler(
+ ActionFactory.REDO.getId(), getLayoutEditorAction( ActionFactory.REDO.getId() ) );
+ }
+
+ if( layoutTplMultiPageEditor.getSelectedPage() instanceof ITextEditor )
+ {
+ actionBars.setGlobalActionHandler(
+ ActionFactory.UNDO.getId(), getTextEditorAction( ITextEditorActionConstants.UNDO ) );
+ actionBars.setGlobalActionHandler(
+ ActionFactory.REDO.getId(), getTextEditorAction( ITextEditorActionConstants.REDO ) );
+ }
+
// update menu bar and tool bar
actionBars.updateActionBars();
}
}
+ protected IAction getTextEditorAction( String actionId )
+ {
+ if( layoutTplMultiPageEditor != null )
+ {
+ try
+ {
+ return layoutTplMultiPageEditor.getSourceEditor().getAction( actionId );
+ }
+ catch( NullPointerException e )
+ {
+ //editor has been disposed, ignore
+ }
+ }
+
+ return null;
+ }
+
+ protected IAction getLayoutEditorAction( String actionId )
+ {
+ if( layoutTplMultiPageEditor != null )
+ {
+ return layoutTplMultiPageEditor.getVisualEditor().getActionRegistry().getAction( actionId );
+ }
+
+ return null;
+ }
+
@Override
public void setActiveEditor( IEditorPart part )
{
if( part instanceof MultiPageEditorPart )
{
- this.multiPageEditor = (MultiPageEditorPart) part;
+ this.layoutTplMultiPageEditor = (LayoutTplMultiPageEditor) part;
}
if( needsMultiInit )
@@ -137,7 +186,7 @@ protected void activateVisualPage( IEditorPart activeEditor )
// null, so pass in multiPageEditor instead (d282414)
if( activeEditor == null )
{
- sourceEditorContributor.setActiveEditor( multiPageEditor );
+ sourceEditorContributor.setActiveEditor( layoutTplMultiPageEditor );
}
else
{
@@ -151,7 +200,7 @@ protected void activateSourcePage( IEditorPart activeEditor )
{
if( visualEditorContributor != null )
{
- visualEditorContributor.setActiveEditor( multiPageEditor );
+ visualEditorContributor.setActiveEditor( layoutTplMultiPageEditor );
}
if( ( sourceEditorContributor != null ) &&

0 comments on commit afabd27

Please sign in to comment.