Skip to content

Commit

Permalink
ADD: Double click in the status line open the Team Message view
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe authored and Christophe committed Apr 5, 2012
1 parent dac728f commit 078153d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
category="epomodoro"
class="net.mornati.epomodoro.views.TeamStatus"
icon="icons/team.png"
id="epomodoro.views.TeamStatus"
id="net.mornati.epomodoro.views.TeamStatus"
name="Team Messages">
</view>
<view
Expand Down
18 changes: 10 additions & 8 deletions src/net/mornati/epomodoro/Activator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.mornati.epomodoro;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -46,14 +47,14 @@ public class Activator extends AbstractUIPlugin {
private PomodoroTimer timer;
private boolean showDialog=false;
private Timer scheduler=new Timer();
final java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("mm : ss");
private final SimpleDateFormat sdf=new SimpleDateFormat("mm : ss");
private static final Logger LOG=Logger.getLogger(Activator.class.getName());
private List<Button> startButtons=new ArrayList<Button>();
private List<Label> counterLabels=new ArrayList<Label>();
private final List<Button> startButtons=new ArrayList<Button>();
private final List<Label> counterLabels=new ArrayList<Label>();

/*
* (non-Javadoc)
*
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
Expand All @@ -69,7 +70,7 @@ public void start(BundleContext context) throws Exception {

/*
* (non-Javadoc)
*
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
Expand All @@ -85,7 +86,7 @@ public void stop(BundleContext context) throws Exception {

/**
* Returns the shared instance
*
*
* @return the shared instance
*/
public static Activator getDefault() {
Expand All @@ -94,7 +95,7 @@ public static Activator getDefault() {

/**
* Returns an image descriptor for the image file at the given plug-in relative path
*
*
* @param path
* the path
* @return the image descriptor
Expand Down Expand Up @@ -200,7 +201,7 @@ public void subscribeCounterLabel(Label label) {
public List<Button> getStartButtons() {
return startButtons;
}

public void scheduleTimer(final int changeInterval) {
final PomodoroTimer internalTimer;
if (timer == null) {
Expand All @@ -209,6 +210,7 @@ public void scheduleTimer(final int changeInterval) {
internalTimer=timer;
}
Display.getDefault().timerExec(changeInterval, new Runnable() {
@Override
public void run() {
if (internalTimer != null) {
for (Label countdown : counterLabels) {
Expand Down
18 changes: 17 additions & 1 deletion src/net/mornati/epomodoro/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import net.mornati.epomodoro.preference.PomodoroPreferencePage;
import net.mornati.epomodoro.util.PluginImages;
import net.mornati.epomodoro.util.UIUtil;
import net.mornati.epomodoro.views.TeamStatus;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.ControlContribution;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.preference.IPreferenceStore;
Expand All @@ -14,13 +17,15 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchWindow;

public class Startup implements IStartup {

@Override
public void earlyStartup() {
Display.getDefault().asyncExec(new Runnable() {
Expand All @@ -38,6 +43,17 @@ protected Control createControl(Composite parent) {
Label imgLabel=new Label(composite, SWT.NONE);
imgLabel.setImage(image);
Label countdownStatus=new Label(composite, SWT.NONE);
countdownStatus.addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event event) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(TeamStatus.ID);
} catch (PartInitException e) {
Activator.getDefault().getLog()
.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to open view " + TeamStatus.ID, e));
}
}
});
countdownStatus.setText(Activator.getDefault().getTimer().getFormatTime());
countdownStatus.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
Activator.getDefault().subscribeCounterLabel(countdownStatus);
Expand Down
15 changes: 12 additions & 3 deletions src/net/mornati/epomodoro/views/TeamStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public class TeamStatus extends ViewPart implements PropertyChangeListener {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID="epomodoro.views.SampleView";
public static final String ID=TeamStatus.class.getName();

private static final Logger LOG=Logger.getLogger(TeamStatus.class.getName());

private TableViewer viewer;
private Action clearTable;
private Action connect;
private PomodoroComparator comparator;
private List<TimerMessage> receivedMessages=new ArrayList<TimerMessage>();
private final List<TimerMessage> receivedMessages=new ArrayList<TimerMessage>();

// This will create the columns for the table
private void createColumns(final Composite parent, final TableViewer viewer) {
Expand Down Expand Up @@ -143,6 +143,7 @@ public TeamStatus() {
/**
* This is a callback that will allow us to create the viewer and initialize it.
*/
@Override
public void createPartControl(Composite parent) {
Composite composite=new Composite(parent, SWT.NONE);
GridLayout gridLayout=new GridLayout();
Expand Down Expand Up @@ -171,9 +172,10 @@ protected IStatus run(IProgressMonitor monitor) {
}
}
Activator.getDefault().getCommunication().setReceiver(new ReceiverAdapter() {
@Override
public void receive(final Message msg) {
if (msg != null && (msg.getObject() instanceof AbstractPomodoroMessage)) {

if (msg.getObject() instanceof TimerMessage) {
TimerMessage tm=(TimerMessage) msg.getObject();
if (receivedMessages.contains(tm)) {
Expand All @@ -191,6 +193,7 @@ public void receive(final Message msg) {
LOG.log(Level.WARNING, "Received a wrong message");
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!viewer.getTable().isDisposed()) {
viewer.refresh();
Expand All @@ -216,6 +219,7 @@ private void hookContextMenu() {
MenuManager menuMgr=new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
TeamStatus.this.fillContextMenu(manager);
}
Expand Down Expand Up @@ -247,9 +251,11 @@ private void fillLocalToolBar(IToolBarManager manager) {

private void makeActions() {
clearTable=new Action() {
@Override
public void run() {
receivedMessages.clear();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!viewer.getTable().isDisposed()) {
viewer.refresh();
Expand All @@ -263,6 +269,7 @@ public void run() {
clearTable.setImageDescriptor(Activator.getImageDescriptor(PluginImages.ICONS_CLEAR));

connect=new Action() {
@Override
public void run() {
Communication communication=Activator.getDefault().getCommunication();
if (communication != null) {
Expand All @@ -278,6 +285,7 @@ public void run() {
}
}
Display.getDefault().timerExec(4000, new Runnable() {
@Override
public void run() {
if (Activator.getDefault().getCommunication().isConnected()) {
connect.setImageDescriptor(Activator.getImageDescriptor(PluginImages.ICONS_CONNECTED));
Expand All @@ -300,6 +308,7 @@ public void run() {
/**
* Passing the focus request to the viewer's control.
*/
@Override
public void setFocus() {
viewer.getControl().setFocus();
}
Expand Down

0 comments on commit 078153d

Please sign in to comment.