Documente Academic
Documente Profesional
Documente Cultură
In Perspective.java
public void createInitialLayout(IPageLayout layout) {
IFolderLayout tabs =
layout.createFolder(ID_TABS_FOLDER, IPageLayout.LEFT, 0.3f, editorArea);
tabs.addView(IPageLayout.ID_OUTLINE +":Template");
tabs.addView(IPageLayout.ID_OUTLINE +":Editor");
}
2. In my editpart class:
@Override
public void performRequest(Request req) {
if (req.getType().equals(RequestConstants.REQ_OPEN)) {
try {
IWorkbenchPage page
= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.showView(IPageLayout.ID_OUTLINE, "Template",
IWorkbenchPage.VIEW_ACTIVATE);
page.showView(IPageLayout.ID_OUTLINE, "Editor",
IWorkbenchPage.VIEW_ACTIVATE);
}
catch (PartInitException e) {
e.printStackTrace();
}
}
}
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView
(IPageLayout.ID_OUTLINE);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView
(EditorGEF.ID);
} catch (Exception e) {
e.printStackTrace(); }
#define PE_HAS_MOUSE
#ifndef PE_HAS_MOUSE
#endif //PE_HAS_MOUSE
MainEditorContributor
activeEditorPart = part;
IActionBars actionBars = getActionBars();
if (actionBars != null) {
ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part :
null;
actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(),
getAction(editor, ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(),
getAction(editor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(
ActionFactory.REDO.getId(),
getAction(editor, ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(),
getAction(editor, ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(),
getAction(editor, ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(),
getAction(editor, ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(),
getAction(editor,
ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(
ActionFactory.FIND.getId(),
getAction(editor, ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(
IDEActionFactory.BOOKMARK.getId(),
getAction(editor, IDEActionFactory.BOOKMARK.getId()));
actionBars.updateActionBars();
}
}
private void createActions() {
sampleAction = new Action() {
@Override
public void run() {
MessageDialog.openInformation(null, "Editor", "Sample Action
Executed");
}
};
sampleAction.setText("Sample Action");
sampleAction.setToolTipText("Sample Action tool tip");
sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
}
@Override
public void contributeToMenu(IMenuManager manager) {
IMenuManager menu = new MenuManager("Editor &Menu");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
menu.add(sampleAction);
}
@Override
public void contributeToToolBar(IToolBarManager manager) {
manager.add(new Separator());
manager.add(sampleAction);
manager.add(getAction(null, ActionFactory.UNDO.getId()));
manager.add(getAction(null, ActionFactory.REDO.getId()));
manager.add(getAction(null, ActionFactory.DELETE.getId()));
manager.add(getAction(null, ActionFactory.COPY.getId()));
manager.add(getAction(null, ActionFactory.PASTE.getId()));
}
GEF
COPY-PASTE
Tile
public boolean isPositionTaken(int x, int y) {
List<Tile> list= this.getChildrenArray();
for (int i = 0; i < list.size(); i++) {
if(list.get(i).getX() == x && list.get(i).getY() == y) {
return true;
}
}
return false;
}
public Point getPositionInGEF() {
Tile tile = this;
int x = 0, y = 0, additionallyAlignment = 0;
while(!(tile instanceof MainScreenModel) && tile != null) {
x += tile.getX();
y += tile.getY();
additionallyAlignment++;
tile = tile.getParent();
}
return new Point(x + additionallyAlignment, y +
additionallyAlignment);
}
public void addParentToAllChildren(Tile tile) {
tile.setParent(this);
if(tile instanceof FrameModel && tile.getChildrenCount() > 0) {
for (int i = 0; i < tile.getChildrenCount(); i++) {
tile.addParentToAllChildren(tile.getChildrenArray().get(i));
}
}
}
public void printChildrenToConsole() {
List<Tile> listOfChilds = this.getChildrenArray();
printChildrenFatherToConsole();
if(listOfChilds.size() > 0) {
for (int i = 0; i < listOfChilds.size(); i++) {
listOfChilds.get(i).printChildrenToConsole();
}
}
}
public void printChildrenFatherToConsole() {
System.out.println("element: " + this.getName());
if(this.getParent() != null) {
System.out.println("perent: " + this.getParent().getName());
}
System.out.println("Broj djece: " + this.getChildrenCount());
}
}
public List<Tile> convertSelectedObjectToModel(List<Object>
selectedObjects) {
List<Tile> listOfModels = new ArrayList<Tile>();
for (int i = 0; i < selectedObjects.size(); i++) {
try {
Object checkEditPart = selectedObjects.get(i);
if (checkEditPart instanceof EditPart) {
EditPart editPart = (EditPart) checkEditPart;
Tile tile = (Tile) editPart.getModel();
listOfModels.add(tile);
}
} catch (ClassCastException e) {
e.printStackTrace();
}
}
return listOfModels;
}
COPY Command
public boolean addElements(Tile tile, List<Tile> list) {
for (int i = 0; i < tile.getChildrenCount(); i++) {
deleteNoSelectedChild(tile.getChildrenArray().get(i), list);
}
Collections.sort(this.list, new Comparator<Tile>() {
@Override
public int compare(Tile first, Tile second) {
return new Integer(first.getX()).compareTo(new
Integer(second.getX()));
}
});
return true;
}
public void deleteNoSelectedChild(Tile tile, List<Tile> list) {
List<Tile> listOfChilds = tile.getChildrenArray();
if(listOfChilds.size() > 0) {
int n = listOfChilds.size();
for (int i = 0; i < listOfChilds.size(); i++) {
Tile lastTile = listOfChilds.get(listOfChilds.size() - 1);
deleteNoSelectedChild(listOfChilds.get(i), list);
if(listOfChilds.size() < n) {
i--;
n = listOfChilds.size();
}
else if(n == listOfChilds.size() && !
(lastTile.equals(listOfChilds.get(listOfChilds.size() - 1)))) {
i--;
}
}
}
if(list.contains(tile)) {
if(!checkAndChangeParent(tile, list)) {
tile.getParent().removeChild(tile);
tile.setParent(null);
this.list.add(tile);
}
}
else if(tile.getParent() != null) {
tile.getParent().removeChild(tile);
tile.setParent(null);
}
}
//
//
Paste Command
public PasteTileCommand(List<Object> selectedObjects) {
Iterator<Object> it = selectedObjects.iterator();
if(it.hasNext()) {
try {
Object checkEditPart = it.next();
if (checkEditPart instanceof EditPart) {
EditPart editPart = (EditPart) checkEditPart;
Tile tile = (Tile) editPart.getModel();
if(tile instanceof FrameModel) {
selectedTile = tile;
mouseClickPosition =
FrameEditPart.getMouseClickPosition();
}
else if(tile instanceof MainScreenModel) {
selectedTile = tile;
mouseClickPosition =
MainScreenEditPart.getMouseClickPosition();
}
}
} catch (ClassCastException e) {
e.printStackTrace();
}
}
}
ArrayList<Tile> copyList = (ArrayList<Tile>) Clipboard.getDefault().getContents();
Iterator<Tile> tile = copyList.iterator();
int index = 0;
Tile nextTile = null;
Tile firstTile = null;
while (tile.hasNext()) {
if(index == 1) {
firstTile = nextTile;
}
nextTile = tile.next();
if (nextTile.isPasteable()) {
if(selectedTile != null) {
try {
Tile clone = nextTile.clone();
clone.setParent(selectedTile);
int x = mouseClickPosition.x selectedTile.getPositionInGEF().x;
int y = mouseClickPosition.y selectedTile.getPositionInGEF().y;
while(selectedTile.isPositionTaken(x, y)) {
x += 15;
y += 15;
}
if(index != 0) {
x += clone.getX() - firstTile.getX();
y += clone.getY() - firstTile.getY();
}
clone.setX(x);
clone.setY(y);
list.put(clone, clone);
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
index++;
}
redo();