Update UI
This commit is contained in:
parent
f92f15dbd2
commit
af0acb41d2
BIN
icons/cog.png
Normal file
BIN
icons/cog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
icons/cog@2x.png
Normal file
BIN
icons/cog@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
@ -4,28 +4,19 @@ package me.mrletsplay.shareclient.views;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
|
||||
@ -57,10 +48,6 @@ public class ShareView extends ViewPart {
|
||||
@Inject IWorkbench workbench;
|
||||
|
||||
private TableViewer viewer;
|
||||
private Action action1;
|
||||
private Action action2;
|
||||
private Action doubleClickAction;
|
||||
|
||||
|
||||
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
|
||||
@Override
|
||||
@ -88,90 +75,27 @@ public class ShareView extends ViewPart {
|
||||
// Create the help context id for the viewer's control
|
||||
workbench.getHelpSystem().setHelp(viewer.getControl(), "ShareClient.viewer");
|
||||
getSite().setSelectionProvider(viewer);
|
||||
makeActions();
|
||||
hookContextMenu();
|
||||
hookDoubleClickAction();
|
||||
contributeToActionBars();
|
||||
}
|
||||
|
||||
private void hookContextMenu() {
|
||||
MenuManager menuMgr = new MenuManager("#PopupMenu");
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
@Override
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
ShareView.this.fillContextMenu(manager);
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(viewer.getControl());
|
||||
viewer.getControl().setMenu(menu);
|
||||
getSite().registerContextMenu(menuMgr, viewer);
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
fillLocalPullDown(bars.getMenuManager());
|
||||
fillLocalToolBar(bars.getToolBarManager());
|
||||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
manager.add(action1);
|
||||
manager.add(new Separator());
|
||||
manager.add(action2);
|
||||
}
|
||||
Action showSettings = new Action() {
|
||||
|
||||
private void fillContextMenu(IMenuManager manager) {
|
||||
manager.add(action1);
|
||||
manager.add(action2);
|
||||
// Other plug-ins can contribute there actions here
|
||||
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(action1);
|
||||
manager.add(action2);
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
action1 = new Action() {
|
||||
@Override
|
||||
public void run() {
|
||||
showMessage("Action 1 executed");
|
||||
}
|
||||
};
|
||||
action1.setText("Action 1");
|
||||
action1.setToolTipText("Action 1 tooltip");
|
||||
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
||||
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||
|
||||
action2 = new Action() {
|
||||
@Override
|
||||
public void run() {
|
||||
showMessage("Action 2 executed");
|
||||
}
|
||||
};
|
||||
action2.setText("Action 2");
|
||||
action2.setToolTipText("Action 2 tooltip");
|
||||
action2.setImageDescriptor(workbench.getSharedImages().
|
||||
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||
doubleClickAction = new Action() {
|
||||
@Override
|
||||
public void run() {
|
||||
IStructuredSelection selection = viewer.getStructuredSelection();
|
||||
Object obj = selection.getFirstElement();
|
||||
showMessage("Double-click detected on "+obj.toString());
|
||||
}
|
||||
};
|
||||
showMessage("Settings");
|
||||
}
|
||||
|
||||
private void hookDoubleClickAction() {
|
||||
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
@Override
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
doubleClickAction.run();
|
||||
}
|
||||
};
|
||||
|
||||
viewer.addDoubleClickListener(event -> {
|
||||
showMessage(String.valueOf(((StructuredSelection) event.getSelection()).toArray()[0]));
|
||||
});
|
||||
|
||||
showSettings.setImageDescriptor(ImageDescriptor.createFromFile(ShareView.class, "/icons/cog.png"));
|
||||
|
||||
bars.getToolBarManager().add(showSettings);
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(
|
||||
viewer.getControl().getShell(),
|
||||
|
Loading…
Reference in New Issue
Block a user